MYSQL中的常用工具

來源:互聯網
上載者:User

標籤:mysql中的常用工具

查看當前登入使用者:mysql> select current_user();

字元集設定:

mysql> set names utf8mb4;

mysql> show variables like ‘chara%‘;


-e 執行sql語句並退出

-E 豎著顯示

-s 去掉線條框顯示

-f 強制執行

-v 顯示更多資訊

--show-warnings 顯示警告


mysqlbinlog

mysql> flush logs;

mysql> use mysql;

mysql> revoke process on *.* from  [email protected] ;

mysql> use test;

mysql> truncate table t2;  

mysql> insert into t2 values(1),(2),(3);


不加任何參數,顯示所有日誌:

[[email protected] 3306]# /usr/bin/mysqlbinlog mysql3306-bin.000009

加-d 選項,將只顯示對test資料庫的動作記錄:

[[email protected] 3306]# /usr/bin/mysqlbinlog mysql3306-bin.000009 -d test

加-o 選項,忽略掉前3個操作:

[[email protected] 3306]# /usr/bin/mysqlbinlog mysql3306-bin.000009 -o 3

加-r 結果輸出到檔案:

[[email protected] 3306]# /usr/bin/mysqlbinlog mysql3306-bin.000009 -o 3 -r /tmp/resultfile

加-s 簡單顯示:

[[email protected] 3306]# /usr/bin/mysqlbinlog mysql3306-bin.000009 -s -o 3

根據時間和pos點過濾日誌:

[[email protected] 3306]# /usr/bin/mysqlbinlog mysql3306-bin.000009 --start-datetime="2016/05/05 13:54:41" --stop-datetime="2016/05/05 13:55:48";

[[email protected] 3306]# /usr/bin/mysqlbinlog mysql3306-bin.000009 --start-position=352 --stop-position=628;

檢查myisam表:

[[email protected] wqh]# /usr/bin/mysqlcheck -p3306 --socket=/data/3306/mysql.sock  wqh -c t1


修複表:

[[email protected] wqh]# /usr/bin/mysqlcheck -p3306 --socket=/data/3306/mysql.sock  wqh -r t1


分析表:

[[email protected] wqh]# /usr/bin/mysqlcheck -p3306 --socket=/data/3306/mysql.sock  wqh -a t1


最佳化表:

[[email protected] wqh]# /usr/bin/mysqlcheck -p3306 --socket=/data/3306/mysql.sock  wqh -o t1


mysqldump

--add-drop-database

--add-drop-table

-n --no-create-db

-t --no-create-info

-d --no-data

--compact 輸出結果簡潔

-c --complete-insert 輸出語句的insert包括欄位名稱

-T 備份為資料檔案和建表檔案


設定匯出的用戶端字元集:

--default-character-set=utf8mb4


-F --flush-logs 重新整理日誌

-l --lock-tables 給所有表加讀鎖


mysqlshow

[[email protected] wqh]# /usr/bin/mysqlshow -p3306 --socket=/data/3306/mysql.sock 

[[email protected] wqh]# /usr/bin/mysqlshow -p3306 --socket=/data/3306/mysql.sock  --count

[[email protected] wqh]# /usr/bin/mysqlshow -p3306 --socket=/data/3306/mysql.sock  wqh  --count

[[email protected] wqh]# /usr/bin/mysqlshow -p3306 --socket=/data/3306/mysql.sock  wqh t6 --count

[[email protected] wqh]# /usr/bin/mysqlshow -p3306 --socket=/data/3306/mysql.sock  mysql user -k


mysql> show full columns from wqh.t7;

mysql> show index  from wqh.t7;  


[[email protected] wqh]# /usr/bin/mysqlshow -p3306 --socket=/data/3306/mysql.sock  mysql user --status

[[email protected] wqh]# /usr/bin/mysqlshow -p3306 --socket=/data/3306/mysql.sock  mysql user -i


mysql> show table status from wqh like "t5";



錯誤碼查看工具:

[[email protected] wqh]# perror 30 60

[[email protected] wqh]# /usr/bin/perror 60


mysql內建的文本替換工具:

覆蓋方式“--”:

[[email protected] ~]# cat  a 

a1 a2 a3

b1 b2 b3

[[email protected] ~]# replace a1 aa1 b1 bb1 -- a 

a converted

[[email protected] ~]# cat  a 

aa1 a2 a3

bb1 b2 b3

[[email protected] ~]# 


非覆蓋方式“<”:


[[email protected] ~]# cat  a 

aa1 a2 a3

bb1 b2 b3

[[email protected] ~]# replace a c b d  < a  # 把檔案a中的a替換成c,b替換成d。

cc1 c2 c3

dd1 d2 d3

[[email protected] ~]# cat  a              

aa1 a2 a3

bb1 b2 b3

[[email protected] ~]# 


MYSQL中的常用工具

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.