15个实用的管理mysql的mysqladmin命令
2015-09-20 14:25
656 查看
15 Practical Usages of Mysqladmin Command For Administering MySQL Server
In all the 15 mysqladmin command-line examples below, tmppassword is used as the MySQL root user password. Please change this
to your MySQL root password.
1. How to change the MySQL root user password?
2. How to check whether MySQL Server is up and running?
3. How do I find out what version of MySQL I am running?
[align=justify]Apart from giving the ‘Server version’, this command also displays the current status of the mysql server.[/align]
4. What is the current status of MySQL server?
[align=justify]The status command displays the following information:[/align]
[align=justify]Uptime: Uptime of the mysql server in seconds[/align]
[align=justify]Threads: Total number of clients connected to the server.[/align]
[align=justify]Questions: Total number of queries the server has executed since the startup.[/align]
[align=justify]Slow queries: Total number of queries whose execution time was more than long_query_time variable’s value.[/align]
[align=justify]Opens: Total number of tables opened by the server.[/align]
[align=justify]Flush tables: How many times the tables were flushed.[/align]
[align=justify]Open tables: Total number of open tables in the database.[/align]
5. How to view all the MySQL Server status variable and it’s current value?
6. How to display all MySQL server system variables and the values?
7. How to display all the running process/queries in the mysql database?
You can use this command effectively to debug any performance issue and identify the query that is causing problems, by running
the command automatically every 1 second as shown below.
8. How to create a MySQL Database?
Note: To display all tables in a database, total number of columns, row, column types, indexes etc., use the mysqlshow
command that we discussed in our previous articles.
9. How to Delete/Drop an existing MySQL database?
10. How to reload/refresh the privilege or the grants tables?
[align=justify]Refresh command will flush all the tables and close/open log files.[/align]
11. What is the safe method to shutdown the MySQL server?
12. List of all mysqladmin flush commands.
[align=justify]flush-hosts: Flush all information in the host cache.[/align]
[align=justify]flush-privileges: Reload the grant tables (same as reload).[/align]
[align=justify]flush-status: Clear status variables.[/align]
[align=justify]flush-threads: Flush the thread cache.[/align]
13. How to kill a hanging MySQL Client Process?
[align=justify]First identify the hanging MySQL client process using the processlist command.[/align]
Now, use the kill command and pass the process_id as shown below. To kill multiple process you can pass comma separated process
id’s.
14. How to start and stop MySQL replication on a slave server?
15. How to combine multiple mysqladmin commands together?
[align=justify]In the example below, you can combine process-list, status and version command to get all the output together as shown below.[/align]
[align=justify]You can also use the short form. as shown below:[/align]
[align=justify]Use the option -h, to connect to a remote MySQL server and execute the mysqladmin commands as shown below.[/align]
In all the 15 mysqladmin command-line examples below, tmppassword is used as the MySQL root user password. Please change this
to your MySQL root password.
1. How to change the MySQL root user password?
# mysqladmin -u root -ptmppassword password 'newpassword' # mysql -u root -pnewpassword Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 8 Server version: 5.1.25-rc-community MySQL Community Server (GPL) Type 'help;' or '\h' for help. Type '\c' to clear the buffer. [align=justify]mysql>[/align] |
# mysqladmin -u root -p ping Enter password: mysqld is alive |
[align=justify]Apart from giving the ‘Server version’, this command also displays the current status of the mysql server.[/align]
# mysqladmin -u root -ptmppassword version mysqladmin Ver 8.42 Distrib 5.1.25-rc, for redhat-linux-gnu on i686 Copyright (C) 2000-2006 MySQL AB This software comes with ABSOLUTELY NO WARRANTY. This is free software, and you are welcome to modify and redistribute it under the GPL license Server version 5.1.25-rc-community Protocol version 10 Connection Localhost via UNIX socket UNIX socket /var/lib/mysql/mysql.sock Uptime: 107 days 6 hours 11 min 44 sec Threads: 1 Questions: 231976 Slow queries: 0 Opens: 17067 Flush tables: 1 Open tables: 64 Queries per second avg: 0.25 |
# mysqladmin -u root -ptmppassword status Uptime: 9267148 Threads: 1 Questions: 231977 Slow queries: 0 Opens: 17067 Flush tables: 1 Open tables: 64 Queries per second avg: 0.25 |
[align=justify]Uptime: Uptime of the mysql server in seconds[/align]
[align=justify]Threads: Total number of clients connected to the server.[/align]
[align=justify]Questions: Total number of queries the server has executed since the startup.[/align]
[align=justify]Slow queries: Total number of queries whose execution time was more than long_query_time variable’s value.[/align]
[align=justify]Opens: Total number of tables opened by the server.[/align]
[align=justify]Flush tables: How many times the tables were flushed.[/align]
[align=justify]Open tables: Total number of open tables in the database.[/align]
5. How to view all the MySQL Server status variable and it’s current value?
# mysqladmin -u root -ptmppassword extended-status [align=justify]+-----------------------------------+-----------+[/align] | Variable_name | Value | [align=justify]+-----------------------------------+-----------+[/align] | Aborted_clients | 579 | | Aborted_connects | 8 | | Binlog_cache_disk_use | 0 | | Binlog_cache_use | 0 | | Bytes_received | 41387238 | | Bytes_sent | 308401407 | | Com_admin_commands | 3524 | | Com_assign_to_keycache | 0 | | Com_alter_db | 0 | | Com_alter_db_upgrade | 0 | |
# mysqladmin -u root -ptmppassword variables [align=justify]+---------------------------------+---------------------------------+[/align] | Variable_name | Value | [align=justify]+---------------------------------+---------------------------------+[/align] | auto_increment_increment | 1 | | basedir | / | | big_tables | OFF | | binlog_format | MIXED | | bulk_insert_buffer_size | 8388608 | | character_set_client | latin1 | | character_set_database | latin1 | | character_set_filesystem | binary | [align=justify]skip.....[/align] | time_format | %H:%i:%s | | time_zone | SYSTEM | | timed_mutexes | OFF | | tmpdir | /tmp | | tx_isolation | REPEATABLE-READ | | unique_checks | ON | | updatable_views_with_limit | YES | | version | 5.1.25-rc-community | | version_comment | MySQL Community Server (GPL) | | version_compile_machine | i686 | | version_compile_os | redhat-linux-gnu | | wait_timeout | 28800 | [align=justify]+---------------------------------+---------------------------------+[/align] |
# mysqladmin -u root -ptmppassword processlist [align=justify]+----+------+-----------+----+---------+------+-------+------------------+[/align] | Id | User | Host | db | Command | Time | State | Info | [align=justify]+----+------+-----------+----+---------+------+-------+------------------+[/align] | 20 | root | localhost | | Sleep | 36 | | | | 23 | root | localhost | | Query | 0 | | show processlist | [align=justify]+----+------+-----------+----+---------+------+-------+------------------+[/align] |
the command automatically every 1 second as shown below.
# mysqladmin -u root -ptmppassword -i 1 processlist [align=justify]+----+------+-----------+----+---------+------+-------+------------------+[/align] | Id | User | Host | db | Command | Time | State | Info | [align=justify]+----+------+-----------+----+---------+------+-------+------------------+[/align] | 20 | root | localhost | | Sleep | 36 | | | | 23 | root | localhost | | Query | 0 | | show processlist | [align=justify]+----+------+-----------+----+---------+------+-------+------------------+[/align] [align=justify]+----+------+-----------+----+---------+------+-------+------------------+[/align] | Id | User | Host | db | Command | Time | State | Info | [align=justify]+----+------+-----------+----+---------+------+-------+------------------+[/align] | 24 | root | localhost | | Query | 0 | | show processlist | [align=justify]+----+------+-----------+----+---------+------+-------+------------------+[/align] |
# mysqladmin -u root -ptmppassword create testdb # mysql -u root -ptmppassword Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 705 Server version: 5.1.25-rc-community MySQL Community Server (GPL) Type 'help;' or '\h' for help. Type '\c' to clear the buffer. mysql> show databases; [align=justify]+--------------------+[/align] | Database | [align=justify]+--------------------+[/align] | information_schema | | mysql | | sugarcrm | | testdb | [align=justify]+--------------------+[/align] 4 rows in set (0.00 sec) |
command that we discussed in our previous articles.
9. How to Delete/Drop an existing MySQL database?
# mysqladmin -u root -ptmppassword drop testdb 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 'testdb' database [y/N] y Database "testdb" dropped # mysql -u root -ptmppassword Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 707 Server version: 5.1.25-rc-community MySQL Community Server (GPL) Type 'help;' or '\h' for help. Type '\c' to clear the buffer. mysql> show databases; [align=justify]+--------------------+[/align] | Database | [align=justify]+--------------------+[/align] | information_schema | | mysql | | sugarcrm | [align=justify]+--------------------+[/align] 3 rows in set (0.00 sec) |
# mysqladmin -u root -ptmppassword reload; |
# mysqladmin -u root -ptmppassword refresh |
# mysqladmin -u root -ptmppassword shutdown # mysql -u root -ptmppassword ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' Note: You can also use “/etc/rc.d/init.d/mysqld stop” to shutdown the server. To start the server, execute “/etc/rc.d/init.d/mysql start” |
# mysqladmin -u root -ptmppassword flush-hosts # mysqladmin -u root -ptmppassword flush-logs # mysqladmin -u root -ptmppassword flush-privileges # mysqladmin -u root -ptmppassword flush-status # mysqladmin -u root -ptmppassword flush-tables # mysqladmin -u root -ptmppassword flush-threads |
[align=justify]flush-privileges: Reload the grant tables (same as reload).[/align]
[align=justify]flush-status: Clear status variables.[/align]
[align=justify]flush-threads: Flush the thread cache.[/align]
13. How to kill a hanging MySQL Client Process?
[align=justify]First identify the hanging MySQL client process using the processlist command.[/align]
# mysqladmin -u root -ptmppassword processlist [align=justify]+----+------+-----------+----+---------+------+-------+------------------+[/align] | Id | User | Host | db | Command | Time | State | Info | [align=justify]+----+------+-----------+----+---------+------+-------+------------------+[/align] | 20 | root | localhost | | Sleep | 64 | | | | 24 | root | localhost | | Query | 0 | | show processlist | [align=justify]+----+------+-----------+----+---------+------+-------+------------------+[/align] |
id’s.
# mysqladmin -u root -ptmppassword kill 20 # mysqladmin -u root -ptmppassword processlist [align=justify]+----+------+-----------+----+---------+------+-------+------------------+[/align] | Id | User | Host | db | Command | Time | State | Info | [align=justify]+----+------+-----------+----+---------+------+-------+------------------+[/align] | 26 | root | localhost | | Query | 0 | | show processlist | [align=justify]+----+------+-----------+----+---------+------+-------+------------------+[/align] |
# mysqladmin -u root -ptmppassword stop-slave Slave stopped # mysqladmin -u root -ptmppassword start-slave mysqladmin: Error starting slave: The server is not configured as slave; fix in config file or with CHANGE MASTER TO |
[align=justify]In the example below, you can combine process-list, status and version command to get all the output together as shown below.[/align]
# mysqladmin -u root -ptmppassword process status version [align=justify]+----+------+-----------+----+---------+------+-------+------------------+[/align] | Id | User | Host | db | Command | Time | State | Info | [align=justify]+----+------+-----------+----+---------+------+-------+------------------+[/align] | 43 | root | localhost | | Query | 0 | | show processlist | [align=justify]+----+------+-----------+----+---------+------+-------+------------------+[/align] Uptime: 3135 Threads: 1 Questions: 80 Slow queries: 0 Opens: 15 Flush tables: 3 Open tables: 0 Queries per second avg: 0.25 mysqladmin Ver 8.42 Distrib 5.1.25-rc, for redhat-linux-gnu on i686 Copyright (C) 2000-2006 MySQL AB This software comes with ABSOLUTELY NO WARRANTY. This is free software, and you are welcome to modify and redistribute it under the GPL license Server version 5.1.25-rc-community Protocol version 10 Connection Localhost via UNIX socket UNIX socket /var/lib/mysql/mysql.sock Uptime: 52 min 15 sec |
# mysqladmin -u root -ptmppassword pro stat ver |
# mysqladmin -u root -ptmppassword pro stat ver |
相关文章推荐
- MySQL数据库
- mysql join中,on和where的区别
- 实现秒杀的几个想法(续)
- 深入浅出:MySQL的左连接、右连接、等值连接
- 在启动mysql的时候出现如下问题:“ERROR 2003 (HY000): Can't connect to MySQL server on 'localhost' (10061)”
- 使用LVM快照实现对mysql数据库的备份
- 如何解决mysqld dead but subsys locked
- mysql数据库登录以及用户权限增删改查
- 解决Mysql中文乱码
- mysql压力测试
- navicat for mysql导入关联的表
- 使用JMeter创建数据库(Mysql)测试
- [error handle][mysql]mysql汉字乱码
- MySQL之终端:管理数据库的基本操作
- MySQL Cluster:如何通过扩展为MySQL带来2亿QPS
- MySQL线程池总结(二)
- MYSQL线程池总结(一)
- MySQL存储过程详解 mysql 存储过程mysql存储过程详解 1. 存储过程简介 我们常用的操作数据库语言SQL语句在执行的时候需要要先编译,然后执行,而存储过程(Stored
- SSD 下的 MySQL IO 优化
- mysql replication(主从复制)(一)MS模式