`

linux_20 MySQL (Mysqladmin) Commands for Database Administration in Linux

 
阅读更多

via: http://www.tecmint.com/mysqladmin-commands-for-database-administration-in-linux/

 

mysqladmin is a command-line utility the comes with MySQL server and it is used by Database Administrators to perform some basic MySQL tasks easily such as setting root password, changing root password, monitoring mysql processes, reloading privileges, checking server status etc.

In this article we’ve compiled some very useful ‘mysqladmin‘ commands that are used by system/database administrators in their day-to-day work. You must have MySQL server installed on your system to perform these tasks.

If you don’t have MySQL server installed or you are using older version of MySQL server, then we recommend you all to install or update your version by following our below article.

  1. Installation of MySQL 5.5.28 Server on RHEL/CentOS/Fedora

1. How to set MySQL Root password?

If you have fresh installation of MySQL server, then it doesn’t required any password to connect it as root user. To set MySQL password for root user, use the following command.

# mysqladmin -u root password YOURNEWPASSWORD

2. How to Change MySQL Root password?

If you would like to change or update MySQL root password, then you need to type the following command. For example, say your old password is 123456 and you want to change it with new password say xyz123.

mysqladmin -u root -p123456 password 'xyz123'

3. How to check MySQL Server is running?

To find out whether MySQL server is up and running, use the following command.

# mysqladmin -u root -p ping

Enter password:
mysqld is alive

4. How to Check which MySQL version I am running?

The following command shows MySQL version along with the current running status .

# mysqladmin -u root -p version

Enter password:
mysqladmin  Ver 8.42 Distrib 5.5.28, for Linux on i686
Copyright (c) 2000, 2012, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Server version          5.5.28
Protocol version        10
Connection              Localhost via UNIX socket
UNIX socket             /var/lib/mysql/mysql.sock
Uptime:                 7 days 14 min 45 sec

Threads: 2  Questions: 36002  Slow queries: 0  Opens: 15  Flush tables: 1  Open tables: 8  Queries per second avg: 0.059

5. How to Find out current Status of MySQL server?

To find out current status of MySQL server, use the following command. The mysqladmincommand shows the status of uptime with running threads and queries.

# mysqladmin -u root -ptmppassword status

Enter password:
Uptime: 606704  Threads: 2  Questions: 36003  Slow queries: 0  Opens: 15  Flush tables: 1  Open tables: 8  Queries per second avg: 0.059

6. How to check status of all MySQL Server Variable’s and value’s?

To check all the running status of MySQL server variables and values, type the following command. The output would be similar to below.

# mysqladmin -u root -p extended-status

Enter password:
+------------------------------------------+-------------+
| Variable_name                            | Value       |
+------------------------------------------+-------------+
| Aborted_clients                          | 3           |
| Aborted_connects                         | 3           |
| Binlog_cache_disk_use                    | 0           |
| Binlog_cache_use                         | 0           |
| Binlog_stmt_cache_disk_use               | 0           |
| Binlog_stmt_cache_use                    | 0           |
| Bytes_received                           | 6400357     |
| Bytes_sent                               | 2610105     |
| Com_admin_commands                       | 3           |
| Com_assign_to_keycache                   | 0           |
| Com_alter_db                             | 0           |
| Com_alter_db_upgrade                     | 0           |
| Com_alter_event                          | 0           |
| Com_alter_function                       | 0           |
| Com_alter_procedure                      | 0           |
| Com_alter_server                         | 0           |
| Com_alter_table                          | 0           |
| Com_alter_tablespace                     | 0           |
+------------------------------------------+-------------+

7. How to see all MySQL server Variables and Values?

To see all the running variables and values of MySQL server, use the command as follows.

# mysqladmin  -u root -p variables

Enter password:
+---------------------------------------------------+----------------------------------------------+
| Variable_name                                     | Value                                        |
+---------------------------------------------------+----------------------------------------------+
| auto_increment_increment                          | 1                                            |
| auto_increment_offset                             | 1                                            |
| autocommit                                        | ON                                           |
| automatic_sp_privileges                           | ON                                           |
| back_log                                          | 50                                           |
| basedir                                           | /usr                                         |
| big_tables                                        | OFF                                          |
| binlog_cache_size                                 | 32768                                        |
| binlog_direct_non_transactional_updates           | OFF                                          |
| binlog_format                                     | STATEMENT                                    |
| binlog_stmt_cache_size                            | 32768                                        |
| bulk_insert_buffer_size                           | 8388608                                      |
| character_set_client                              | latin1                                       |
| character_set_connection                          | latin1                                       |
| character_set_database                            | latin1                                       |
| character_set_filesystem                          | binary                                       |
| character_set_results                             | latin1                                       |
| character_set_server                              | latin1                                       |
| character_set_system                              | utf8                                         |
| character_sets_dir                                | /usr/share/mysql/charsets/                   |
| collation_connection                              | latin1_swedish_ci                            |
+---------------------------------------------------+----------------------------------------------+

8. How to check all the running Process of MySQL server?

The following command will display all the running process of MySQL database queries.

# mysqladmin -u root -p processlist

Enter password:
+-------+---------+-----------------+---------+---------+------+-------+------------------+
| Id    | User    | Host            | db      | Command | Time | State | Info             |
+-------+---------+-----------------+---------+---------+------+-------+------------------+
| 18001 | rsyslog | localhost:38307 | rsyslog | Sleep   | 5590 |       |                  |
| 18020 | root    | localhost       |         | Query   | 0    |       | show processlist |
+-------+---------+-----------------+---------+---------+------+-------+------------------+

9. How to create a Database in MySQL server?

To create a new database in MySQL server, use the command as shown below.

# mysqladmin -u root -p create databasename

Enter password:
# mysql -u root -p

Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 18027
Server version: 5.5.28 MySQL Community Server (GPL) by Remi

Copyright (c) 2000, 2012, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| databasename       |
| mysql              |
| test               |
+--------------------+
8 rows in set (0.01 sec)

mysql>

10. How to drop a Database in MySQL server?

To drop a Database in MySQL server, use the following command. You will be asked to confirm press ‘y‘.

# mysqladmin -u root -p drop databasename

Enter password:
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 'databasename' database [y/N] y
Database "databasename" dropped

11. How to reload/refresh MySQL Privileges?

The reload command tells the server to reload the grant tables. The refresh command flushes all tables and reopens the log files.

# mysqladmin -u root -p reload;
# mysqladmin -u root -p refresh

12. How to shutdown MySQL server Safely?

To shutdown MySQL server safely, type the following command.

mysqladmin -u root -p shutdown

Enter password:

You can also use the following commands to start/stop MySQL server.

# /etc/init.d/mysqld stop
# /etc/init.d/mysqld start

13. Some useful MySQL Flush commands

Following are some useful flush commands with their description.

  1. flush-hosts: Flush all host information from host cache.
  2. flush-tables: Flush all tables.
  3. flush-threads: Flush all threads cache.
  4. flush-logs: Flush all information logs.
  5. flush-privileges: Reload the grant tables (same as reload).
  6. flush-status: Clear status variables.
# mysqladmin -u root -p flush-hosts
# mysqladmin -u root -p flush-tables
# mysqladmin -u root -p flush-threads
# mysqladmin -u root -p flush-logs
# mysqladmin -u root -p flush-privileges
# mysqladmin -u root -p flush-status

14. How to kill Sleeping MySQL Client Process?

Use the following command to identify sleeping MySQL client process.

# mysqladmin -u root -p processlist

Enter password:
+----+------+-----------+----+---------+------+-------+------------------+
| Id | User | Host      | db | Command | Time | State | Info             |
+----+------+-----------+----+---------+------+-------+------------------+
| 5  | root | localhost |    | Sleep   | 14   |       |					 |
| 8  | root | localhost |    | Query   | 0    |       | show processlist |
+----+------+-----------+----+---------+------+-------+------------------+

Now, run the following command with kill and process ID as shown below.

# mysqladmin -u root -p kill 5

Enter password:
+----+------+-----------+----+---------+------+-------+------------------+
| Id | User | Host      | db | Command | Time | State | Info             |
+----+------+-----------+----+---------+------+-------+------------------+
| 12 | root | localhost |    | Query   | 0    |       | show processlist |
+----+------+-----------+----+---------+------+-------+------------------+

If you like to kill multiple process, then pass the process ID‘s with comma separated as shown below.

# mysqladmin -u root -p kill 5,10

15. How to run multiple mysqladmin commands together?

If you would like to execute multiple ‘mysqladmin‘ commands together, then the command would be like this.

# mysqladmin  -u root -p processlist status version

Enter password:
+----+------+-----------+----+---------+------+-------+------------------+
| Id | User | Host      | db | Command | Time | State | Info             |
+----+------+-----------+----+---------+------+-------+------------------+
| 8  | root | localhost |    | Query   | 0    |       | show processlist |
+----+------+-----------+----+---------+------+-------+------------------+
Uptime: 3801  Threads: 1  Questions: 15  Slow queries: 0  Opens: 15  Flush tables: 1  Open tables: 8  Queries per second avg: 0.003
mysqladmin  Ver 8.42 Distrib 5.5.28, for Linux on i686
Copyright (c) 2000, 2012, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Server version          5.5.28
Protocol version        10
Connection              Localhost via UNIX socket
UNIX socket             /var/lib/mysql/mysql.sock
Uptime:                 1 hour 3 min 21 sec

Threads: 1  Questions: 15  Slow queries: 0  Opens: 15  Flush tables: 1  Open tables: 8  Queries per second avg: 0.003

16. How to Connect remote mysql server

To connect remote MySQL server, use the -h (host)  with IP Address of remote machine.

# mysqladmin  -h 172.16.25.126 -u root -p

17. How to execute command on remote MySQL server

Let’s say you would like to see the status of remote MySQL server, then the command would be.

# mysqladmin  -h 172.16.25.126 -u root -p status

18. How to start/stop MySQL replication on a slave server?

To start/stop MySQL replication on salve server, use the following commands.

# mysqladmin  -u root -p start-slave
# mysqladmin  -u root -p stop-slave

19. How to store MySQL server Debug Information to logs?

It tells the server to write debug information about locks in use, used memory and query usage to the MySQL log file including information about event scheduler.

# mysqladmin  -u root -p debug

Enter password:

20. How to view mysqladmin options and usage

To find out more options and usage of myslqadmin command use the help command as shown below. It will display a list of available options.

# mysqladmin --help

We have tried our best to include almost all of ‘mysqladmin‘ commands with their examples in this article, If still, we’ve missed anything, please do let us know via comments and don’t forget to share with your friends.

分享到:
评论

相关推荐

    MysqladminCommands for Database Administration in Linux

    MySQLadmin是一个与MySQL服务器一同提供的命令行工具,它使得数据库管理员能够方便地执行一些基础的MySQL任务。这篇文章将介绍20个非常实用的MySQLadmin命令,这些命令在日常工作中对系统和数据库管理员极其有用。在...

    MySQL-client-5.6.29-1.linux_glibc2.5.x86_64,MySQL-server-5.6.29-1.linux_glibc

    MySQL-client是用于与MySQL服务器进行交互的工具集,包括mysql命令行客户端、mysqladmin、mysqldump等。这些工具使得用户能够连接到MySQL服务器,执行SQL查询,管理数据库,备份和恢复数据。5.6.29版本的客户端支持...

    msql-for-Linux.zip_MYSQL_linux mysql_mysql linux

    "msql-for-Linux.zip"这个压缩包可能包含了关于如何在Linux系统上安装、配置和管理MySQL的详细资料,特别是针对"嵌入式数据库msql在Linux下的应用.png"这个文件,我们可以推测它可能是一个教程或示例,展示了MySQL在...

    linux_install_mysql.doc

    【在Linux下安装MySQL】 在Linux环境中安装MySQL数据库是一个必要的步骤,尤其对于那些需要在Linux系统上进行数据库管理的工作。本文以Red Hat 9.0操作系统和MySQL 4.0.16版本为例,详细讲解如何在Linux下安装MySQL...

    MySQL-client-5.6.29-1.linux_glibc2.5.x86_64.rar

    在这个特定的压缩包"MySQL-client-5.6.29-1.linux_glibc2.5.x86_64.rar"中,我们关注的是MySQL客户端的5.6.29版本,针对Linux操作系统,并且是为glibc 2.5编译的x86_64架构。这个版本的客户端包含了运行在64位Linux...

    mysql_client for linux 最新mysql客户端

    本文将深入探讨“mysql_client for Linux”中的最新MySQL客户端,包括其功能、安装过程以及与MySQL服务器的交互。 MySQL客户端是MySQL数据库管理系统的一部分,它允许用户通过命令行界面或编程接口(如PHP、Python...

    MySQL for Database Administrators Student Guide - Volume I

    - 理解MySQL的配置文件如***f(在Linux系统)或my.ini(在Windows系统)。 - 能够调整性能相关的参数来优化数据库性能。 2. 数据库架构设计: - 设计数据库结构,包括数据库、表、索引、视图、存储过程、触发器...

    MySQL-client-server-5.6.26-1.linux_glibc2.5.x86_64.rar

    "MySQL-client-5.6.26-1.linux_glibc2.5.x86_64.rpm"包含了一系列命令行工具,如`mysql`(用于执行SQL查询)、`mysqldump`(用于数据库备份)、`mysqladmin`(用于服务器管理任务)等。这些工具使得用户可以在终端中...

    linux中mysql开机自动启动3种方法.docx

    Linux 中 MySQL 开机自动启动 3 种方法 Linux 中 MySQL 开机自动启动是指在 Linux 系统启动时自动启动 MySQL 服务,以便提供数据库服务。本文将介绍三种实现 Linux 中 MySQL 开机自动启动的方法。 方法一:使用 ...

    linux下安装mysql服务器

    Linux 下安装 MySQL 服务器 Linux 下安装 MySQL 服务器是指在 Linux 操作系统中安装和配置 MySQL 数据库服务器的过程。MySQL 是一种关系型数据库管理系统,广泛应用于 Web 应用程序中。 知识点: 1. 安装 MySQL ...

    linux下启动mysql服务

    ### Linux 下启动、停止与重启 MySQL 服务的知识点详解 #### 一、启动 MySQL 服务的方法 在 Linux 系统中启动 MySQL 数据库服务是非常常见的操作。根据给定的文件内容,主要有以下三种方法来启动 MySQL 服务: 1....

    mysql安装包对于Linux for susemysql安装包对于Linux for susemysql安装包对于Linux

    MySQL是世界上最受欢迎的关系型数据库管理系统之一,尤其在Linux操作系统中被广泛使用。SUSE Linux Enterprise Server(SLES)是一款稳定且安全的企业级Linux发行版,它为MySQL提供了良好的支持环境。在SUSE上安装...

    mysql 监控 Monitoring_MySQL mysql_en mysql

    - 可以定期记录状态信息,例如使用`mysqladmin -i 20 extended-status >> status.log`命令每20秒记录一次。 - 还可以通过`information_schema.global_status`表来访问这些状态变量。 - 典型的状态变量包括`...

    MySQL_for_Linux安装配置.doc

    MySQL for Linux的安装配置是一个关键的步骤,尤其对于熟悉Linux系统的服务器管理员来说,理解这一过程至关重要。以下是一份详细的指南,涵盖了从下载到安装,再到配置和验证MySQL数据库服务的全过程。 首先,你...

    linux mysql rpm包

    Linux MySQL RPM包是针对Linux操作系统的一种安装MySQL数据库服务器和客户端的软件包格式。RPM(Red Hat Package Manager)是Linux世界中广泛使用的软件包管理器,它可以方便地安装、升级和卸载软件。在本例中,我们...

    NetBackup102_WebUIGuide_MySQLAdmin.pdf

    《NetBackup 10.2 Web UI MySQL 管理指南》是一份详细阐述如何使用Veritas公司的NetBackup产品通过Web界面来管理MySQL数据库的文档。NetBackup是一款强大的备份和恢复解决方案,它允许管理员保护和恢复各种数据源,...

    linux中安装mysql8.0安装包

    在Linux环境中安装MySQL 8.0是一个常见的任务,尤其对于那些需要搭建数据库服务器或进行开发工作的用户来说。MySQL 8.0是当前的稳定版本,提供了许多改进和新特性,如增强的安全性、性能优化以及更强大的数据管理...

    Linux下安装mysql

    ### Linux 下安装 MySQL 在 Linux 系统中安装 MySQL 数据库是一项常见的任务,尤其是在搭建 Web 服务器或开发环境中。本文将详细介绍如何在 Linux 系统上安装 MySQL,并提供相关的配置和管理指南。 #### 准备工作 ...

    NetBackup1011_WebUIGuide_MySQLAdmin.pdf

    MySQL 管理指南则是专门针对在 NetBackup 环境中保护 MySQL 数据库而设计的,它涵盖了如何配置和优化 MySQL 备份过程的关键步骤。MySQL 是一种广泛使用的开源关系型数据库管理系统,因此确保其数据的安全和可恢复性...

    Linux下的mysql数据库的基本操作

    mysql> create database linux; ``` **确认创建成功**: ```sql mysql> show databases; ``` 此时,`linux`数据库应该出现在数据库列表中。 **删除数据库**: ```sql mysql> drop database [数据库名]; ``` **示例*...

Global site tag (gtag.js) - Google Analytics