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

相关推荐

  • 个人主题怎么制作?

    制作个人主题是一个将个人风格、兴趣或专业领域转化为视觉化或结构化内容的过程,无论是用于个人博客、作品集、社交媒体账号还是品牌形象,核心都是围绕“个人特色”展开,以下从定位、内容规划、视觉设计、技术实现四个维度,详细拆解制作个人主题的完整流程,明确主题定位:找到个人特色的核心主题定位是所有工作的起点,需要先回答……

    2025-11-20
    0
  • 社群营销管理关键是什么?

    社群营销的核心在于通过建立有温度、有价值、有归属感的社群,实现用户留存、转化和品牌传播,其管理需贯穿“目标定位-内容运营-用户互动-数据驱动-风险控制”全流程,以下从五个维度展开详细说明:明确社群定位与目标社群管理的首要任务是精准定位,需明确社群的核心价值(如行业交流、产品使用指导、兴趣分享等)、目标用户画像……

    2025-11-20
    0
  • 香港公司网站备案需要什么材料?

    香港公司进行网站备案是一个涉及多部门协调、流程相对严谨的过程,尤其需兼顾中国内地与香港两地的监管要求,由于香港公司注册地与中国内地不同,其网站若主要服务内地用户或使用内地服务器,需根据服务器位置、网站内容性质等,选择对应的备案路径(如工信部ICP备案或公安备案),以下从备案主体资格、流程步骤、材料准备、注意事项……

    2025-11-20
    0
  • 如何企业上云推广

    企业上云已成为数字化转型的核心战略,但推广过程中需结合行业特性、企业痛点与市场需求,构建系统性、多维度的推广体系,以下从市场定位、策略设计、执行落地及效果优化四个维度,详细拆解企业上云推广的实践路径,精准定位:明确目标企业与核心价值企业上云并非“一刀切”的方案,需先锁定目标客户群体,提炼差异化价值主张,客户分层……

    2025-11-20
    0
  • PS设计搜索框的实用技巧有哪些?

    在PS中设计一个美观且功能性的搜索框需要结合创意构思、视觉设计和用户体验考量,以下从设计思路、制作步骤、细节优化及交互预览等方面详细说明,帮助打造符合需求的搜索框,设计前的规划明确使用场景:根据网站或APP的整体风格确定搜索框的调性,例如极简风适合细线条和纯色,科技感适合渐变和发光效果,电商类则可能需要突出搜索……

    2025-11-20
    0

发表回复

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