客户端执行管理操作mysql数据库的工具
mysqladmin是一个执行管理操作的客户端程序。它可以用来检查服务器的配置和当前状态、创建和删除数据库等。
mysqladmin 工具的使用格式:mysqladmin [option] command [command option]command …option
option选项
-c, --count=# Number of iterations to make. This works with -i
(--sleep) only.
-f, --force Don't ask for confirmation on drop database; with
multiple commands, continue even if an error occurs.
-C, --compress Use compression in server/client protocol.
--character-sets-dir=name
Directory for character set files.
--default-character-set=name
Set the default character set.
-?, --help Display this help and exit.
-h, --host=name Connect to host.
-b, --no-beep Turn off beep on error.
-p, --password[=name]
Password to use when connecting to server. If password is
not given it's asked from the tty.
-P, --port=# Port number to use for connection or 0 for default to, in
order of preference, my.cnf, $MYSQL_TCP_PORT,
/etc/services, built-in default (3306).
--protocol=name The protocol to use for connection (tcp, socket, pipe,
memory).
-r, --relative Show difference between current and previous values when
used with -i. Currently only works with extended-status.
-s, --silent Silently exit if one can't connect to server.
-S, --socket=name The socket file to use for connection.
-i, --sleep=# Execute commands repeatedly with a sleep between.
-u, --user=name User for login if not current user.
-v, --verbose Write more information.
-V, --version Output version information and exit.
-E, --vertical Print output vertically. Is similar to --relative, but
prints output vertically.
-w, --wait[=#] Wait and retry if connection is down.
1、查看服务器状态
[root@localhost ~]# mysqladmin -uroot -p status
Enter password:
Uptime: 388 Threads: 2 Questions: 3 Slow queries: 0 Opens: 131 Flush tables: 3 Open tables: 35 Queries per second avg: 0.007
2、修改root密码
[root@localhost ~]# mysqladmin -u root -pADmin@123 password 'Admin@123'
mysqladmin: [Warning] Using a password on the command line interface can be insecure.
Warning: Since password will be sent to server in plain text, use ssl connection to ensure password safety.
3、查看mysqlserve是否可用
[root@localhost ~]# mysqladmin -uroot -pAdmin@123 ping
mysqladmin: [Warning] Using a password on the command line interface can be insecure.
mysqld is alive
4、查看mysql版本
[root@localhost ~]# mysqladmin -uroot -pAdmin@123 version
mysqladmin: [Warning] Using a password on the command line interface can be insecure.
mysqladmin Ver 8.0.16 for Linux on x86_64 (MySQL Community Server - GPL)
Copyright (c) 2000, 2019, 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.16
Protocol version 10
Connection Localhost via UNIX socket
UNIX socket /var/lib/mysql/mysql.sock
Uptime: 11 min 8 sec
Threads: 2 Questions: 17 Slow queries: 0 Opens: 151 Flush tables: 3 Open tables: 55 Queries per second avg: 0.025
5、显示服务器的所有运行进程
[root@localhost ~]# mysqladmin -uroot -pAdmin@123 -i 1 processlist
mysqladmin: [Warning] Using a password on the command line interface can be insecure.
+----+-----------------+-----------+----+---------+------+------------------------+------------------+
| Id | User | Host | db | Command | Time | State | Info |
+----+-----------------+-----------+----+---------+------+------------------------+------------------+
| 4 | event_scheduler | localhost | | Daemon | 784 | Waiting on empty queue | |
| 15 | root | localhost | | Query | 0 | starting | show processlist |
+----+-----------------+-----------+----+---------+------+------------------------+------------------+
[root@localhost ~]# mysqladmin -uroot -pAdmin@123 processlist
mysqladmin: [Warning] Using a password on the command line interface can be insecure.
+----+-----------------+-----------+----+---------+------+------------------------+------------------+
| Id | User | Host | db | Command | Time | State | Info |
+----+-----------------+-----------+----+---------+------+------------------------+------------------+
| 4 | event_scheduler | localhost | | Daemon | 848 | Waiting on empty queue | |
| 16 | root | localhost | | Query | 0 | starting | show processlist |
+----+-----------------+-----------+----+---------+------+------------------------+------------------+
6、创建数据库
[root@localhost ~]# mysqladmin -uroot -p create data_test
[root@localhost ~]# mysql -uroot -pAdmin@123 -e 'show databases;'
mysql: [Warning] Using a password on the command line interface can be insecure.
+--------------------+
| Database |
+--------------------+
| data_test |
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
7、显示系统的所有数据库
[root@localhost ~]# mysqlshow -uroot -p
Enter password:
+--------------------+
| Databases |
+--------------------+
| data_test |
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
8、显示指定数据库中的所有表
[root@localhost ~]# mysqlshow -uroot -p mysql
Enter password:
Database: mysql
+---------------------------+
| Tables |
+---------------------------+
| columns_priv |
| component |
| db |
| default_roles |
| engine_cost |
| func |
| general_log |
| global_grants |
| gtid_executed |
| help_category |
| help_keyword |
| help_relation |
| help_topic |
| innodb_index_stats |
| innodb_table_stats |
| password_history |
| plugin |
| procs_priv |
| proxies_priv |
| role_edges |
| server_cost |
| servers |
| slave_master_info |
| slave_relay_log_info |
| slave_worker_info |
| slow_log |
| tables_priv |
| time_zone |
| time_zone_leap_second |
| time_zone_name |
| time_zone_transition |
| time_zone_transition_type |
| user |
+---------------------------+
9、显示数据库表列的统计
[root@localhost ~]# mysqlshow -uroot -p mysql -v
Enter password:
Database: mysql
+---------------------------+----------+
| Tables | Columns |
+---------------------------+----------+
| columns_priv | 7 |
| component | 3 |
| db | 22 |
| default_roles | 4 |
| engine_cost | 7 |
| func | 4 |
| general_log | 6 |
| global_grants | 4 |
| gtid_executed | 3 |
| help_category | 4 |
| help_keyword | 2 |
| help_relation | 2 |
| help_topic | 6 |
| innodb_index_stats | 8 |
| innodb_table_stats | 6 |
| password_history | 4 |
| plugin | 2 |
| procs_priv | 8 |
| proxies_priv | 7 |
| role_edges | 5 |
| server_cost | 5 |
| servers | 9 |
| slave_master_info | 28 |
| slave_relay_log_info | 9 |
| slave_worker_info | 13 |
| slow_log | 12 |
| tables_priv | 8 |
| time_zone | 2 |
| time_zone_leap_second | 2 |
| time_zone_name | 2 |
| time_zone_transition | 3 |
| time_zone_transition_type | 5 |
| user | 51 |
+---------------------------+----------+
33 rows in set.
10、显示数据库表列和行的统计
[root@localhost ~]# mysqlshow -uroot -p mysql -v -v
Enter password:
Database: mysql
+---------------------------+----------+------------+
| Tables | Columns | Total Rows |
+---------------------------+----------+------------+
| columns_priv | 7 | 0 |
| component | 3 | 1 |
| db | 22 | 2 |
| default_roles | 4 | 0 |
| engine_cost | 7 | 2 |
| func | 4 | 0 |
| general_log | 6 | 0 |
| global_grants | 4 | 23 |
| gtid_executed | 3 | 0 |
| help_category | 4 | 41 |
| help_keyword | 2 | 704 |
| help_relation | 2 | 1488 |
| help_topic | 6 | 658 |
| innodb_index_stats | 8 | 10 |
| innodb_table_stats | 6 | 3 |
| password_history | 4 | 0 |
| plugin | 2 | 0 |
| procs_priv | 8 | 0 |
| proxies_priv | 7 | 1 |
| role_edges | 5 | 0 |
| server_cost | 5 | 6 |
| servers | 9 | 0 |
| slave_master_info | 28 | 0 |
| slave_relay_log_info | 9 | 0 |
| slave_worker_info | 13 | 0 |
| slow_log | 12 | 0 |
| tables_priv | 8 | 2 |
| time_zone | 2 | 0 |
| time_zone_leap_second | 2 | 0 |
| time_zone_name | 2 | 0 |
| time_zone_transition | 3 | 0 |
| time_zone_transition_type | 5 | 0 |
| user | 51 | 4 |
+---------------------------+----------+------------+
33 rows in set.
11、删除数据库
[root@localhost ~]# mysqladmin -uroot -pAdmin@123 drop data_test
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 'data_test' database [y/N] y
Database "data_test" dropped
[root@localhost ~]# mysqlshow -uroot -p
Enter password:
+--------------------+
| Databases |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
12、重载权限信息
mysqladmin -uroot -p reload