下面以 CentOS 7 / 8 为例,介绍如何安装和配置 MySQL(以 MySQL 8.0 为主,兼顾 5.7)。
rpm -qa | grep mariadb
yum remove mariadb* -y
rpm -Uvh https://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm
CentOS 8 可用:
dnf install -y https://dev.mysql.com/get/mysql80-community-release-el8-1.noarch.rpm
yum install mysql-server -y
或
dnf install mysql-server -y
systemctl start mysqld
systemctl enable mysqld
systemctl status mysqld
grep 'temporary password' /var/log/mysqld.log
mysql_secure_installation
按提示:
配置文件位置:
/etc/my.cnf
示例(常用):
[mysqld]
character-set-server=utf8mb4
collation-server=utf8mb4_general_ci
bind-address=0.0.0.0
max_connections=500
修改后重启:
systemctl restart mysqld
CREATE DATABASE testdb DEFAULT CHARACTER SET utf8mb4;
CREATE USER 'testuser'@'%' IDENTIFIED BY 'Password123!';
GRANT ALL PRIVILEGES ON testdb.* TO 'testuser'@'%';
FLUSH PRIVILEGES;
firewall-cmd --add-port=3306/tcp --permanent
firewall-cmd --reload
systemctl stop mysqld
mysqld_safe --skip-grant-tables &
然后:
ALTER USER 'root'@'localhost' IDENTIFIED BY 'NewPass123!';
SET GLOBAL validate_password.policy=LOW;
如果你需要:
可以告诉我,我可以进一步说明。