mysqladmin Command in Linux



mysqladmin is a client for performing administrative operations on a MySQL server. It can be used to perform various tasks such as checking the server's status, creating and dropping databases, and managing user privileges.

Table of Contents

Here is a comprehensive guide to the options available with the mysqladmin command −

Understanding mysqladmin Command

mysqladmin is a powerful and versatile tool for managing MySQL servers on a Linux system. It provides a wide range of commands for performing administrative tasks, making it an essential tool for database administrators.

Installing MySQL and mysqladmin

Before using mysqladmin, you need to have MySQL installed on your Linux system. mysqladmin is included with the MySQL client package. If it's not already installed, you can install it using your package manager.

For Debian-based systems (e.g., Ubuntu)

sudo apt update
sudo apt install mysql-client
mysqladmin Command in Linux1

For Red Hat-based systems (e.g., CentOS)

sudo yum install mysql

Verify installation −

which mysqladmin
mysqladmin Command in Linux2

How to Use mysqladmin Command in Linux?

The mysqladmin command is used to perform administrative tasks on a MySQL server. The basic syntax for using mysqladmin is as follows −

mysqladmin [options] command [command-options]

Checking MySQL Server Status

One of the primary uses of mysqladmin is to check the status of the MySQL server. This can be done using the status command.

sudo mysqladmin -u root -p status
mysqladmin Command in Linux3

This command will prompt you for the root user's password and then display the server's status, including uptime, threads, queries, and more.

Creating a Database

You can create a new database using the create command.

sudo mysqladmin -u root -p create mydatabase
mysqladmin Command in Linux4

This command will prompt you for the root user's password and then create a new database named mydatabase.

Dropping a Database

To delete an existing database, use the drop command.

sudo mysqladmin -u root -p drop mydatabase
mysqladmin Command in Linux5

This command will prompt you for the root user's password and then delete the database named mydatabase.

Checking Server Variables and Status

You can check the server variables and status using the variables and extended-status commands.

sudo mysqladmin -u root -p variables
sudo mysqladmin -u root -p extended-status
mysqladmin Command in Linux6

These commands will display the server's variables and extended status information.

Shutting Down the MySQL Server

To shut down the MySQL server, use the shutdown command.

sudo mysqladmin -u root -p shutdown
mysqladmin Command in Linux7

This command will prompt you for the root user's password and then shut down the MySQL server.

Reloading Privilege Tables

If you make changes to the user privileges, you need to reload the privilege tables using the reload command.

sudo mysqladmin -u root -p reload
mysqladmin Command in Linux8

This command will prompt you for the root user's password and then reload the privilege tables.

Flushing Tables and Logs

You can flush tables and logs using the flush-tables and flush-logs commands.

sudo mysqladmin -u root -p flush-tables
sudo mysqladmin -u root -p flush-logs
mysqladmin Command in Linux9

These commands will prompt you for the root user's password and then flush the tables and logs.

Checking Server Version

To check the version of the MySQL server, use the version command.

sudo mysqladmin -u root -p version
mysqladmin Command in Linux10

This command will prompt you for the root user's password and then display the server's version information.

Ping the MySQL Server

You can check if the MySQL server is running by using the ping command.

sudo mysqladmin -u root -p ping
mysqladmin Command in Linux11

This command will prompt you for the root user's password and then check if the server is alive.

Setting Passwords

You can set or change the password for a MySQL user using the password command.

sudo mysqladmin -u root -p password 'newpassword'
mysqladmin Command in Linux12

This command will prompt you for the root user's current password and then set the new password to newpassword.

Killing a MySQL Thread

To kill a specific MySQL thread, use the kill command followed by the thread ID.

sudo mysqladmin -u root -p kill 12345
mysqladmin Command in Linux13

This command will prompt you for the root user's password and then kill the thread with ID 12345.

Checking Process List

You can check the list of currently running processes on the MySQL server using the processlist command.

sudo mysqladmin -u root -p processlist
mysqladmin Command in Linux14

This command will prompt you for the root user's password and then display the list of running processes.

Setting Server Variables

You can set server variables using the set-variable command.

sudo mysqladmin -u root -p set-variable max_connections=200
mysqladmin Command in Linux15

This command will prompt you for the root user's password and then set the max_connections variable to 200.

Checking InnoDB Status

To check the status of the InnoDB storage engine, use the innodb-status command.

mysqladmin -u root -p innodb-status
mysqladmin Command in Linux16

This command will prompt you for the root user's password and then display the InnoDB status information.

Checking Replication Status

If you are using MySQL replication, you can check the replication status using the replication-status command.

sudo mysqladmin -u root -p replication-status
mysqladmin Command in Linux17

This command will prompt you for the root user's password and then display the replication status information.

Checking Slave Status

To check the status of a MySQL slave server, use the slave-status command.

sudo mysqladmin -u root -p slave-status
mysqladmin Command in Linux18

This command will prompt you for the root user's password and then display the slave status information.

Checking Master Status

To check the status of a MySQL master server, use the master-status command.

sudo mysqladmin -u root -p master-status
mysqladmin Command in Linux19

This command will prompt you for the root user's password and then display the master status information.

Checking Binary Logs

You can check the binary logs using the binlog command.

sudo mysqladmin -u root -p binlog
mysqladmin Command in Linux20

This command will prompt you for the root user's password and then display the binary logs information.

Conclusion

mysqladmin is a powerful and versatile tool for managing MySQL servers on a Linux system. It provides a wide range of commands for performing administrative tasks, making it an essential tool for database administrators.

By understanding and using the various options and commands available in mysqladmin, you can effectively manage your MySQL server and ensure its smooth operation.

Advertisements