MySQL 管理

用 mysqladmin 与系统命令做日常管理:启停、查看状态、改密码。

Beginner
Key Pointsmysqladmin 是命令行管理瑞士军刀:ping、status、processlist、create/drop 都能干。

启动与停止

Shell
sudo systemctl start mysql     # 启动
sudo systemctl stop mysql      # 停止
sudo systemctl restart mysql   # 重启
sudo systemctl status mysql    # 查看状态
Output
● mysql.service - MySQL Community Server
     Active: active (running)

mysqladmin 常用命令

Shell
mysqladmin -u root -p ping          # 探活
mysqladmin -u root -p status         # 简要状态
mysqladmin -u root -p processlist    # 当前连接
mysqladmin -u root -p create shop    # 建库
mysqladmin -u root -p drop shop      # 删库
Output
mysqladmin: [Warning] Using a password on the command line interface can be insecure.
mysqld is alive

修改 root 密码

Shell
mysqladmin -u root -p password 'NewPass!23'
Passing the password on the command line triggers an insecure-warning, not an error. In production use ~/.my.cnf or enter it interactively.

Friends & Partners