Mysqladmin 是 Mysql 自带的管理工具,我们常用它来做密码变更、检测 Mysql 是否存活、Mysql 状态查看等等。
1、查看帮助信息
2、检测 Mysql 是否存活
3、查看 Mysql 状态
4、查看 Mysql 的连接线程信息
5、还可以关闭服务 shutdown 、打印版本信息 version 、杀死线程 kill id 、重载授权表 reload 、打印可用变量 variables 等等~~
1、查看帮助信息
点击(此处)折叠或打开
- [root@Mysql ~]# mysqladmin --help ## 可以使用 --help 输出帮助信息,这里就不贴了
2、检测 Mysql 是否存活
点击(此处)折叠或打开
- [root@Mysql ~]# mysqladmin -uroot -p123456 ping ## 可以看到提示信息 " mysql is alive " 。
- Warning: Using a password on the command line interface can be insecure.
- mysqld is alive
-
- [root@Mysql ~]# mysqladmin -uroot -p123456 ping ## 当 Mysql 停止时,可以看到提示 " 连接 Mysql 失败 ",可以通过 $? 、检索 alive / failed 来判断。
- Warning: Using a password on the command line interface can be insecure.
- mysqladmin: connect to server at 'localhost' failed
- error: 'Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)'
- Check that mysqld is running and that the socket: '/tmp/mysql.sock
3、查看 Mysql 状态
点击(此处)折叠或打开
- [root@Mysql ~]# mysqladmin -uroot -p123456 status
- Warning: Using a password on the command line interface can be insecure.
- Uptime: 13 Threads: 1 Questions: 2 Slow queries: 0 Opens: 67 Flush tables: 1 Open tables: 60 Queries per second avg: 0.153
-
- ## Mysql 总运行时间,秒
- ## 活跃线程( 客户 )数
- ## 服务器启动以来客户查询数
- ## 慢查询数
- ## 服务器已经打开的数据表数
- ## 服务器已经执行 flush 、refresh 、reload 命令数
- ## 目前打开的表数
- ## 自上次运行计算,平均每秒查询次数
4、查看 Mysql 的连接线程信息
点击(此处)折叠或打开
- [root@Mysql ~]# mysqladmin -uroot -p123456 processlist
- Warning: Using a password on the command line interface can be insecure.
- +----+------+-----------+----+---------+------+-------+------------------+
- | Id | User | Host | db | Command | Time | State | Info |
- +----+------+-----------+----+---------+------+-------+------------------+
- | 2 | root | localhost | | Query | 0 | init | show processlist |
- +----+------+-----------+----+---------+------+-------+------------------+
5、还可以关闭服务 shutdown 、打印版本信息 version 、杀死线程 kill id 、重载授权表 reload 、打印可用变量 variables 等等~~