mysqladmin
是一个MySQL
服务器命令行工具,它由Database Administrators
执行一些基本的命令诸如更改 root 密码、监控 mysql 进程、重新加载权限、检查服务器状态等任务。
如果你想更改MySQL
root
密码,然后你需要键入以下命令。
123456
rumenz123
> mysqladmin -u root -p 123456 password rumenz123
查看
MySQL
服务器运行状态
> mysqladmin -u root -p ping
Enter password:
mysqld is alive
显示
MySQL
版本以及当前运行状态。
> mysqladmin -u root -p version
Enter password:
mysqladmin Ver 8.0.27 for macos10.14 on x86_64 (Homebrew)
Copyright (c) 2000, 2021, Oracle and/or its affiliates.
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.27
Protocol version 10
Connection Localhost via UNIX socket
UNIX socket /tmp/mysql.sock
Uptime: 5 days 5 hours 46 min 40 sec
Threads: 2 Questions: 140408 Slow queries: 0 Opens: 727 Flush tables: 3 Open tables: 624 Queries per second avg: 0.310
查看当前
MySQL
服务器状态。mysqladmin
命令显示状态uptime
,threads
和queries
.
> mysqladmin -u root -p status
Uptime: 452778 Threads: 2 Questions: 140406 Slow queries: 0 Opens: 727 Flush tables: 3 Open tables: 624 Queries per second avg: 0.310
检查
MySQL
服务器变量和值
> mysqladmin -u root -p extended-status
Enter password:
+------------------------------------------+-------------+
| Variable_name | Value |
+------------------------------------------+-------------+
| Aborted_clients | 3 |
| Aborted_connects | 3 |
| Binlog_cache_disk_use | 0 |
| Binlog_cache_use | 0 |
| Binlog_stmt_cache_disk_use | 0 |
| Binlog_stmt_cache_use | 0 |
| Bytes_received | 6400357 |
| Bytes_sent | 2610105 |
| Com_admin_commands | 3 |
| Com_assign_to_keycache | 0 |
| Com_alter_db | 0 |
| Com_alter_db_upgrade | 0 |
| Com_alter_event | 0 |
| Com_alter_function | 0 |
| Com_alter_procedure | 0 |
| Com_alter_server | 0 |
| Com_alter_table | 0 |
| Com_alter_tablespace | 0 |
+------------------------------------------+-------------+
查看
MySQL
变量和值
> mysqladmin -u root -p variables
Enter password:
+---------------------------------------------------+----------------------------------------------+
| Variable_name | Value |
+---------------------------------------------------+----------------------------------------------+
| auto_increment_increment | 1 |
| auto_increment_offset | 1 |
| autocommit | ON |
| automatic_sp_privileges | ON |
| back_log | 50 |
| basedir | /usr |
| big_tables | OFF |
| binlog_cache_size | 32768 |
| binlog_direct_non_transactional_updates | OFF |
| binlog_format | STATEMENT |
| binlog_stmt_cache_size | 32768 |
| bulk_insert_buffer_size | 8388608 |
| character_set_client | latin1 |
| character_set_connection | latin1 |
| character_set_database | latin1 |
| character_set_filesystem | binary |
| character_set_results | latin1 |
| character_set_server | latin1 |
| character_set_system | utf8 |
| character_sets_dir | /usr/share/mysql/charsets/ |
| collation_connection | latin1_swedish_ci |
+---------------------------------------------------+----------------------------------------------+
> mysqladmin -u root -p processlist
Enter password:
+-------+---------+-----------------+---------+---------+------+-------+------------------+
| Id | User | Host | db | Command | Time | State | Info |
+-------+---------+-----------------+---------+---------+------+-------+------------------+
| 18001 | rsyslog | localhost:38307 | rsyslog | Sleep | 5590 | | |
| 18020 | root | localhost | | Query | 0 | | show processlist |
+-------+---------+-----------------+---------+---------+------+-------+------------------+
创建数据库。
> mysqladmin -u root -p create rumenz_test
Enter password:
通过
mysqladmin
创建数据库
> mysqladmin -u root -p drop rumenz_test
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 'rumenz_test' database [y/N] y
Database "rumenz_test" dropped
reload
命令告诉服务器重新加载授权表。refresh
命令刷新所有表并重新打开日志文件。
> mysqladmin -u root -p reload
> mysqladmin -u root -p refresh
> mysqladmin -u root -p shutdown
Enter password:
flush-hosts
:从主机缓存中刷新所有主机信息。flush-tables
: 刷新所有表。flush-threads
:刷新所有线程缓存。flush-logs
:刷新所有信息日志。flush-privileges
:重新加载授权表(与重新加载相同)。flush-status
:清除状态变量。# mysqladmin -u root -p flush-hosts
# mysqladmin -u root -p flush-tables
# mysqladmin -u root -p flush-threads
# mysqladmin -u root -p flush-logs
# mysqladmin -u root -p flush-privileges
# mysqladmin -u root -p flush-status
找出休眠的进程
> mysqladmin -u root -p processlist
Enter password:
+----+------+-----------+----+---------+------+-------+------------------+
| Id | User | Host | db | Command | Time | State | Info |
+----+------+-----------+----+---------+------+-------+------------------+
| 5 | root | localhost | | Sleep | 14 | | |
| 8 | root | localhost | | Query | 0 | | show processlist |
+----+------+-----------+----+---------+------+-------+------------------+
用
kill
和process ID
杀死
> mysqladmin -u root -p kill 5
Enter password:
+----+------+-----------+----+---------+------+-------+------------------+
| Id | User | Host | db | Command | Time | State | Info |
+----+------+-----------+----+---------+------+-------+------------------+
| 12 | root | localhost | | Query | 0 | | show processlist |
+----+------+-----------+----+---------+------+-------+------------------+
如果需要
kill
多个进程,用逗号分隔多个process ID
> mysqladmin -u root -p kill 5,10
同时执行多个
mysqladmin
命令
> mysqladmin -u root -p processlist status version
Enter password:
+----+------+-----------+----+---------+------+-------+------------------+
| Id | User | Host | db | Command | Time | State | Info |
+----+------+-----------+----+---------+------+-------+------------------+
| 8 | root | localhost | | Query | 0 | | show processlist |
+----+------+-----------+----+---------+------+-------+------------------+
Uptime: 3801 Threads: 1 Questions: 15 Slow queries: 0 Opens: 15 Flush tables: 1 Open tables: 8 Queries per second avg: 003
mysqladmin Ver 42 Distrib 28, for Linux on i686
Copyright (c) 2000, 2012, 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 28
Protocol version 10
Connection Localhost via UNIX socket
UNIX socket /var/lib/mysql/mysql.sock
Uptime: 1 hour 3 min 21 sec
Threads: 1 Questions: 15 Slow queries: 0 Opens: 15 Flush tables: 1 Open tables: 8 Queries per second avg: 003
连接远程
MySQL
服务器,使用-h
(host
) 和IP Address
参数
> mysqladmin -h rumenz.com -u root -p
如果想查看远程的
MySQL
服务器的status
> mysqladmin -h rumenz.com -u root -p status
要在从服务器上启动/停止MySQL 复制,使用以下命令。
> mysqladmin -u root -p start-slave
> mysqladmin -u root -p stop-slave
将有关正在使用的锁、已用内存和查询使用情况的调试信息写入
MySQL
日志文件(包括有关事件调度程序的信息)。
> mysqladmin -u root -p debug
Enter password:
了解更多
myslqadmin
命令选项和用法。
> mysqladmin --help
END
→点关注,不迷路←
文章引用微信公众号"嵌入式微处理器",如有侵权,请联系管理员删除!