温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

如何使用mysqladmin管理mysql

发布时间:2021-08-05 18:28:08 来源:亿速云 阅读:278 作者:chen 栏目:MySQL数据库

本篇内容主要讲解“如何使用mysqladmin管理mysql”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习“如何使用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                                                |

到此,相信大家对“如何使用mysqladmin管理mysql”有了更深的了解,不妨来实际操作一番吧!这里是亿速云网站,更多相关内容可以进入相关频道进行查询,关注我们,继续学习!

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI