15個實用的管理mysql的mysqladmin命令
15 Practical Usages of Mysqladmin Command For Administering MySQL Server
by Ramesh Natarajan on January 14, 2009
1. How to change the MySQL root user password?
# mysqladmin -u root -ptmppassword password 'newpassword'# mysql -u root -pnewpasswordWelcome to the MySQL monitor. Commands end with ; or \g.Your MySQL connection id is 8Server version: 5.1.25-rc-community MySQL Community Server (GPL)Type 'help;' or '\h' for help. Type '\c' to clear the buffer.mysql>
2. How to check whether MySQL Server is up and running?
# mysqladmin -u root -p pingEnter password:mysqld is alive
3. How do I find out what version of MySQL I am running?
# mysqladmin -u root -ptmppassword versionmysqladmin Ver 8.42 Distrib 5.1.25-rc, for redhat-linux-gnu on i686Copyright (C) 2000-2006 MySQL ABThis software comes with ABSOLUTELY NO WARRANTY. This is free software,and you are welcome to modify and redistribute it under the GPL licenseServer version 5.1.25-rc-communityProtocol version 10Connection Localhost via UNIX socketUNIX socket /var/lib/mysql/mysql.sockUptime: 107 days 6 hours 11 min 44 secThreads: 1 Questions: 231976 Slow queries: 0 Opens: 17067Flush tables: 1 Open tables: 64 Queries per second avg: 0.25
4. What is the current status of MySQL server?
# mysqladmin -u root -ptmppassword statusUptime: 9267148Threads: 1 Questions: 231977 Slow queries: 0 Opens: 17067Flush tables: 1 Open tables: 64 Queries per second avg: 0.25
-
Uptime: Uptime of the mysql server in seconds
-
Threads: Total number of clients connected to the server.
-
Questions: Total number of queries the server has executed since the startup.
-
Slow queries: Total number of queries whose execution time was more than long_query_time variable’s value.
-
Opens: Total number of tables opened by the server.
-
Flush tables: How many times the tables were flushed.
-
Open tables: Total number of open tables in the database.
5. How to view all the MySQL Server status variable and it’s current value?
# mysqladmin -u root -ptmppassword extended-status+-----------------------------------+-----------+| Variable_name | Value |+-----------------------------------+-----------+| 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 |
6. How to display all MySQL server system variables and the values?
# mysqladmin -u root -ptmppassword variables+---------------------------------+---------------------------------+| Variable_name | Value |+---------------------------------+---------------------------------+| 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 |skip.....| 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 |+---------------------------------+---------------------------------+
7. How to display all the running process/queries in the mysql database?
# mysqladmin -u root -ptmppassword processlist+----+------+-----------+----+---------+------+-------+------------------+| Id | User | Host | db | Command | Time | State | Info |+----+------+-----------+----+---------+------+-------+------------------+| 20 | root | localhost | | Sleep | 36 | | || 23 | root | localhost | | Query | 0 | | show processlist |+----+------+-----------+----+---------+------+-------+------------------+
# mysqladmin -u root -ptmppassword -i 1 processlist+----+------+-----------+----+---------+------+-------+------------------+| Id | User | Host | db | Command | Time | State | Info |+----+------+-----------+----+---------+------+-------+------------------+| 20 | root | localhost | | Sleep | 36 | | || 23 | root | localhost | | Query | 0 | | show processlist |+----+------+-----------+----+---------+------+-------+------------------++----+------+-----------+----+---------+------+-------+------------------+| Id | User | Host | db | Command | Time | State | Info |+----+------+-----------+----+---------+------+-------+------------------+| 24 | root | localhost | | Query | 0 | | show processlist |+----+------+-----------+----+---------+------+-------+------------------+
8. How to create a MySQL Database?
# mysqladmin -u root -ptmppassword create testdb# mysql -u root -ptmppasswordWelcome to the MySQL monitor. Commands end with ; or \g.Your MySQL connection id is 705Server 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;+--------------------+| Database |+--------------------+| information_schema || mysql || sugarcrm || testdb |+--------------------+4 rows in set (0.00 sec)
Note: To display all tables in a database, total number of columns, row, column types, indexes etc., use the that we discussed in our previous articles.
9. How to Delete/Drop an existing MySQL database?
# mysqladmin -u root -ptmppassword drop testdbDropping 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] yDatabase "testdb" dropped# mysql -u root -ptmppasswordWelcome to the MySQL monitor. Commands end with ; or \g.Your MySQL connection id is 707Server 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;+--------------------+| Database |+--------------------+| information_schema || mysql || sugarcrm |+--------------------+3 rows in set (0.00 sec)
10. How to reload/refresh the privilege or the grants tables?
# mysqladmin -u root -ptmppassword reload;
# mysqladmin -u root -ptmppassword refresh
11. What is the safe method to shutdown the MySQL server?
# mysqladmin -u root -ptmppassword shutdown# mysql -u root -ptmppasswordERROR 2002 (HY000): Can't connect to local MySQL serverthrough 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”
12. List of all mysqladmin flush commands.
# 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
-
flush-hosts: Flush all information in the host cache.
-
flush-privileges: Reload the grant tables (same as reload).
-
flush-status: Clear status variables.
-
flush-threads: Flush the thread cache.
13. How to kill a hanging MySQL Client Process?
# mysqladmin -u root -ptmppassword processlist+----+------+-----------+----+---------+------+-------+------------------+| Id | User | Host | db | Command | Time | State | Info |+----+------+-----------+----+---------+------+-------+------------------+| 20 | root | localhost | | Sleep | 64 | | || 24 | root | localhost | | Query | 0 | | show processlist |+----+------+-----------+----+---------+------+-------+------------------+
# mysqladmin -u root -ptmppassword kill 20# mysqladmin -u root -ptmppassword processlist+----+------+-----------+----+---------+------+-------+------------------+| Id | User | Host | db | Command | Time | State | Info |+----+------+-----------+----+---------+------+-------+------------------+| 26 | root | localhost | | Query | 0 | | show processlist |+----+------+-----------+----+---------+------+-------+------------------+
14. How to start and stop MySQL replication on a slave server?
# mysqladmin -u root -ptmppassword stop-slaveSlave stopped# mysqladmin -u root -ptmppassword start-slavemysqladmin: Error starting slave: The server is not configured as slave;fix in config file or with CHANGE MASTER TO
15. How to combine multiple mysqladmin commands together?
# mysqladmin -u root -ptmppassword process status version+----+------+-----------+----+---------+------+-------+------------------+| Id | User | Host | db | Command | Time | State | Info |+----+------+-----------+----+---------+------+-------+------------------+| 43 | root | localhost | | Query | 0 | | show processlist |+----+------+-----------+----+---------+------+-------+------------------+Uptime: 3135Threads: 1 Questions: 80 Slow queries: 0 Opens: 15 Flush tables: 3Open tables: 0 Queries per second avg: 0.25mysqladmin Ver 8.42 Distrib 5.1.25-rc, for redhat-linux-gnu on i686Copyright (C) 2000-2006 MySQL ABThis software comes with ABSOLUTELY NO WARRANTY. This is free software,and you are welcome to modify and redistribute it under the GPL licenseServer version 5.1.25-rc-communityProtocol version 10Connection Localhost via UNIX socketUNIX socket /var/lib/mysql/mysql.sockUptime: 52 min 15 sec
# mysqladmin -u root -ptmppassword pro stat ver
# mysqladmin -u root -ptmppassword pro stat ver
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/23650854/viewspace-687151/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- mysql下mysqladmin日常管理命令總結MySql
- mysqladmin 管理命令詳細應用MySql
- 使用mysqladmin管理mysqlMySql
- MySQL中強大的mysqladminMySql
- 15 條實用 Linux/Unix 磁帶管理命令Linux
- 媽咪,我找到了!15個實用的Linux find命令示例Linux
- 媽咪 我找到了! 15個實用的Linux find命令示例Linux
- Linux基礎命令---mysqladmin資料庫管理工具LinuxMySql資料庫
- MySQL:unblock with 'mysqladmin flush-hosts'MySqlBloC
- 25個實用的VMware ESXi命令
- 15個Linux Grep命令使用例項(實用、常用)Linux
- 15款最佳的MySQL管理工具和應用程式MySql
- 最最實用的30個Linux命令!Linux
- ls 命令的 20 個實用範例
- 15個超級實用的jQuery外掛jQuery
- 15個實用的CSS線上例項教程CSS
- 15個實用的PHP正規表示式PHP
- 15 個實用的 PHP 正規表示式PHP
- mysqladmin的用法簡介MySql
- 6個超實用的Sudo命令使用技巧
- 九個常用的網路命令 ,很實用!
- 【實操案例】Linux磁碟管理常用的三個命令!Linux
- 實用的top命令
- 工作中5個實用的Linux命令Linux
- 15 個鮮為人知的Unix命令
- 給Linux系統/網路管理員準備的Nmap命令的29個實用範例Linux
- 80%的人都不會的,15個Linux實用技巧Linux
- 8 個基本的 Docker 容器管理命令Docker
- 管理Websphere的10個有用命令Web
- 四個 Python 庫,實現超實用的命令列功能Python命令列
- Linux中11個比較實用的命令列Linux命令列
- 8 個實用的 Linux netcat 命令示例Linux
- 技術管理者的幾個實用技巧
- MySQL 5.5 常用的複製環境管理命令MySql
- mysql用命令增加管理帳號的方法(轉)MySql
- MySQL程式設計中的6個重要的實用技巧MySql程式設計
- Linux 下 cut 命令的 4 個基礎實用的示例Linux
- 實用的Linux命令Linux