在 CentOS7 上安装 MySQL8.0.21

1, 安装

下载yum仓库,在如下url中,找到 Red Hat Enterprise Linux 7 的 rpm package。
https://dev.mysql.com/downloads/repo/yum/

# 下载回来
wget https://repo.mysql.com/mysql80-community-release-el7-3.noarch.rpm

# 安装仓库
yum -y install mysql80-community-release-el7-3.noarch.rpm

# 确认可以安装的版本
yum list | grep mysql | grep server
mysql-community-server.x86_64        8.0.21-1.el7             mysql80-community

# 安装 MySQL 
yum -y install mysql-community-server

2, 配置

# 启动MySQL
systemctl restart mysqld

# 查看状态
systemctl status mysqld

# 修改密码,初始密码在 /var/log/mysqld.log
[root@D-WY-DEV8 ~]# grep password /var/log/mysqld.log
root@localhost: dIc%e:ptD54?
[root@D-WY-DEV8 ~]# mysql -u root -p
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY '<你的密码>';
Query OK, 0 rows affected (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

# 确认一下安装的MySQL的版本
[root@do-airflow ~]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2863
Server version: 8.0.21 MySQL Community Server - GPL

# 修改datadir,如果有专门用于存放数据的磁盘分区,就要改一下这个
[root@D-WY-DEV8 ~]# systemctl stop mysqld
[root@D-WY-DEV8 ~]# mkdir /mnt/nokia/mysql-data
[root@D-WY-DEV8 ~]# mv /var/lib/mysql /mnt/nokia/mysql-data/
[root@D-WY-DEV8 ~]# ln -s /mnt/nokia/mysql-data/mysql /var/lib/
[root@D-WY-DEV8 ~]# chown -R mysql:mysql /mnt/nokia/mysql-data
[root@D-WY-DEV8 ~]# chown mysql:mysql /var/lib/mysql
[root@D-WY-DEV8 ~]# ll /var/lib/mysql
lrwxrwxrwx. 1 mysql mysql 27 7月  14 16:45 /var/lib/mysql -> /mnt/nokia/mysql-data/mysql

# 重新启动 MySQL
[root@D-WY-DEV8 ~]# systemctl start mysqld
[root@D-WY-DEV8 ~]#

# 卸载 mysql yum库
[root@D-WY-DEV8 ~]# yum -y remove mysql80-community-release-el7-3.noarch.rpm
[root@D-WY-DEV8 ~]# rm -f /etc/yum.repos.d/mysql*
[root@D-WY-DEV8 ~]# 

你可能感兴趣的:(开船,mysql,centos)