一、mysql鏈接後快捷鍵mysql
\?#幫助sql
\c#終止當前命令數據庫
\r#重連數據庫c#
\d#修改命令結束符ide
\e#寫入文件,同時執行多條命令spa
\G#垂直顯示結果命令行
\q#退出數據庫線程
\g#命令結束orm
\h#幫助server
\t#取消寫入文件
\T#將執行過程與結果寫入一個文件
\p#打印一次命令
\R#修改命令提示符
source (\.) #讀取sql文件
status (\s) #查看數據庫狀態
system (\!) #在數據庫裏執行命令行命令
use (\u) #切換數據庫
prompt (\R) Change your mysql prompt.
nopager (\n) Disable pager, print to stdout.
pager (\P) Set PAGER [to_pager]. Print the query results via PAGER.
charset (\C) Switch to another charset. Might be needed for processing binlog with multi-byte charsets.
warnings (\W) Show warnings after every statement.
nowarning (\w) Don't show warnings after every statement.
二、help命令
mysql> help
mysql> help contents
mysql> help select
mysql> help create
mysql> help create user
mysql> help status
mysql> help show
三、客戶端mysqladmin命令
1).修改密碼
mysqladmin -uroot -p123 password 123456
2).關閉數據庫
#通常多實例使用
mysqladmin -uroot -p123 -S /tmp/mysql.sock shutdown
3).建庫
[root@k8s-master1]# mysqladmin -uroot -p create hahashen
Enter password:
4).刪庫
[root@k8s-master1]# mysqladmin -uroot -p drop hahashen
Enter password:
Dropping the database is potentially a very bad thing to do.
Any data stored in the database will be destroyed.
Do you really want to drop the 'hahashen' database [y/N] y
Database "hahashen" dropped
5).查看數據庫配置
[root@k8s-master1]# mysqladmin -uroot -p variables | grep server_id
Enter password:
| server_id | 4 |
| server_id_bits | 32 |
6).確認數據庫是否啓動
[root@k8s-master1]# mysqladmin -uroot -p123 ping
7).刷新受權表
#至關於在數據庫中執行 flush privileges
[root@k8s-master1]# mysqladmin -uroot -p123 reload
8).刷新binlog
#若是有主從,不要刷新binlog,若是沒有主從,能夠先刷新binlog再作主從
[root@k8s-master1]# mysqladmin -uroot -p123 flush-log
四、今天工做遇到的問題,數據庫CPU不斷升高,持續達到85%,須要查看是那個sql致使的
1).查mysql進程id
ps -ef | grep -i mysql
2).實時查看mysql進程中佔用CPU
top -p 124468 -H
3).查看mysql數據庫中對應的線程ID
select thread_id,name ,PROCESSLIST_ID,THREAD_OS_ID from threads where thread_os_id = 124468;
4).mysql數據庫的線程ID獲取sql
select sql_text from performance_schema.events_statements_current where thread_id = 124468 \G;