MySQL 客户端命令
文章目錄
- 1、連接命令
- 2、斷開連接
- 3、命令結(jié)束符
- 4、查看所有數(shù)據(jù)庫(kù)
- 5、切換到指定數(shù)據(jù)庫(kù)
- 6、查看當(dāng)前使用的數(shù)據(jù)庫(kù)
- 7、查看庫(kù)中所有表
- 8、查看所有用戶
- 9、執(zhí)行SQL腳本
- 10、查詢當(dāng)前時(shí)間
1、連接命令
首先定位到MySQL安裝根目錄/bin目錄下,然后執(zhí)行如下命令:
mysql -h[主機(jī)名] -P[端口] -u[用戶名] -p[密碼]#例如:
mysql -hlocalhost -P3306 -uroot -p123注:
-
localhost是指MySQL數(shù)據(jù)庫(kù)安裝在本機(jī),如果是遠(yuǎn)程機(jī)器,那么localhost換成對(duì)應(yīng)機(jī)器的IP地址即可;
-
端口默認(rèn)為3306的話,可以不輸入-P;
-
最好不要在一行中輸入密碼,這樣敲出去會(huì)被別人看到。
如果不想被看到密碼,可以使用如下方式連接:
mysql -hlocalhost -uroot -p回車之后提示輸入密碼:
Enter password:不過(guò)這回你輸入的密碼不會(huì)被顯示出來(lái),心懷不軌的人也就看不到了,輸入完成點(diǎn)擊回車就成功連接到了服務(wù)器。
執(zhí)行成功之后的界面如下:
mysql: [Warning] Using a password on the command line interface can be insecure. Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 24 Server version: 5.7.30 MySQL Community Server (GPL)Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.mysql>最后一行的 mysql> 是一個(gè)客戶端的提示符,之后客戶端發(fā)送給服務(wù)器的命令都需要寫在這個(gè)提示符后邊。
注:如果你愿意,你可以多打開幾個(gè)命令行窗口,每個(gè)窗口都可以使用連接命令,從而達(dá)到運(yùn)行多個(gè)客戶端程序的效果,每個(gè)客戶端程序都是互不影響的。
2、斷開連接
quit exit \q注:如上三個(gè)命令是關(guān)閉客戶端程序的方式,不是關(guān)閉服務(wù)器程序的方式。
3、命令結(jié)束符
在書寫完一個(gè)命令之后需要以下邊這幾個(gè)符號(hào)之一結(jié)尾:
; \g \G4、查看所有數(shù)據(jù)庫(kù)
show databases;查詢結(jié)果:
+--------------------+ | Database | +--------------------+ | information_schema | | db_cwtsb | | mysql | | performance_schema | | sys | +--------------------+ 5 rows in set (0.00 sec)5、切換到指定數(shù)據(jù)庫(kù)
use [數(shù)據(jù)庫(kù)名稱];這里我們選擇 information_schema
use information_schema;查詢結(jié)果:
Reading table information for completion of table and column names You can turn off this feature to get a quicker startup with -ADatabase changed6、查看當(dāng)前使用的數(shù)據(jù)庫(kù)
select database();查詢結(jié)果:
+--------------------+ | database() | +--------------------+ | information_schema | +--------------------+ 1 row in set (0.00 sec)7、查看庫(kù)中所有表
show tables;查詢結(jié)果:
+---------------------------------------+ | Tables_in_information_schema | +---------------------------------------+ | CHARACTER_SETS | | COLLATIONS | ... | INNODB_SYS_TABLESTATS | +---------------------------------------+ 61 rows in set (0.00 sec)8、查看所有用戶
select user,host,authentication_string FROM mysql.user;查詢結(jié)果:
+---------------+-----------+-------------------------------------------+ | user | host | authentication_string | +---------------+-----------+-------------------------------------------+ | root | localhost | *112646FC4B3886349C1C2A17DDFD146AD53C1B1 | | mysql.session | localhost | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHER | | mysql.sys | localhost | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHER | +---------------+-----------+-------------------------------------------+ 3 rows in set (0.01 sec)9、執(zhí)行SQL腳本
source [腳本.sql文件]10、查詢當(dāng)前時(shí)間
select now();查詢結(jié)果:
+---------------------+ | now() | +---------------------+ | 2022-03-07 11:59:16 | +---------------------+ 1 row in set (0.00 sec)總結(jié)
以上是生活随笔為你收集整理的MySQL 客户端命令的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 单向认证
- 下一篇: java.sql.SQLExceptio