安装 MySQL8
netnr 2020-09-03
### 清理

# 查找并删除mysql(原本的残留)
rpm -qa | grep mysql # 查找
yum remove 软件包名 # 删除

# 查找并删除mariaDB
rpm -qa | grep mariadb # 查找
rpm -e --nodeps mariadb-libs-5.5.56-2.el7.x86_64 # 删除

# 查找并删除mysql配置文件
find / -name mysql # 查找
rm -rf /usr/lib64/mysql # 删完

# 更新密钥
rpm --import https://repo.mysql.com/RPM-GPG-KEY-mysql-2022

### CentOS7 安装
# 安装源,注意最新版本 https://dev.mysql.com/downloads/repo/yum/
rpm -ivh https://dev.mysql.com/get/mysql80-community-release-el7-11.noarch.rpm # 安装repo文件
yum clean all # 更新yum缓存
yum makecache
yum list | grep mysql # 查看可用
yum install mysql-community-server # 安装

# CentOS8 安装
# ref https://qiita.com/yasushi-jp/items/1579c301075d693a2a36
# 安装源,注意最新版本 https://dev.mysql.com/downloads/repo/yum/
dnf localinstall https://dev.mysql.com/get/mysql80-community-release-el8-9.noarch.rpm
cd /etc/yum.repos.d && ls -l # 查看源
dnf repolist enabled | grep "mysql.*-community.*" # 启用 MySQL 存储库
dnf module disable mysql # 禁用默认 MySQL 模块
dnf info mysql-community-server # 确认安装信息
dnf install mysql-community-server # 安装 MySQL
mysqld --version # 查看版本

systemctl start mysqld # 启动服务
systemctl status mysqld # 查看服务
systemctl enable mysqld # 开机启动

mysql -uroot -p # 登录

grep 'temporary password' /var/log/mysqld.log # 查找临时密码

mysql_secure_installation # 设置 MySQL 安全部署,输入 y, 需要开启远程登录则输入 n
# 修改 root 密码,删除匿名用户,阻止 root 远程登录,删除测试数据库

# 设置身份验证
# MySQL 8.0 开始,身份验证默认值为 caching_sha2_password 而不是 mysql_native_password
# 可取消配置文件注释 /etc/my.cnf
default-authentication-plugin=mysql_native_password
# 设置端口号
prot=3307

# 允许远程访问
use mysql;
select host,user from user;
UPDATE user SET Host='%' WHERE User='root' AND Host='localhost' LIMIT 1;
flush privileges;


# Ubuntu
apt install @mysql
# 允许远程访问
vi /etc/mysql/mysql.conf.d/mysqld.cnf # 屏蔽 bind-address 
# 更改范围
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%';
UPDATE mysql.user SET host='%' WHERE user='root'; 

ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY '123'; # 修改密码
flush privileges; # 刷新生效


### help
https://blog.csdn.net/qq_40243950/article/details/106651484
登录写评论