当前位置:首页 > 系统运维 > 正文内容

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

a8116255316年前 (2010-06-09)系统运维11

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

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.  MySQL> How to check whether MySQL Server is up and running  # MySQLadmin -u root -p ping  Enter password:  MySQLd is alive3. How do I find out what version of MySQL I am running  Apart from giving the ‘Server version’, this command also displays the current status of the MySQL server.  # 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 ABSOLUTE ***  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.254. What is the current status of MySQL server  # 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.25The status command displays the following information:  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 waas 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 |  +----+------+-----------+----+---------+------+-------+------------------+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.  # 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 -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;  +--------------------+  | 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 MySQLshow 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;  +——————–+  | 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;Refresh command will flush all the tables and close/open log files.  # MySQLadmin -u root -ptmppassword refresh11. What is the safe method to shutdown the MySQL server  # 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”  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-threadsflush-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  First identify the hanging MySQL client process using the processlist command.  # 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 |  +----+------+-----------+----+---------+------+-------+------------------+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.  # 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-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 TO15. How to combine multiple MySQLadmin commands together  In the example below, you can combine process-list, status and version command to get all the output together as shown below.  # MySQLadmin -u root -ptmppassword process status version  +----+------+-----------+----+---------+------+-------+------------------+  | Id | User | Host | db | Command | Time | State | Info |  +----+------+-----------+----+---------+------+-------+------------------+  | 43 | root | localhost | | Query | 0 | | show processlist |  +----+------+-----------+----+---------+------+-------+------------------+  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 ABSOLUTE ***  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 secYou can also use the short form as shown below:  # 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.  # MySQLadmin -h 192.168.1.112 -u root -ptmppassword pro stat ver  

上述的相关内容就是对15个MySQL使用管理命令的描述,IT技术网itjs.cn整理分享给学习MySQL的朋友,希望大家喜欢这样的Mysql文章或资料。

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

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

扫描二维码推送至手机访问。

版权声明:本文由2345好导航站长资讯发布,如需转载请注明出处。

本文链接:http://www.2345hao.cn/blog/index.php/post/20959.html

分享给朋友:

“15个常用的MySQL使用管理命令示例” 的相关文章

上帝不止一个 更多Windows7 快捷模式.

上帝不止一个 更多Windows7 快捷模式.

国外媒体CNET NEWS就这个“上帝模式”和微软Windows部门主管Steven Sinofsky进行邮件交流后得知,这其实只是众多快捷方式中的一个,Sinofsky在邮件里给出了十多个这类快捷方式的关键字符串。 它们的建立方法和之前的“上帝模式”一样,在任意位置新建的一个文件夹,然后改名即可...

windows 7系统怎么取消禁ping命令?

windows 7系统怎么取消禁ping命令?

当我在虚拟机的linux系统中ping本机的ip发现ping不通,而本机可以ping通虚拟机中的ip。应该是出于安全考虑吧,Windows 7默认在防火墙里禁止了。 1、查看主机ip 打开“开始”程序中的“附件”,找到“命令提示符”打开。输入命令:ipconfig,可以看到本机的ip是192.1...

windows 7如何创建拨号连接

windows 7如何创建拨号连接

一、打开控制面板,选择“网络和共享中心”; 二、在网络和共享中心中选择“设置新的连接或网络”; 三、选择连接到Internet; 四、选择“仍要设置新的连接”; 五、选择“宽带PPPoE ”; 六、输入对应的宽带帐号及密码,点击连接即可;...

windows 7启动后检测到硬盘出错提示请立即备份文件

windows 7启动后检测到硬盘出错提示请立即备份文件

许多朋友的Windows 7系统每次启动到桌面后,都会收到一个提示:Windows检测到一个硬盘问题,请立即备份文件以防信息丢失,并联系计算机制造商以确定是否需要修复或更换硬盘。如下图情况: 碰到这种情况的朋友就需要注意了,虽然不知道当前硬盘是碰到什么问题,但在电脑还能使用的情况下,我们首先要...

windows 7系统下磁盘出错该如何手动检测修复有哪些方法

windows 7系统下磁盘出错该如何手动检测修复有哪些方法

我们在使用Windows 7系统时,一些无意中的操作很可能导致磁盘出现一些小故障,例如系统文件损坏、软件安装过程中出问题、又或者是在传输文件时停电、断电等。通常遇到这些问题,系统都会启动磁盘自动修复功能,但有时系统自动修复不成功,就需要我们手动检测修复了,许多朋友还不知道如何手动修复磁盘,下面几种方...

Ubuntu修改命令提示符PS1教程(非常详细)

Ubuntu修改命令提示符PS1教程(非常详细)

Ubuntu在使用命令的时候,有时需要修改命令提示符PS1,可很多人并不知道如何修改PS1,下面小编就给大家介绍下Ubuntu如何修改命令提示符PS1,一起来学习下吧。 命令多行输入不方便也不直观,要想修改这个命令提示符。修改~/.bashrc文件中的PS1即可。 PS1是主要的提示符设置,...