mysqladmin是mysql官方提供的shell命令行工具,它的参数都需要在shell命令行里面执行,当我们使用mysqladmin的时候,必须指定两类参数,一类是连接参数,另外一类是命令参数,连接参数用来指定相应的连接信息,而命令参数用来指定命令信息,例如可以用来检查服务器的配置和当前状态、创建和删除数据库等。它的语法如下:
1
|
mysqladmin [options] command [command-options] [command [command options]] ...
|
除此之外,还有一些相关的参数配置(代码可以左滑哦~):
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
|
--bind-address=name 绑定远程访问主机的ip地址
-i, --sleep=# 间隔多长时间执行一次。
-c, --count=# 统计计数。与i选项配合使用。
-f, --force 强制执行,删除数据库是无需确认信息,多条语句执行时忽略其中某条语句的错误。
--default-character-set=name 设置默认字符集。
-?, --help 显示帮助信息。
-h, --host=name 指定连接主机。
-u, --user=name 登录用户。
-p, --password[=name] 登录密码,如果不写于参数后,则会提示输入。
-p, --port=# 指定数据库端口。
--protocol=name 使用的连接协议。(tcp,socket,pipe,memory)
-r, --relative 显示前后两次输出的差异。必须与i选项配合使用。
-s, --silent 静默退出。
-s, --socket=name 指定socket文件。
-v, --verbose 显示更多信息。
-v, --version 显示版本信息。
-w, --wait[=#] 如果连接断开,等待指定的时间后重试
|
这么多参数,想看着比较乱,那么我们来看看它具体能够帮我们做哪些事情吧:
1.查看服务器的状态:
1
2
3
4
5
|
#每隔两秒查看一次服务器的状态
[root@dev01 ~]# mysqladmin -uroot -p -i 2 -c 2 status
enter password :
uptime: 42767 threads: 2 questions: 533 slow queries: 0 opens: 346 flush tables: open tables: queries per second avg : 0.012
uptime: threads: questions: slow queries: opens: flush tables: open tables: queries per second avg : 0.012
|
2.修改root密码:
1
2
|
#修改root密码
mysqladmin -u root -p原密码 password 'newpassword'
|
3.检查mysqlserver是否可用
1
2
3
4
|
#查询服务是否正常
[root@dev01 ~]# mysqladmin -uroot -p ping
enter password :
mysqld is alive
|
4.查询服务器的版本
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
|
[root@dev01 ~]# mysqladmin -uroot -p version
enter password :
mysqladmin ver 8.42 distrib 5.7.19, for linux-glibc2.12 on x86_64
copyright (c) 2000, 2017, 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 5.7.19
protocol version 10
connection localhost via unix socket
unix socket /tmp/mysql.sock
uptime: 12 hours 42 sec
threads: 2 questions: 538 slow queries: 0 opens: 346 flush tables: 1 open tables: 285 queries per second avg : 0.012
|
5.查看系统当前的状态值 (省略其中的部分结果)
1
2
3
4
5
6
7
8
9
10
11
12
|
[root@dev01 ~]# mysqladmin -uroot -p extended-status
enter password :
+ -----------------------------------------------+----------+
| variable_name | value |
+ -----------------------------------------------+----------+
| aborted_clients | |
| aborted_connects | |
| innodb_num_open_files | |
| innodb_truncated_status_writes | |
| uptime | |
| uptime_since_flush_status | |
+ -----------------------------------------------+----------+
|
6.查看服务器系统变量值
1
2
3
4
5
6
7
8
9
10
11
|
[root@dev01 ~]# mysqladmin -uroot -p variables
enter password :
......
| key_cache_block_size | |
| key_cache_division_limit | |
| large_files_support | on |
| large_page_size | |
| large_pages | off |
| lc_messages | en_us |
| lc_messages_dir | /usr/ local /mysql/share/ |
......
|
7.查看当前所有的进程
1
2
3
4
5
6
7
8
|
[root@dev01 ~]# mysqladmin -uroot -p processlist
enter password :
+ ----+------+----------------------+----------+---------+-------+----------+------------------+
| id | user | host | db | command | time | state | info |
+ ----+------+----------------------+----------+---------+-------+----------+------------------+
| | root | 192.168.56.102: | devopsdb | sleep | | | |
| | root | localhost | | query | | starting | show processlist |
+ ----+------+----------------------+----------+---------+-------+----------+------------------+
|
8.创建数据库
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
[root@dev01 ~]# mysqladmin -uroot -p create db_test
enter password :
[root@dev01 ~]# mysql -uroot -p
enter password :
mysql: [warning] using a password on the command line interface can be insecure.
welcome to the mysql monitor. commands end with ; or \g.
your mysql connection id is
server version: 5.7.19 mysql community server (gpl)
copyright (c) 2000, 2017, 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.
type 'help;' or '\h' for help. type '\c' to clear the current input statement.
mysql> show databases;
+ --------------------+
| database |
+ --------------------+
| information_schema |
| tkgrowdb_dbo |
| tkgrowlog_dbo |
| cydevopsdb |
| db_test |
| yeyz |
+ --------------------+
rows in set (0.00 sec)
mysql> exit
bye
|
从上面的命令我们可以看到,我们已经通过create命令创建了数据库db_test
9.删除特定的数据库:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
[root@dev01 ~]# mysqladmin -uroot -p drop db_test
enter password :
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 'db_test' database [y/n] y
database "db_test" dropped
[root@dev01 ~]# mysql -uroot -p
enter password :
welcome to the mysql monitor. commands end with ; or \g.
your mysql connection id is
server version: 5.7.19 mysql community server (gpl)
copyright (c) 2000, 2017, 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.
type 'help;' or '\h' for help. type '\c' to clear the current input statement.
mysql> show databases;
+ --------------------+
| database |
+ --------------------+
| information_schema |
| tkgrowdb_dbo |
| tkgrowlog_dbo |
| cydevopsdb |
| yeyz |
+ --------------------+
rows in set (0.00 sec)
|
在我们日常操作中,drop操作应该谨慎一些,可以看到,mysql也友好的给出了提醒。
10.重载权限表和刷新缓存(无明显输出)
1
2
3
4
|
[root@dev01 ~]# mysqladmin -uroot -p reload
enter password :
[root@dev01 ~]# mysqladmin -uroot -p refresh
enter password :
|
11.启用安全模式关闭数据库
1
2
3
4
5
6
7
8
|
[root@dev01 ~]# ps -ef|grep mysqld
root : ? :: /bin/sh /usr/ local /mysql/bin/mysqld_safe --datadir=/data/mysql --pid-file=/data/mysql/dev01.pid
mysql : ? :: /usr/ local /mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/data/mysql --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/data/mysql/mysqld.log --pid-file=/data/mysql/dev01.pid --socket=/tmp/mysql.sock
root : pts/ :: grep mysqld
[root@dev01 ~]# mysqladmin -uroot -p shutdown
enter password :
[root@dev01 ~]# ps -ef|grep mysqld
root : pts/ :: grep mysqld
|
12.各种刷新命令
1
2
3
4
5
6
|
[root@dev01 ~]# mysqladmin -u root -ptmppassword flush-hosts
[root@dev01 ~]# mysqladmin -u root -ptmppassword flush-logs
[root@dev01 ~]# mysqladmin -u root -ptmppassword flush- privileges
[root@dev01 ~]# mysqladmin -u root -ptmppassword flush-status
[root@dev01 ~]# mysqladmin -u root -ptmppassword flush-tables
[root@dev01 ~]# mysqladmin -u root -ptmppassword flush-threads
|
13.停止和启动mysql从节点复制过程
1
2
|
[root@dev01 ~]# mysqladmin -u root -p stop-slave
[root@dev01 ~]# mysqladmin -u root -p start-slave
|
以上就是mysqladmin最常用的一些功能,标注为红色的一般在工作中应用的范围及其广泛,可以多留意下。
以上就是mysql mysqladmin客户端的使用简介的详细内容,更多关于mysql mysqladmin客户端的资料请关注服务器之家其它相关文章!
原文链接:https://cloud.tencent.com/developer/article/1533616