DOS命令行操作MySQL常用命令


平時用可視化界面用慣了,如果緊急排查問題,沒有安裝可視化工具的話,只能通過命令來看了。

以備不時之需,我們要熟悉一下命令行操作MySQL。

打開DOS命令窗口:WIN + R 輸入cmd,回車

 

然后輸入命令:mysql -uroot -proot -h127.0.0.1  【-u 用戶名 -p密碼 -h host地址】

 

這里連接的是本地MySQL服務(先確保服務已啟動)

輸入 show databases; (有分號) 輸出所有數據庫

輸入use demo 切換到demo數據庫

輸入show tables; 輸出該數據庫下所有表名

查詢表數據:select * from fruit_type

出現中文亂碼,原因是登陸時使用的是lastin碼,所以需要重新退出使用編碼明確登陸。

輸入 exit 或 Ctrl + C退出,重新登錄輸入命令:mysql -uroot -proot -h127.0.0.1 --default-character-set=GBK

再來查詢

 

 查看執行計划 explain select * from fruit_type where type_id = 1;

 

查看表結構:desc tableName;

查詢表中列的注釋信息

select * from information_schema.columns
where table_schema = 'demo' 
and table_name = 'fruit_type' ;

只查詢列名和注釋
select column_name, column_comment from information_schema.columns where table_schema ='demo' and table_name = 'fruit_type' ;

圖片太長了

 

查看表的注釋
select table_name,table_comment from information_schema.tables where table_schema = 'demo' and table_name ='fruit_type';

我這個沒寫注釋。

表操作命令:
復制表結構:create table table1 like table;
復制數據:insert into table1 select * from table

機器授權:
grant select on *.* to 'reader'@'%' identified by '123456' WITH GRANT OPTION
flush privileges

修改表結構
alter table fruit_type add addr VARCHAR2(20) unsigned DEFAULT NULL COMMENT '產地';

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM