MySQL 安装

在 Linux / Windows / macOS 上安装并启动 MySQL。

Beginner
Key Points一条命令装好服务端,再用 `systemctl` 或 `mysqld` 启动,最后用 `mysql_secure_installation` 做初始安全配置。

Linux(Ubuntu / Debian)

Shell
# Debian/Ubuntu
sudo apt update
sudo apt install -y mysql-server
sudo systemctl enable --now mysql
Output
Created symlink /etc/systemd/system/multi-user.target.wants/mysql.service
Active: active (running) since ...

Linux(CentOS / RHEL)

Shell
# 添加 MySQL 官方 yum 源后
sudo yum install -y mysql-community-server
sudo systemctl enable --now mysqld
Output
mysqld.service - MySQL Server
   Loaded: loaded
   Active: active (running)

macOS / Windows

On macOS use Homebrew: brew install mysql then brew services start mysql. On Windows, run the MySQL Installer and pick MySQL Server plus MySQL Workbench.

初始安全配置

Shell
sudo mysql_secure_installation
# 依次设置 root 密码、移除匿名用户、禁止 root 远程登录、删除 test 库
On CentOS 7 mysqld generates a temp root password in /var/log/mysqld.log; after login run ALTER USER 'root'@'localhost' IDENTIFIED BY 'NewPass!23';

Friends & Partners