1 新安装MYSQL后,设置root密码
#mysqladmin --help
# mysqladmin -u root password YOURNEWPASSWORD
2 更新ROOT 密码
mysqladmin -u root -pYOUROLDPASSWORD password 'YOURNEWPASSWORD'
3 检查MySql是否运行
# mysqladmin -u root -p ping
Enter password:
mysqld is alive
4 检查MySql版本
# mysqladmin -u root -p version
5 检查MySQL运行状态
# mysqladmin -u root -ptmppassword status
Enter password:
Uptime: 606704 Threads: 2 Questions: 36003 Slow queries: 0 Opens: 15 Flush tables: 1 Open tables: 8 Queries per second avg: 0.059
6 检查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 |
+------------------------------------------+-------------+
7 检查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 |
+---------------------------------------------------+----------------------------------
8 检查当前所有MySQL进程
# 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 |
+-------+---------+-----------------+---------+---------+------+-------+------------------+
9 创建数据库
# mysqladmin -u root -p create databasename
10 删除数据库
# mysqladmin -u root -p drop databasename
11 刷新,重载MySql 权限
# mysqladmin -u root -p reload; #重载授权的表
# mysqladmin -u root -p refresh #刷新表和日志
12 安全关闭MySQL
#mysqladmin -u root -p shutdown
# /etc/init.d/mysqld stop
# /etc/init.d/mysqld start
#sytemctl stop mysqld
13 常用flush命令
# 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
14 清理睡眠的客户进程
# 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 |
+----+------+-----------+----+---------+------+-------+------------------+
# mysqladmin -u root -p kill 5,8
Enter password:
+----+------+-----------+----+---------+------+-------+------------------+
| Id | User | Host | db | Command | Time | State | Info |
+----+------+-----------+----+---------+------+-------+------------------+
| 12 | root | localhost | | Query | 0 | | show processlist |
+----+------+-----------+----+---------+------+-------+------------------+
15 运行多参数的mysaldump,空格分开参数
# mysqladmin -u root -p processlist status version
16 远程连接
# mysqladmin -h 172.16.25.126 -u root -p
17 远程主机执行mysqladmin
# mysqladmin -h 172.16.25.126 -u root -p status
18 启动停止主从复制
# mysqladmin -u root -p start-slave
# mysqladmin -u root -p stop-slave
19 保存debug信息到log
# mysqladmin -u root -p debug