MySQL 安装
在 Linux / Windows / macOS 上安装并启动 MySQL。
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 mysqlOutput
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 mysqldOutput
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';Linux(Ubuntu / Debian)
Shell
# Debian/Ubuntu
sudo apt update
sudo apt install -y mysql-server
sudo systemctl enable --now mysqlOutput
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 mysqldOutput
mysqld.service - MySQL Server
Loaded: loaded
Active: active (running)macOS / Windows
macOS 用 Homebrew:brew install mysql 然后 brew services start mysql。Windows 直接下载 MySQL Installer,按向导装好 MySQL Server 与 MySQL Workbench 即可。
初始安全配置
Shell
sudo mysql_secure_installation
# 依次设置 root 密码、移除匿名用户、禁止 root 远程登录、删除 test 库CentOS 7 上
mysqld 首次启动会生成临时 root 密码,存在 /var/log/mysqld.log,登录后必须改密码:ALTER USER 'root'@'localhost' IDENTIFIED BY 'NewPass!23';