當前位置:首頁 » 編程語言 » 華為雲linux怎麼進去sql
擴展閱讀
webinf下怎麼引入js 2023-08-31 21:54:13
堡壘機怎麼打開web 2023-08-31 21:54:11

華為雲linux怎麼進去sql

發布時間: 2022-07-08 17:37:11

A. 如何在LINUX下建立一個MYsql資料庫,然後我想把一個SQL資料庫導入進去,求步驟!

首先需要安裝MYSQL數據,不知你的是哪個發行版,就當是常用的吧,一般為
#apt-get install mysql-server mysql-client #for debian ubuntu

#yum install mysql-server mysql-client #for CENTOS RHEL

安裝完畢後進入資料庫
mysql 回車,一般在本機上直接用此命令就可以進入的,從其它機器連接還需要賬號密碼

mysql>source <filename> #把<filename>換成你要導入的資料庫備份SQL文件完整路徑,回車等待
mysql>exit #打完收功,退出MYSQL

B. linux下怎麼運行sql文件

要看你有沒有設資料庫bin目錄的環境變數如果設置了就直接可以用,如果沒設置你就:
1.切換工作目錄到mysql(或其他資料庫產品)下,用root用戶執行
sudo
bin/mysqld_safe
--user
root
&(這個符號表示從後台啟動)
2.然後再切換到bin目錄下工作
執行./mysql
-u
用戶名
-p
3.終端會提示你輸入密碼

C. linux下如何進入類似SQL>提示符下

右鍵桌面選terminal
打開後打
sqlplus / as sysdba
或者sqlplus user/password as sysdba

D. linux 怎麼執行sql

要看你有沒有設資料庫bin目錄的環境變數 如果設置了就直接可以用,如果沒設置你就:
1.切換工作目錄到mysql(或其他資料庫產品)下,用root用戶執行 sudo bin/mysqld_safe --user root &(這個符號表示從後台啟動)
2.然後再切換到bin目錄下工作 執行./mysql -u 用戶名 -p
3.終端會提示你輸入密碼

E. 在linux中,怎樣打開sql中的表

什麼資料庫?sqlite?如果是sqlite工具SQLite Database Browser打開,或者在終端直接輸入命令sqlite3 xx.db,在輸入select * from xxx;
xx.db是資料庫,xxx是表名,這樣就可以看到xxx表中所有數據了。

F. linux系統下怎麼在終端運行sql語句

主要有以下幾種方法:
1、將SQL語句直接嵌入到shell腳本文件中
代碼如下:

--演示環境
[root@SZDB ~]# more /etc/issue
CentOS release 5.9 (Final)
Kernel \r on an \m
root@localhost[(none)]> show variables like 'version';
+---------------+------------+
| Variable_name | Value |
+---------------+------------+
| version | 5.6.12-log |
+---------------+------------+

[root@SZDB ~]# more shell_call_sql1.sh
#!/bin/bash
# Define log
TIMESTAMP=`date +%Y%m%d%H%M%S`
LOG=call_sql_${TIMESTAMP}.log
echo "Start execute sql statement at `date`." >>${LOG}

# execute sql stat
mysql -uroot -p123456 -e "
tee /tmp/temp.log
drop database if exists tempdb;
create database tempdb;
use tempdb
create table if not exists tb_tmp(id smallint,val varchar(20));
insert into tb_tmp values (1,'jack'),(2,'robin'),(3,'mark');
select * from tb_tmp;
notee
quit"

echo -e "\n">>${LOG}
echo "below is output result.">>${LOG}
cat /tmp/temp.log>>${LOG}
echo "script executed successful.">>${LOG}
exit;

[root@SZDB ~]# ./shell_call_sql1.sh
Logging to file '/tmp/temp.log'
+------+-------+
| id | val |
+------+-------+
| 1 | jack |
| 2 | robin |
| 3 | mark |
+------+-------+
Outfile disabled.

2、命令行調用單獨的SQL文件

代碼如下:

[root@SZDB ~]# more temp.sql
tee /tmp/temp.log
drop database if exists tempdb;
create database tempdb;
use tempdb
create table if not exists tb_tmp(id smallint,val varchar(20));
insert into tb_tmp values (1,'jack'),(2,'robin'),(3,'mark');
select * from tb_tmp;
notee
[root@SZDB ~]# mysql -uroot -p123456 -e "source /root/temp.sql"
Logging to file '/tmp/temp.log'
+------+-------+
| id | val |
+------+-------+
| 1 | jack |
| 2 | robin |
| 3 | mark |
+------+-------+
Outfile disabled.

3、使用管道符調用SQL文件
代碼如下:

[root@SZDB ~]# mysql -uroot -p123456 </root/temp.sql
Logging to file '/tmp/temp.log'
id val
1 jack
2 robin
3 mark
Outfile disabled.
#使用管道符調用SQL文件以及輸出日誌
[root@SZDB ~]# mysql -uroot -p123456 </root/temp.sql >/tmp/temp.log
[root@SZDB ~]# more /tmp/temp.log
Logging to file '/tmp/temp.log'
id val
1 jack
2 robin
3 mark
Outfile disabled.

4、shell腳本中MySQL提示符下調用SQL

代碼如下:

[root@SZDB ~]# more shell_call_sql2.sh
#!/bin/bash
mysql -uroot -p123456 <<EOF
source /root/temp.sql;
select current_date();
delete from tempdb.tb_tmp where id=3;
select * from tempdb.tb_tmp where id=2;
EOF
exit;
[root@SZDB ~]# ./shell_call_sql2.sh
Logging to file '/tmp/temp.log'
id val
1 jack
2 robin
3 mark
Outfile disabled.
current_date()
2014-10-14
id val
2 robin

5、shell腳本中變數輸入與輸出

代碼如下:

[root@SZDB ~]# more shell_call_sql3.sh
#!/bin/bash
cmd="select count(*) from tempdb.tb_tmp"
cnt=$(mysql -uroot -p123456 -s -e "${cmd}")
echo "Current count is : ${cnt}"
exit
[root@SZDB ~]# ./shell_call_sql3.sh
Warning: Using a password on the command line interface can be insecure.
Current count is : 3

[root@SZDB ~]# echo "select count(*) from tempdb.tb_tmp"|mysql -uroot -p123456 -s
3

[root@SZDB ~]# more shell_call_sql4.sh
#!/bin/bash
id=1
cmd="select count(*) from tempdb.tb_tmp where id=${id}"
cnt=$(mysql -uroot -p123456 -s -e "${cmd}")
echo "Current count is : ${cnt}"
exit

[root@SZDB ~]# ./shell_call_sql4.sh
Current count is : 1

G. 怎麼在linux下執行sql文件

要看你有沒有設資料庫bin目錄的環境變數如果設置了就直接可以用,如果沒設置你就:
1.切換工作目錄到mysql(或其他資料庫產品)下,用root用戶執行 sudo bin/mysqld_safe --user root &(這個符號表示從後台啟動)
2.然後再切換到bin目錄下工作 執行./mysql -u 用戶名 -p
3.終端會提示你輸入密碼

H. Linux下如何運行sql腳本

1、打開navicat for mysql並打開鏈接和資料庫,注意資料庫的狀態是打開的,關閉狀態下是無法運行sql腳本的。

I. 如何在linux中執行sql文件

如何在linux中執行sql文件
第一種方法:
在命令行下(未連接資料庫),輸入 mysql -h localhost -u root -p123456 < F:\hello world\niuzi.sql (注意路徑不用加引號的!!) 回車即可.
第二種方法:
在命令行下(已連接資料庫,此時的提示符為 mysql> ),輸入 source F:\hello world\niuzi.sql (注意路徑不用加引號的)
或者 \. F:\hello world\niuzi.sql (注意路徑不用加引號的) 回車即可.