Centos7安装mysql5.7
如果没有yum则输入命令安装
yum -y install wget
下载mysql安装文件
wget https://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm
安装mysql安装源
yum -y localinstall mysql57-community-release-el7-11.noarch.rpm
在线安装MySQL
安装的依赖比较多需要等待
yum -y install mysql-community-server
启动mysql
systemctl start mysqld
设置开机自启
systemctl enable mysqld
systemctl daemon-reload
mysql安装完成之后,会在/var/log/mysqld.log文件中给root生成了一个临时的默认密码
vim /var/log/mysqld.log
KVqXHkNxv0<- 就是生成的密码
mysql -uroot -p
输入复制的密码
修改密码,必须大小写和特殊字符
ALTER USER ‘root‘@‘localhost‘ IDENTIFIED BY ‘Root@2021‘;
远程登陆开启
GRANT ALL PRIVILEGES ON *.* TO ‘root‘@‘%‘ IDENTIFIED BY ‘Root@2021‘ WITH GRANT OPTION;
退出
exit
开放3306端
firewall-cmd --zone=public --add-port=3306/tcp --permanent
firewall-cmd --reload
配置mysql编码
vim /etc//my.cnf
修改/etc/my.cnf配置文件,在[mysqld]下添加编码配置
character_set_server=utf8
init_connect=‘SET NAMES utf8‘
wq!保存退出
重启mysql
systemctl restart mysqld
测试远程连接