The mysqladmin
command is a command-line administrative tool for managing MySQL database servers. It provides various administrative functions such as server shutdown, status checking, user management, and more. Here’s how you can use it:
-
To use
mysqladmin
, you need to specify the command you want to execute, followed by any required options and arguments. -
Here are some commonly used
mysqladmin
commands:-
Ping: Check if the MySQL server is running and accessible:
mysqladmin ping
-
Server Status: Get the status of the MySQL server:
mysqladmin status
-
Server Shutdown: Shutdown the MySQL server:
mysqladmin shutdown
-
Create Database: Create a new database:
mysqladmin create {{database_name}}
-
Drop Database: Delete an existing database:
mysqladmin drop {{database_name}}
-
User Management: Create, modify, or delete MySQL users:
mysqladmin -u {{username}} -p{{password}} {{command}}
Replace
{{username}}
with the MySQL username,{{password}}
with the user’s password, and{{command}}
with the specific user management command (e.g.,create
,drop
,password
, etc.). -
Change MySQL Root Password: Change the password for the MySQL root user:
mysqladmin -u root -p password {{new_password}}
Replace
{{new_password}}
with the desired new password.
-
-
mysqladmin
supports various options and flags to customize its behavior. You can refer to the official documentation or runmysqladmin --help
to see the available options.
Here are a few examples to help you understand better:
-
Check if the MySQL server is running:
mysqladmin ping
-
Get the status of the MySQL server:
mysqladmin status
-
Shutdown the MySQL server:
mysqladmin shutdown
-
Create a new database called
mydatabase
:mysqladmin create mydatabase
-
Delete an existing database called
mydatabase
:mysqladmin drop mydatabase
-
Create a new MySQL user:
mysqladmin -u root -p createuser myuser
-
Change the password for the MySQL root user:
mysqladmin -u root -p password newpassword
Remember to replace {{database_name}}
, {{username}}
, {{password}}
, and {{new_password}}
with the appropriate values for your specific use case.
Keep in mind that mysqladmin
requires proper authentication and privileges to perform certain operations, so make sure you have the necessary permissions before executing administrative commands.