一、安装
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、启动并设置开机自启
systemctl start mysqld
systemctl enable mysqld
systemctl status mysqld
6、查看版本
mysql --version
7、查看初始密码并重新设置
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';
//授权
GRANT ALL PRIVILEGES ON *.* TO 'username'@'%'