0
0
MysqlHow-ToBeginner · 3 min read

How to Use mysqladmin: Basic Commands and Examples

Use mysqladmin to perform administrative tasks on a MySQL server from the command line, such as checking server status, creating or dropping databases, and shutting down the server. Run commands like mysqladmin -u root -p status to check server status or mysqladmin -u root -p create dbname to create a database.
📐

Syntax

The basic syntax of mysqladmin is:

  • mysqladmin [options] command [command-arg]

Where:

  • options: Specify user credentials and connection details, e.g., -u username and -p to prompt for password.
  • command: The administrative action to perform, like status, create, drop, or shutdown.
  • command-arg: Additional argument for the command, such as the database name when creating or dropping.
bash
mysqladmin -u root -p status
mysqladmin -u root -p create mydatabase
mysqladmin -u root -p drop mydatabase
mysqladmin -u root -p shutdown
💻

Example

This example shows how to check the MySQL server status and create a new database named testdb using mysqladmin.

bash
mysqladmin -u root -p status
mysqladmin -u root -p create testdb
Output
Uptime: 3600 Threads: 2 Questions: 100 Slow queries: 0 Opens: 20 Flush tables: 1 Open tables: 15 Queries per second avg: 0.027
⚠️

Common Pitfalls

Common mistakes when using mysqladmin include:

  • Not specifying the correct user with -u or forgetting -p to prompt for a password, causing authentication errors.
  • Trying to create a database that already exists, which will cause an error.
  • Using drop without caution, as it permanently deletes the database.
  • Running commands without sufficient privileges.

Always double-check the command and user permissions before running administrative commands.

bash
mysqladmin -u root -p create testdb
# Error if testdb exists

mysqladmin -u root -p drop testdb
# Use with caution: this deletes the database permanently
📊

Quick Reference

CommandDescriptionExample
statusShow server statusmysqladmin -u root -p status
create dbnameCreate a new databasemysqladmin -u root -p create mydb
drop dbnameDelete a databasemysqladmin -u root -p drop mydb
shutdownStop the MySQL servermysqladmin -u root -p shutdown
processlistShow active MySQL processesmysqladmin -u root -p processlist

Key Takeaways

Use mysqladmin with -u and -p options to specify user and prompt for password.
Common commands include status, create, drop, and shutdown for managing MySQL server.
Be careful with drop command as it permanently deletes databases.
Check user privileges before running administrative commands to avoid permission errors.
mysqladmin is a quick way to perform server tasks without logging into the MySQL shell.