MySQL8 mysqladmin详解

mysqladmin是一个十分轻便的数据库管理工具

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

OPTIONS:

-h, --host=name

要连接的MySQL服务器地址,可以是IP地址,也可以是域名地址

-p, --password[=name]

MySQL服务器的密码,使用时要用两个单引号''框起来例如-p'123_Test'

-u, --user=name

登录到MySQL服务器的用户,与系统用户无关

  -V, --version

查看版本MySQL服务器版本

--sleep:

周期性(秒)显示MySQL状态或其他信息,这取决于用什么选项与--sleep搭配

 
shell> mysqladmin -uroot -p'123_Test' --sleep ping

mysqld is alive
mysqld is alive
mysqld is alive
mysqld is alive
mysqld is alive

-c, --count=#

限定显示几次,例如与--sleep搭配,实现服务器状态的监控

shell> mysqladmin -uroot -p'123_Test' --sleep 1 --count 10 ping

mysqld is alive
mysqld is alive
mysqld is alive
mysqld is alive
mysqld is alive
mysqld is alive
mysqld is alive
mysqld is alive
mysqld is alive
mysqld is alive

shell> mysqladmin -uroot -p'123_Test' -i 2  -c 5 status
Uptime: 13656  Threads: 2  Questions: 292  Slow queries: 0  Opens: 187  Flush tables: 3  Open tables: 107  Queries per second avg: 0.021
Uptime: 13658  Threads: 2  Questions: 293  Slow queries: 0  Opens: 187  Flush tables: 3  Open tables: 107  Queries per second avg: 0.021
Uptime: 13660  Threads: 2  Questions: 294  Slow queries: 0  Opens: 187  Flush tables: 3  Open tables: 107  Queries per second avg: 0.021
Uptime: 13662  Threads: 2  Questions: 295  Slow queries: 0  Opens: 187  Flush tables: 3  Open tables: 107  Queries per second avg: 0.021
Uptime: 13664  Threads: 2  Questions: 296  Slow queries: 0  Opens: 187  Flush tables: 3  Open tables: 107  Queries per second avg: 0.021

command

create:

创建数据库

shell> mysqladmin -u root -p'123_Test' create testsql

drop:

删除数据库

shell> mysqladmin -u root -p'123_Test' drop testsql

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 'testsql' database [y/N] y
Database "testsql" dropped

ping:

测试目标MySQL服务器是否在线

连接成功:

shell> mysqladmin -u root -p'123_Test' ping 

mysqld is alive

因为目标服务器没有开mysql而连接失败:

shell> mysqladmin -u root -p'123_Test' -h 192.168.1.200 ping

mysqladmin: connect to server at '192.168.1.200' failed
error: 'Can't connect to MySQL server on '192.168.1.200' (113)'
Check that mysqld is running on 192.168.1.200 and that the port is 3306.
You can check this by doing 'telnet 192.168.1.200 3306'

processlist:

查看MySQL创建的进程

shell> mysqladmin -uroot -p'123_Test' processlist

+----+-----------------+-----------+----+---------+------+------------------------+------------------+
| Id | User            | Host      | db | Command | Time | State                  | Info             |
+----+-----------------+-----------+----+---------+------+------------------------+------------------+
| 4  | event_scheduler | localhost |    | Daemon  | 2552 | Waiting on empty queue |                  |
| 15 | root            | localhost |    | Query   | 0    | starting               | show processlist |
+----+-----------------+-----------+----+---------+------+------------------------+------------------+

status:

查看MySQL服务器状态

shell> mysqladmin -uroot -p'123_Test' status

Uptime: 2737  Threads: 2  Questions: 9  Slow queries: 0  Opens: 115  Flush tables: 3  Open tables: 35  Queries per second avg: 0.003

Uptime:正常运行时间(单位:秒)

Threads:正在运行的线程数

Questions:已经完成的查询数

Slow Queries:已经完成的慢查询数

Opens:打开的表数

Flush tables:刷新的表数

Open tables:打开的表数

Queries per second avg:平均每秒的查询量

extended-status:

显示MySQL的状态变量,可以实时监控运行状态(太多,不写)

variables:

显示服务器系统变量(太多,不写)

flush-privileges = reload

使MySQL重读授权表

flush-tables

关闭所有已打开的表

flush-threads

重置线程池,清除线程池内所有线程

flush-status

重置大多数MySQL状态变量

flush-logs

默认情况下刷新所有日志,或在后面加参数,指定日志类型,bianry,engine,error,general,relay,slow

flush-hosts

用于解决由于过多的DNS缓存与过多的主机登录错误信息,例如一个主机频繁地登录MySQL服务器但都认证失败了,为了服务器安全起见,MySQL会禁止该主机再次尝试登录,但如果该主机是一个合法用户,他就真的无法登陆了,所以可以使用flush-hosts参数清空主机错误信息的限制

refresh

关闭所有打开的表,并滚动日志,相当于flush-hosts与flush-logs一并执行

shutdown

直接关闭MySQL服务

version

显示MySQL版本号及相关状态信息

shell> mysqladmin -uroot -p'123_Test' version

mysqladmin  Ver 8.0.19 for Linux on x86_64 (MySQL Community Server - GPL)
Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Server version          8.0.19
Protocol version        10
Connection              Localhost via UNIX socket
UNIX socket             /var/lib/mysql/mysql.sock
Uptime:                 2 hours 6 min 12 sec

Threads: 2  Questions: 84  Slow queries: 0  Opens: 164  Flush tables: 3  Open tables: 84  Queries per second avg: 0.011

start-slave

启动从服务器的复制线程,SQL thread与I/O thread

stop-slave

停止从服务器复制线程

你可能感兴趣的:(MySQL,MySQL,mysqladmin)