使用mysqladmin管理mysql

mysqladmin是mysql数据库中的专用管理工具,通过该工具可以完成检查服务器配置、当前状态、创建/删除数据库等操作。

 

用法:
Usage: mysqladmin [OPTIONS] command command....

 

常用参数:
● -i,--sleep=#:重复执行该命令的间隔时间。
● -r,--relative:当于-i参数联合使用并且指定了extended-status命令时,显示本次与上次之间,各状态值之间的差异。

 

常用命令:

● create databasename:创建数据库
● drop databasename:删除数据库
● extended-status:查看服务端状态信息,和在mysql命令行模式下执行show global status的功能一样。
● flush-logs:刷新日志。
● flush-status:重置状态变量。
● flush-tables:刷新所有表。
● flush-threads:刷新线程缓存。
● flush-privileges:重新加载授权表,功能与reload命令完全相同。
● refresh:刷新所有表,请切换日志文件。
● password [new-password]:修改指定用户的密码,功能与set password语句完全相同。
● ping:通过ping的方式,检查当前mysql服务是否仍能正常提供服务。
● kill id、id、...:杀掉连接至mysql服务器的线程,功能与kill id语句完全相同。
● processlist:查看当前mysql服务所有的连接线程信息。功能完全等同于show processlist语句。常用。
● shutdown:关闭数据库。常用。
● status:查看当前mysql的状态,只显示mysql命令行模式下status命令的最后一行信息。
● start-slave:启动slave服务,跟start slave语句功能完全相同。
● stop-slave:停止slave服务,跟stop slave语句功能完全相同。
● variables:显示系统变量,功能与show global variables语句完全相同。
● version:查看版本信息,同时还包括status命令的信息。

 

用法示例:
(1)创建和删除数据库
[root@oeldb1 ~]# mysqladmin -uroot -p123456 create test1
mysqladmin: [Warning] Using a password on the command line interface can be insecure.

[root@oeldb1 ~]# mysqladmin -uroot -p123456 drop test1;
mysqladmin: [Warning] Using a password on the command line interface can be insecure.
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 'test1' database [y/N] y
Database "test1" dropped

 

(2)查看状态信息
[root@oeldb1 ~]# mysqladmin -uroot -p123456 status
mysqladmin: [Warning] Using a password on the command line interface can be insecure.
Uptime: 952  Threads: 2  Questions: 12  Slow queries: 0  Opens: 109  Flush tables: 1  Open tables: 102  Queries per second avg: 0.012
其中:

● Uptime: mysql服务的启动时间。
● Threads:当前连接的会话数。
● Questions: 自mysql服务启动后,执行的查询语句数量。
● Slow queries:慢查询语句的数量。
● Opens: 当前处于打开状态的表对象的数量。
● Flush tables: 执行过flush-*、refresh和reload命令的数量。
● Open tables: 当前会话打开的表对象的数量。
● Queries per second avg: 查询的执行频率。

 

详细的状态信息:
[root@oeldb1 ~]# mysqladmin -uroot -p123456 extended-status | grep -i max
mysqladmin: [Warning] Using a password on the command line interface can be insecure.
| Connection_errors_max_connections             | 0                                                |
| Innodb_row_lock_time_max                      | 0                                                |
| Max_execution_time_exceeded                   | 0                                                |
| Max_execution_time_set                        | 0                                                |
| Max_execution_time_set_failed                 | 0                                                |
| Max_used_connections                          | 1                                                |
| Max_used_connections_time                     | 2017-06-25 21:22:48                              |
| Tc_log_max_pages_used                         | 0                                                |

 

(3)查看mysq服务是否alive
[root@oeldb1 ~]# mysqladmin -uroot -p123456 ping
mysqladmin: [Warning] Using a password on the command line interface can be insecure.
mysqld is alive

 

(4)每隔一秒输出一下当前mysql服务的状态信息:
[root@oeldb1 ~]# mysqladmin -uroot -p123456 -i 1 status
mysqladmin: [Warning] Using a password on the command line interface can be insecure.
Uptime: 1069  Threads: 2  Questions: 14  Slow queries: 0  Opens: 109  Flush tables: 1  Open tables: 102  Queries per second avg: 0.013
Uptime: 1070  Threads: 2  Questions: 15  Slow queries: 0  Opens: 109  Flush tables: 1  Open tables: 102  Queries per second avg: 0.014
Uptime: 1071  Threads: 2  Questions: 16  Slow queries: 0  Opens: 109  Flush tables: 1  Open tables: 102  Queries per second avg: 0.014
Uptime: 1072  Threads: 2  Questions: 17  Slow queries: 0  Opens: 109  Flush tables: 1  Open tables: 102  Queries per second avg: 0.015
Uptime: 1073  Threads: 2  Questions: 18  Slow queries: 0  Opens: 109  Flush tables: 1  Open tables: 102  Queries per second avg: 0.016
Uptime: 1074  Threads: 2  Questions: 19  Slow queries: 0  Opens: 109  Flush tables: 1  Open tables: 102  Queries per second avg: 0.017

 

(5)每秒执行的查询数量:
[root@oeldb1 ~]# mysqladmin -uroot -p123456 -i 1 -r extended-status | grep -e "Com_select"
mysqladmin: [Warning] Using a password on the command line interface can be insecure.
| Com_select                                    | 0                                                |
| Com_select                                    | 0                                                |
| Com_select                                    | 0                                                |
| Com_select                                    | 0                                                |
| Com_select                                    | 0                                                |

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/28536251/viewspace-2141238/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/28536251/viewspace-2141238/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值