MySQL工做经常使用命令

一、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;

相关文章
相关标签/搜索