如何使用mysqladmin管理mysql

54次阅读
没有评论

共计 3600 个字符,预计需要花费 9 分钟才能阅读完成。

本篇内容主要讲解“如何使用 mysqladmin 管理 mysql”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让丸趣 TV 小编来带大家学习“如何使用 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”有了更深的了解,不妨来实际操作一番吧!这里是丸趣 TV 网站,更多相关内容可以进入相关频道进行查询,关注我们,继续学习!

正文完
 
丸趣
版权声明:本站原创文章,由 丸趣 2023-08-03发表,共计3600字。
转载说明:除特殊说明外本站除技术相关以外文章皆由网络搜集发布,转载请注明出处。
评论(没有评论)