一、安裝
1、查看Centos版本
cat /etc/redhat-release
2檐薯、卸載之前的mysql和mariadb
rpm -qa|grep mysql
yum -y remove mariadb-libs-5.5.60-1.el7_5.x86_64
3材原、下載mysql源
wget https://repo.mysql.com//mysql80-community-release-el7-5.noarch.rpm
yum localinstall mysql80-community-release-el7-5.noarch.rpm
4、檢查下源是否包含mysql8.0
yum clean all && yum makecache
yum repolist enabled | grep "mysql.-community."
yum repolist all | grep mysql
5袖迎、安裝
yum install mysql-community-server -y
5冕臭、啟動(dòng)并設(shè)置開機(jī)自啟
systemctl start mysqld
systemctl enable mysqld
systemctl status mysqld
6腺晾、查看版本
mysql --version
7、查看初始密碼并重新設(shè)置
grep 'temporary password' /var/log/mysqld.log
mysql -u root -p //回車后輸入以上查出的密碼
ALTER USER 'root'@'localhost' IDENTIFIED BY 'root-new-password';
二辜贵、修改端口
- 編輯配置文件
vim /etc/my.cnf
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
# 加入如下配置
port=3216
- 重啟mysql
systemctl restart mysqld
三悯蝉、添加用戶
// 添加用戶
CREATE USER 'newuser'@'%' IDENTIFIED BY 'password';
//授權(quán)
GRANT ALL PRIVILEGES ON *.* TO 'username'@'%'