现在centos上默认是没有yum源的,yum安装的是 MariaDB。所以我们需要自己先配置yum源。配置yum源步骤如下:
1、下载yum源:
wget 'https://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm'
2、安装yum源
rpm -Uvh mysql57-community-release-el7-11.noarch.rpm
3、查看有哪些版本的mysql:
yum repolist all | grep mysql
4、安装
yum install -y mysql-community-server
5、启动,查看状态
systemctl start/status mysqld
6、查看临时密码,登录数据库,修改密码
grep 'temporary password' /var/log/mysqld.log
mysql -uroot -p
SET PASSWORD = PASSWORD('Admin123!');
7、开机启动
systemctl enable mysqld
systemctl daemon-reload
8、修改默认端口,并设置编码为UTF8
即修改/etc/my.cnf配置文件,在[mysqld]下添加如下配置:
[mysqld]
port=3308
character_set_server=utf8
init_connect='SET NAMES utf8'
重启mysql
systemctl restart mysqld
9、开放防火墙端口
firewall-cmd --zone=public --add-port=3308/tcp --permanent
firewall-cmd --reload
10、创建数据库并开放该数据库的远程访问权限
mysql -uroot -p
create database testsys;
GRANT ALL PRIVILEGES ON testsys.* TO 'root'@'%' IDENTIFIED BY 'Admin123!' WITH GRANT OPTION;
flush privileges;