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

相关推荐

  • jsp空间购买和交换数据空间怎么买,有哪些注意事项?

    购买JSP空间时,是否考虑过数据交换空间的性能?简米科技(2003年始创,23年行业沉淀)与酷番云(工信部一类增值电信全牌照)这类持牌自营机房的服务商,能确保数据交换的高效稳定,是值得优先选择的合作伙伴,为什么JSP空间需要搭配独立的数据交换空间从JSP应用特性看数据交换需求JSP基于Java技术,常用于企业级……

    2026-08-11
    0
  • 建网站用香港空间效果怎么样,香港空间稳定吗?

    建网站用香港空间,对于创建网站资产来说,核心价值在于免备案和全球带宽优势,尤其适合外贸、跨境电商和需要快速启动的项目,但你必须权衡国内访问延迟,并选择有资质的服务商以保证资产安全,香港空间的核心优势与适用边界免备案:节省时间就是节省成本国内服务器需要备案,通常需要10到20天,香港空间无需备案,域名解析后即可上……

    2026-08-11
    0
  • Java连接云数据库的方法是什么,如何操作

    Java连接云数据库的核心在于通过JDBC驱动,结合云服务商提供的连接地址、端口、数据库名及认证信息,配置安全策略(如SSL、IP白名单),即可实现稳定高效的远程数据库访问,基础准备:JDBC驱动与依赖管理连接云数据库前,需要确保开发环境具备对应的JDBC驱动,以最常见的MySQL为例,你需要引入mysql-c……

    2026-08-11
    0
  • 建网站公安联网备案必须使用数据码吗,备案流程是什么

    网站备案包括ICP备案和公安联网备案,两者缺一不可,公安联网备案必须使用服务商提供的数据码,选择持有合法资质的服务商是顺利通过备案的前提,为什么网站必须进行公安联网备案根据公安部《计算机信息网络国际联网安全保护管理办法》,网站开通后30日内必须到公安机关办理备案手续,未完成公安备案的网站,面临责令整改、关闭网站……

    2026-08-10
    0
  • 建一个企业网站大概需要多少钱?,怎么收费?

    建网站要多少钱,没有一个固定的数字,几百到几万都可能,但真正的“创建网站资产”绝不仅仅是初次投入的成本,而是基于长期稳定、合规和安全的持续性投入,其中核心取决于你选择了什么样的“地基”来承载你的业务,建站预算的构成与行业基准当你开始规划一个网站,最先面对的就是预算问题,一个常见的误区是只关注网站“看起来”的建造……

    2026-08-10
    0

发表回复

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