卸载MariaDB
rpm -qa | grep -i mariadb
rpm -e --nodeps mariadb-libs-5.5.64-1.el7.x86_64
安装wget
yum install -y wget
安装mysql
wget https://repo.mysql.com//mysql80-community-release-el7-3.noarch.rpm
rpm --import https://repo.mysql.com/RPM-GPG-KEY-mysql-2022
yum -y install mysql80-community-release-el7-3.noarch.rpm
yum -y install mysql-community-server
安装5.7则修改/etc/yum.repos.d/mysql-community.repo
或者直接安装5.7
wget -i -c http://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm
rpm --import https://repo.mysql.com/RPM-GPG-KEY-mysql-2022
yum install mysql57-community-release-el7-10.noarch.rpm -y
yum -y install mysql-community-server
开启mysql并默认启动
systemctl start mysqld.service
systemctl enable mysqld.service
查看mysql默认密码
cat /var/log/mysqld.log | grep password
grep "password" /var/log/mysqld.log
配置mysql
mysql -uroot -p
alter user 'root'@'localhost' identified by 'PASSWORD';
CREATE DATABASE IF NOT EXISTS DATABASENAME DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;
CREATE USER IF NOT EXISTS 'USERNAME'@'localhost' IDENTIFIED BY 'PASSWORD';
GRANT ALL PRIVILEGES ON DATABASENAME.* TO 'USERNAME'@'localhost';
FLUSH PRIVILEGES;