mysql常用查詢命令

2021-08-18 03:47:23 字數 2100 閱讀 3787

1、 linux鏈結mysql命令語句

mysql -h -p-u -p

例子:mysql -h 127.0.0.1 -p5000 -u test -p123456

2、展示所有的資料庫

show databases;

3、進入使用某一資料庫

use test;//test為當前資料庫中的乙個schema

4、檢視資料庫狀態,服務所用語言,埠號,執行緒,慢查詢等資訊

5、檢視正在執行的sql

6、採集出現事物阻塞的資訊

select r.trx_id waiting_trx_id,r.trx_mysql_thread_id waiting_thread,r.trx_query waiting_query,b.trx_id blocking_trx_id,b.trx_mysql_thread_id blocking_thread,b.trx_query blocking_query from information_schema.innodb_lock_waits w inner join information_schema.innodb_trx b on b.trx_id=w.blocking_trx_id inner join information_schema.innodb_trx r on r.trx_id=w.requesting_trx_id\g;

解釋下上面的日誌輸出:

waiting_trx_id: 被阻塞的事務id

waiting_thread:被阻塞的mysql執行緒id

waiting_query:被阻塞的sql語句

blocking_trx_id: 阻塞者的事務id

blocking_thread: 阻塞者的mysql執行緒id

blocking_query: 阻塞者的sql語句    

7、開啟日誌

setgloballog_output = 'table'; setglobalgeneral_log = 'on';

setgloballog_output = 'table'; setglobalgeneral_log = 'off';

8、匯出資料庫

例子:mysqldump -u test -p123456 --databases test > mysql.sql 或

select * from test into outfile 'c://users/admin/desktop/test.xls';

9、檢視系統變數的名稱和值

show variables ;

例如: show variables  like '%secure%';//檢視這個匯出位址,我這裡是指定的乙個地點

10、顯示使用者授予的許可權

show grants for ;

例子:

11、顯示表索引

12、顯示最後乙個錯誤

show errors; 

mysql 查詢 常用 mysql常用查詢

一.group concat函式,以指定的分割符合並列,與group by 一起用 例 selectgroup concat c.columnname separator group by 二.preparedstatement.return generated keys 得到剛剛插入記錄的id p...

mysql常用的查詢 MySQL常用查詢

資料庫 1.查詢所有資料的大小 data length 資料大小 index length 索引大小 select concat round sum data length index length 1024 1024,2 mb as data from information schema.tab...

mysql常用的查詢 MySQL常用查詢

select from unixtime create time,y m as time,sum sales amount sales amount sum from sales group by time 執行結果如下 查詢每年的銷售額 select from unixtime create ti...