MySQL 命令

MySQL 快捷键

?			# 帮助
c			# 终止当前命令
d			# 修改命令结束符
G			# 垂直显示结果
q			# 退出数据库
T			# 将执行过程与结果写入一个文件
	
			# 重连数据库
	e			# 写入文件,同时执行多条命令
	g			# 命令结束
	h			# 帮助
					# 取消写入文件
	p			# 打印一次命令
	
			# 重连数据库
	R			# 修改命令提示符
source  (.) # 读取sql文件
status  (s) # 查看数据库状态
system  (!) # 在数据库里执行命令行命令
use     (u) # 切换数据库

prompt    (R) Change your mysql prompt.
nopager   (
) 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 环境)

mysql> help
mysql> help contents
mysql> help select
mysql> help create
mysql> help create user
mysql> help status
mysql> help show

Mysqladmin 命令(Linux 环境)

修改密码

mysqladmin -uroot -p123 password 123456

关闭数据库

# 一般多实例使用
mysqladmin -uroot -p123 -S /tmp/mysql.sock shutdown

创建数据库

[root@db03 ~]#  mysqladmin -uroot -p create zengdao
Enter password:

删除数据库

[root@db03 ~]#  mysqladmin -uroot -p drop zengdao
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 'zengdao' database [y/N] y
Database "zengdao" dropped

查看数据库配置(变量)

[root@db03 ~]#  mysqladmin -uroot -p variables | grep server_id
Enter password: 
| server_id        | 4  |
| server_id_bits   | 32 |

确认数据库状态

[root@db03 ~]#  mysqladmin -uroot -p123 ping
Warning: Using a password on the command line interface can be insecure.
mysqld is alive

查看数据库信息

[root@db03 ~]#  mysqladmin -uroot -p123 status
Warning: Using a password on the command line interface can be insecure.
Uptime: 143  Threads: 1  Questions: 22  Slow queries: 0  Opens: 70  Flush tables: 1  Open tables: 63  Queries per second avg: 0.153

刷新授权表

# 相当于在数据库中执行 flush privileges
[root@db03 ~]#  mysqladmin -uroot -p123 reload

刷新 bin_log

# 如果有主从,不要刷新 bin_log,如果没有主从,可以先刷新 bin_log 再做主从
[root@db03 ~]#  mysqladmin -uroot -p123 flush-log
原文地址:https://www.cnblogs.com/zzzwqh/p/13301021.html