- 添加Mysql5.7仓库
sudo rpm -ivh https://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm
- 确认Mysql仓库成功添加
sudo yum repolist all | grep mysql | grep enabled
如果展示像下面,则表示成功添加仓库:
mysql-connectors-community/x86_64 MySQL Connectors Community enabled: 51
mysql-tools-community/x86_64 MySQL Tools Community enabled: 63
mysql57-community/x86_64 MySQL 5.7 Community Server enabled: 267
- 开始安装Mysql5.7
sudo yum -y install mysql-community-server
- 修改配置文件
sudo systemctl start mysqld
5.设置系统启动时自动启动
sudo systemctl enable mysqld
6.查看启动状态
sudo systemctl status mysqld
- CentOS上的root默认密码可以在文件/var/log/mysqld.log找到,通过下面命令可以打印出来
cat /var/log/mysqld.log | grep -i 'temporary password'
8.执行下面命令进行安全设置,这个命令会进行设置root密码设置,移除匿名用户,禁止root用户远程连接等
mysql_secure_installation
9.设置数据库编码为utf8 打开配置文件
sudo vim /etc/my.cnf
在[mysqld],[client],[mysql]节点下添加编码设置
[client]
default-character-set=utf8
[mysql]
default-character-set=utf8
[mysqld]
character-set-server = utf8
init-connect='SET NAMES utf8'
collation-server = utf8_unicode_ci
10.重启Mysql即可
sudo systemctl restart mysqld
11.配置root用户远程登陆
连接mysql
mysql -uroot -p
GRANT ALL PRIVILEGES ON *.* TO "root"@"%" IDENTIFIED BY 'changeMe';