15个mysql使用管理命令
15个mysql使用管理命令
1. 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>
2. How to check whether MySQL Server is up and running?
# mysqladmin -u root -p ping Enter password: mysqld is alive
3. 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 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-community Protocol version 10 Connection Localhost via UNIX socket UNIX socket /var/lib/mysql/mysql.sock Uptime: 107 days 6 hours 11 min 44 secThreads: 1 Questions: 231976 Slow queries: 0 Opens: 17067 Flush tables: 1 Open tables: 64 Queries per second avg: 0.25
4. 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.25
The 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 refresh
11. 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-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?
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 TO
15. 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.25mysqladmin Ver 8.42 Distrib 5.1.25-rc, for redhat-linux-gnu on i686 Copyright (C) 2000-2006 MySQL AB This 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-community Protocol version 10 Connection Localhost via UNIX socket UNIX socket /var/lib/mysql/mysql.sock Uptime: 52 min 15 sec
You can also use the short form as shown below:
# mysqladmin -u root -ptmppassword pro stat ver
Use 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
转载于:https://www.cnblogs.com/encounter/archive/2009/02/26/2189068.html
15个mysql使用管理命令相关推荐
- mysql : 常用管理命令
常用的show命令: show culumns from TableName [from DBName] :返回指定表的列的相关信息,DESC TableName , 相当于sqlserver 中 ...
- mysql 常用管理命令
2019独角兽企业重金招聘Python工程师标准>>> mysql提示符执行shell 方法一: system shell-command 方法二: \! shell-command ...
- mysql常用管理命令
2019独角兽企业重金招聘Python工程师标准>>> mysql 登录 mysql -u root -p 查看所有用户 SELECT DISTINCT CONCAT('User: ...
- mysql参数优化步骤_MySQL架构优化实战系列4:SQL优化步骤与常用管理命令2(转)
MySQL架构优化实战系列4:SQL优化步骤与常用管理命令 原文:http://dbaplus.cn/news-11-649-1.html 一.SQL语句优化步骤 1.查看MySQL状态及配置 sho ...
- Linux命令:MySQL系列之十一--MySQL日志管理
MySQL日志管理 SHOW GLOBAL VARIABLES LIKE '%log%':查看关于log的全局变量 一.日志分类 1.错误日志 2.一般查询日志 3.慢查询日志 4.二进制日志 ...
- upgrade lnmpa php.sh,LNMP 状态管理命令说明及Nginx、MySQL/MariaDB、PHP升级教程
状态管理命令分 LNmp状态管理命令 和 LNmpA状态管理命令,LNMPA代表的是Linux下Nginx.MySQL.PHP.Apache这种网站服务器架构,是结合LAMP与LNMP各自的优点而产生 ...
- mysql 账户管理_如何用MySQL 命令来实现账户管理
今天我们要学习的是如何用MySQL 命令的方式来对账号进行管理,我们大家都知道在实际应用中MySQL 命令可以完成多种任务,以下的文章主要是对用MySQL 命令的方式来对账号进行管理的具体内容介绍. ...
- 一个网络管理员应该掌握的mysql管理命令
一个网络管理员应该掌握的mysql管理命令 一. 数据库基本管理: 1. 登陆及退出数据库: 将root密码设置:pwd@123,并在次登陆(使用mysqladmin): 2. 显示数据库结构: 查看 ...
- ps efgrep mysql 命令_mysql常用管理命令
安装直接yum install mysql-server yum install mysql service mysqld start //启动mysql服务 登录mysql -u root -p 初 ...
- Mysql运维管理-Mysql常用基础命令实战4
单实例mysql启动和关闭方法 1.常规方法启动数据库 (1)启动mysql服务命令 [root@localhost ~]# /etc/init.d/mysqld start Starting MyS ...
最新文章
- 最新Android系统版本与API等级对应关系表
- IOT数据库选型——NOSQL,MemSQL,cassandra,Riak或者OpenTSDB,InfluxDB
- Dev-C++实现调试功能
- [Java] Hashmap分析
- javaweb mysql 连接池 c3p0 配置_JavaWeb基础—数据库连接池DBCP、C3P0
- mongodb数据库扩展名_MongoDB如何存储数据
- bzoj1934 [Shoi2007]Vote 善意的投票 最小割
- MAC下安装xgboost
- 用python爬虫抓站的一些技巧
- LabVIEW开发结构监控系统
- 游戏策划——游戏的分类
- java cnzz_cnzz 模拟请求登录(传入url get data ) demo
- 计算机网络第七版笔记--第一章
- oracle双活什么意思,什么是双活数据中心
- ISUP信令REL原因值
- VSC/SMC(十六)——自适应鲁棒滑模控制
- linux可以玩什么游戏_为什么我们要在Linux上玩游戏,与Icculus聊天等等
- 10040---微信与朋友圈后台架构
- vsto 判断是否安装插件
- windows桌面远程提示你的凭据不工作-4个解决方法
热门文章
- 阶段5 3.微服务项目【学成在线】_day02 CMS前端开发_17-CMS前端工程创建-单页面应用介绍...
- 阶段3 2.Spring_02.程序间耦合_5 编写工厂类和配置文件
- [No0000151]菜鸟理解.NET Framework中的CLI,CLS,CTS,CLR,FCL,BCL
- day03_01 Python历史、32bit和64bit系统的区别
- PCL Save VTK File With Texture Coordinates 使用PCL库来保存带纹理坐标的VTK文件
- 解决远程桌面无法复制黏贴
- CentOS 5.4 安装和卸载桌面
- ESS And 迅雷5 让我不能上网
- LoadRunner如何建立关联
- Android中SQLite,ContentProvider和ContentResolver的使用(一)