下載和準(zhǔn)備
wget https://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm
rpm -ivh mysql80-community-release-el7-3.noarch.rpm

yum倉庫中多了兩項(xiàng)
yum clean all
yum makecache

這個(gè)命令可以看到哪個(gè)是啟用的
yum會默認(rèn)安裝啟用的最新版本。
想要修改,可以編輯/etc/yum.repos.d/mysql-community.repo

修改enable的值來選擇要安裝的版本
執(zhí)行安裝:
yum install mysql-community-server
修改默認(rèn)安裝路徑
默認(rèn)是安裝在/var/lib/mysql的。 可以改為其他路徑,比如/mnt/mysql8/:
vi /etc/my.cnf
[mysqld]
datadir=/mnt/mysql8
socket=/mnt/mysql8/mysql.sock
log-error=/mnt/mysql8/mysqld.log
pid-file=/mnt/mysql8/mysqld.pid
lower-case-table-names=1
啟動
systemctl start mysqld
這一步會自動初始化數(shù)據(jù)庫,在/mnt/mysql8下創(chuàng)建系統(tǒng)數(shù)據(jù)庫:

初始
初始化以后,有一個(gè)初始化的密碼,可以在log中找到:
[root@localhost mysql8]# cat mysqld.log |grep pass
2020-01-10T06:24:01.322045Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: 0alTmIprge,C
然后登錄,需要加上參數(shù)-h127.0.0.1 (因?yàn)槲已b了docker。docker里也有mysql)
[root@localhost mysql8]# mysql -uroot -p -h127.0.0.1
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 9
Server version: 8.0.18
Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> show databases;
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
mysql>
首次登錄必須修改密碼。
三聯(lián)改密法:前兩個(gè)是簡化密碼復(fù)雜度策略限制的。
mysql> set global validate_password.policy=0;
Query OK, 0 rows affected (0.01 sec)
mysql> set global validate_password.length=6;
Query OK, 0 rows affected (0.00 sec)
mysql> ALTER USER root@localhost IDENTIFIED BY '123asd';
Query OK, 0 rows affected (0.05 sec)
配置遠(yuǎn)程登錄
三聯(lián)配置遠(yuǎn)程登錄:
mysql> create user 'root'@'%' identified by '123asd'
-> ;
Query OK, 0 rows affected (0.01 sec)
mysql> ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY '123asd';
Query OK, 0 rows affected (0.00 sec)
mysql> grant all privileges on *.* to 'root'@'%';
Query OK, 0 rows affected (0.01 sec)
mysql> flush privileges;
大功告成!

navicat連接成功