15个常用的MySQL使用管理命令示例

以下的文章主要向大家描述的是15个MySQL使用管理命令的描述,我前两天在相关网站看见15个MySQL数据库使用管理命令的资料,觉得挺好,就拿出来供大家分享,望大家浏览之后会有所收获。

  1. How to change the MySQL root user password?  
  2. # MySQLadmin -u root -ptmppassword password 'newpassword'  
  3. # MySQL -u root -pnewpassword  
  4. Welcome to the MySQL monitor. Commands end with ; or \g.  
  5. Your MySQL connection id is 8  
  6. Server version: 5.1.25-rc-community MySQL Community Server (GPL)  
  7. Type 'help;' or '\h' for help. Type '\c' to clear the buffer.  
  8. MySQL> 
  9. How to check whether MySQL Server is up and running?  
  10. # MySQLadmin -u root -p ping  
  11. Enter password:  
  12. MySQLd is alive3. How do I find out what version of MySQL I am running?  
  13. Apart from giving the ‘Server version’, this command also displays the current status of the MySQL server.  
  14. # MySQLadmin -u root -ptmppassword version  
  15. MySQLadmin Ver 8.42 Distrib 5.1.25-rc, for redhat-linux-gnu on i686  
  16. Copyright (C) 2000-2006 MySQL AB  
  17. This software comes with ABSOLUTELY NO WARRANTY. This is free software,  
  18. and you are welcome to modify and redistribute it under the GPL license  
  19. Server version 5.1.25-rc-community  
  20. Protocol version 10  
  21. Connection Localhost via UNIX socket  
  22. UNIX socket /var/lib/MySQL/MySQL.sock  
  23. Uptime: 107 days 6 hours 11 min 44 sec  
  24. Threads: 1 Questions: 231976 Slow queries: 0 Opens: 17067  
  25. Flush tables: 1 Open tables: 64 Queries per second avg: 0.254. What is the current status of MySQL server?  
  26. # MySQLadmin -u root -ptmppassword status  
  27. Uptime: 9267148  
  28. Threads: 1 Questions: 231977 Slow queries: 0 Opens: 17067  
  29. Flush tables: 1 Open tables: 64 Queries per second avg: 0.25The status command displays the following information:  
  30. Uptime: Uptime of the MySQL server in seconds   
  31. Threads: Total number of clients connected to the server.   
  32. Questions: Total number of queries the server has executed since the startup.   
  33. Slow queries: Total number of queries whose execution time waas more than long_query_time variable’s value.   
  34. Opens: Total number of tables opened by the server.   
  35. Flush tables: How many times the tables were flushed.   
  36. Open tables: Total number of open tables in the database.   
  37. 5. How to view all the MySQL Server status variable and it’s current value?  
  38. # MySQLadmin -u root -ptmppassword extended-status  
  39. +-----------------------------------+-----------+  
  40. | Variable_name | Value |  
  41. +-----------------------------------+-----------+  
  42. | Aborted_clients | 579 |  
  43. | Aborted_connects | 8 |  
  44. | Binlog_cache_disk_use | 0 |  
  45. | Binlog_cache_use | 0 |  
  46. | Bytes_received | 41387238 |  
  47. | Bytes_sent | 308401407 |  
  48. | Com_admin_commands | 3524 |  
  49. | Com_assign_to_keycache | 0 |  
  50. | Com_alter_db | 0 |  
  51. | Com_alter_db_upgrade | 0 |6. How to display all MySQL server system variables and the values?  
  52. # MySQLadmin -u root -ptmppassword variables  
  53. +---------------------------------+---------------------------------+  
  54. | Variable_name | Value |  
  55. +---------------------------------+---------------------------------+  
  56. | auto_increment_increment | 1 |  
  57. | basedir | / |  
  58. | big_tables | OFF |  
  59. | binlog_format | MIXED |  
  60. | bulk_insert_buffer_size | 8388608 |  
  61. | character_set_client | latin1 |  
  62. | character_set_database | latin1 |  
  63. | character_set_filesystem | binary |  
  64. skip.....  
  65. | time_format | %H:%i:%s |  
  66. | time_zone | SYSTEM |  
  67. | timed_mutexes | OFF |  
  68. | tmpdir | /tmp |  
  69. | tx_isolation | REPEATABLE-READ |  
  70. | unique_checks | ON |  
  71. | updatable_views_with_limit | YES |  
  72. | version | 5.1.25-rc-community |  
  73. | version_comment | MySQL Community Server (GPL) |  
  74. | version_compile_machine | i686 |  
  75. | version_compile_os | redhat-linux-gnu |  
  76. | wait_timeout | 28800 |  
  77. +---------------------------------+---------------------------------+
    7. How to display all the running process/queries in the MySQL database?  
  78. # MySQLadmin -u root -ptmppassword processlist  
  79. +----+------+-----------+----+---------+------+-------+------------------+  
  80. | Id | User | Host | db | Command | Time | State | Info |  
  81. +----+------+-----------+----+---------+------+-------+------------------+  
  82. | 20 | root | localhost | | Sleep | 36 | | |  
  83. | 23 | root | localhost | | Query | 0 | | show processlist |  
  84. +----+------+-----------+----+---------+------+-------+------------------+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.  
  85. # MySQLadmin -u root -ptmppassword -i 1 processlist  
  86. +----+------+-----------+----+---------+------+-------+------------------+  
  87. | Id | User | Host | db | Command | Time | State | Info |  
  88. +----+------+-----------+----+---------+------+-------+------------------+  
  89. | 20 | root | localhost | | Sleep | 36 | | |  
  90. | 23 | root | localhost | | Query | 0 | | show processlist |  
  91. +----+------+-----------+----+---------+------+-------+------------------+  
  92. +----+------+-----------+----+---------+------+-------+------------------+  
  93. | Id | User | Host | db | Command | Time | State | Info |  
  94. +----+------+-----------+----+---------+------+-------+------------------+  
  95. | 24 | root | localhost | | Query | 0 | | show processlist |  
  96. +----+------+-----------+----+---------+------+-------+------------------+8. How to create a MySQL Database?  
  97. # MySQLadmin -u root -ptmppassword create testdb  
  98. # MySQL -u root -ptmppassword  
  99. Welcome to the MySQL monitor. Commands end with ; or \g.  
  100. Your MySQL connection id is 705  
  101. Server version: 5.1.25-rc-community MySQL Community Server (GPL)  
  102. Type 'help;' or '\h' for help. Type '\c' to clear the buffer.  
  103. MySQL> show databases;  
  104. +--------------------+  
  105. | Database |  
  106. +--------------------+  
  107. | information_schema |  
  108. | MySQL |  
  109. | sugarcrm |  
  110. | testdb |  
  111. +--------------------+  
  112. 4 rows in set (0.00 sec)  
  113. 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.  
  114. 9. How to Delete/Drop an existing MySQL database?  
  115. # MySQLadmin -u root -ptmppassword drop testdb  
  116. Dropping the database is potentially a very bad thing to do.  
  117. Any data stored in the database will be destroyed.  
  118. Do you really want to drop the 'testdb' database [y/N] y  
  119. Database “testdb” dropped  
  120. # MySQL -u root -ptmppassword  
  121. Welcome to the MySQL monitor. Commands end with ; or \g.  
  122. Your MySQL connection id is 707  
  123. Server version: 5.1.25-rc-community MySQL Community Server (GPL)  
  124. Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the buffer.  
  125. MySQL> show databases;  
  126. +——————–+  
  127. | Database |  
  128. +——————–+  
  129. | information_schema |  
  130. | MySQL |  
  131. | sugarcrm |  
  132. +——————–+  
  133. 3 rows in set (0.00 sec)10. How to reload/refresh the privilege or the grants tables?  
  134. # MySQLadmin -u root -ptmppassword reload;Refresh command will flush all the tables and close/open log files.  
  135. # MySQLadmin -u root -ptmppassword refresh11. What is the safe method to shutdown the MySQL server?  
  136. # MySQLadmin -u root -ptmppassword shutdown  
  137. # MySQL -u root -ptmppassword  
  138. ERROR 2002 (HY000): Can't connect to local MySQL server  
  139. 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”  
  140. 12. List of all MySQLadmin flush commands.  
  141. # MySQLadmin -u root -ptmppassword flush-hosts  
  142. # MySQLadmin -u root -ptmppassword flush-logs  
  143. # MySQLadmin -u root -ptmppassword flush-privileges  
  144. # MySQLadmin -u root -ptmppassword flush-status  
  145. # MySQLadmin -u root -ptmppassword flush-tables  
  146. # MySQLadmin -u root -ptmppassword flush-threadsflush-hosts: Flush all information in the host cache.   
  147. flush-privileges: Reload the grant tables (same as reload).   
  148. flush-status: Clear status variables.   
  149. flush-threads: Flush the thread cache.   
  150. 13. How to kill a hanging MySQL Client Process?  
  151. First identify the hanging MySQL client process using the processlist command.  
  152. # MySQLadmin -u root -ptmppassword processlist  
  153. +----+------+-----------+----+---------+------+-------+------------------+  
  154. | Id | User | Host | db | Command | Time | State | Info |  
  155. +----+------+-----------+----+---------+------+-------+------------------+  
  156. | 20 | root | localhost | | Sleep | 64 | | |  
  157. | 24 | root | localhost | | Query | 0 | | show processlist |  
  158. +----+------+-----------+----+---------+------+-------+------------------+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.  
  159. # MySQLadmin -u root -ptmppassword kill 20  
  160. # MySQLadmin -u root -ptmppassword processlist  
  161. +----+------+-----------+----+---------+------+-------+------------------+  
  162. | Id | User | Host | db | Command | Time | State | Info |  
  163. +----+------+-----------+----+---------+------+-------+------------------+  
  164. | 26 | root | localhost | | Query | 0 | | show processlist |  
  165. +----+------+-----------+----+---------+------+-------+------------------+14. How to start and stop MySQL replication on a slave server?  
  166. # MySQLadmin -u root -ptmppassword stop-slave  
  167. Slave stopped  
  168. # MySQLadmin -u root -ptmppassword start-slave  
  169. MySQLadmin: Error starting slave: The server is not configured as slave;  
  170. fix in config file or with CHANGE MASTER TO15. How to combine multiple MySQLadmin commands together?  
  171. In the example below, you can combine process-list, status and version command to get all the output together as shown below.  
  172. # MySQLadmin -u root -ptmppassword process status version  
  173. +----+------+-----------+----+---------+------+-------+------------------+  
  174. | Id | User | Host | db | Command | Time | State | Info |  
  175. +----+------+-----------+----+---------+------+-------+------------------+  
  176. | 43 | root | localhost | | Query | 0 | | show processlist |  
  177. +----+------+-----------+----+---------+------+-------+------------------+  
  178. Uptime: 3135  
  179. Threads: 1 Questions: 80 Slow queries: 0 Opens: 15 Flush tables: 3  
  180. Open tables: 0 Queries per second avg: 0.25  
  181. MySQLadmin Ver 8.42 Distrib 5.1.25-rc, for redhat-linux-gnu on i686  
  182. Copyright (C) 2000-2006 MySQL AB  
  183. This software comes with ABSOLUTELY NO WARRANTY. This is free software,  
  184. and you are welcome to modify and redistribute it under the GPL license  
  185. Server version 5.1.25-rc-community  
  186. Protocol version 10  
  187. Connection Localhost via UNIX socket  
  188. UNIX socket /var/lib/MySQL/MySQL.sock  
  189. Uptime: 52 min 15 secYou can also use the short form as shown below:  
  190. # MySQLadmin -u root -ptmppassword pro stat verUse the option -h, 
    to connect to a remote MySQL server and execute the MySQLadmin commands as shown below.  
  191. # MySQLadmin -h 192.168.1.112 -u root -ptmppassword pro stat ver  

 

 

上述的相关内容就是对15个MySQL使用管理命令的描述,希望会给你带来一些帮助在此方面。

原文标题:15个MySQL使用管理命令

连接:http://www.cnblogs.com/alon/archive/2010/01/21/1652849.html

【编辑推荐】

  1. 在Linux下安装MySQL 和配置 MySQL实战演习
  2. .NET访问MySQL数据库的经验漫谈
  3. Java连接MYSQL 数据库的连接步骤
  4. MySQL存储过程的创建步骤描述
  5. 忘记MySQLroot密码的解决方案

 

文章来源网络,作者:管理,如若转载,请注明出处:https://shuyeidc.com/wp/231317.html<

(0)
管理的头像管理
上一篇2025-04-19 15:41
下一篇 2025-04-19 15:42

相关推荐

  • 站群服务器和普通服务器到底哪个更适合GEO,怎么选?

    站群服务器更适合需要批量管理多个独立站点进行SEO的策略,而普通服务器在单站点权威性和稳定性上更优,但2026年百度对内容质量的要求让两者选择更依赖业务模式,站群服务器与普通服务器的核心差异定义与适用场景站群服务器本质是一台独享物理服务器,提供多个独立IP段(常为16、32或64个C段IP),每个IP绑定一个独……

    2026-07-28
    0
  • 物理服务器和云服务器做站群到底选哪个,哪个更稳定?

    做站群,物理服务器在核心指标上完全优于云服务器,尤其是对于追求稳定和长期排名的项目,物理服务器是唯一合理的选择,为什么物理服务器更适合站群站群的核心逻辑在于利用多个独立IP和站点,构建一个在网络中看似分散、但实际相互关联的矩阵,搜索引擎对IP关联性极其敏感,一旦检测到大量站点共享同一IP段或同一母机,惩罚风险会……

    2026-07-28
    0
  • 国内高防服务器哪家防御真实靠谱,怎么选?

    国内高防服务器哪家防御真实靠谱?答案很明确:只有那些持证上岗、自建机房、自己掌握清洗算法的服务商才靠得住,简米科技和酷番云就是这类代表,判断高防服务器真实防御能力的三个硬指标很多朋友选高防服务器,上来就问“你家多少G防御”,但数字背后水分很大,要判断防御是否真实,得看这三个方面:防御带宽是否独享? 有些服务商宣……

    2026-07-28
    0
  • 裸金属服务器和物理服务器有什么区别?,怎么选?

    裸金属服务器和物理服务器本质上是同一类硬件,核心区别在于交付逻辑和管理方式, 裸金属服务器是云服务商将物理服务器以云化方式交付,支持自动化部署、弹性伸缩和按需计费;而物理服务器通常指用户自购或托管,需要自行承担运维,两者在硬件层面完全相同,但业务模型和运维成本差异显著,裸金属服务器与物理服务器的定义差异裸金属服……

    2026-07-28
    0
  • 做GEO站群选哪家服务器服务商靠谱,怎么选?

    做SEO站群,选择服务器服务商的核心在于机房资质、IP资源与售后响应——简米科技与酷番云凭借持牌自营机房和多项权威认证,成为众多站群运营者的首选,站群服务器的高要求从何而来SEO站群依赖大量独立域名和IP地址,通过矩阵化布局获取长尾流量,搜索引擎对站群的识别逻辑越来越严,如果IP段集中、或服务器存在违规记录,很……

    2026-07-28
    0

发表回复

您的邮箱地址不会被公开。必填项已用 * 标注