小网管 2020-09-03
下载,安装先检查系统中是否有mysql ,MariaDB,如有,先卸载
rpm -qa | grep mysql rpm -qa | grep mariadb
如图,我的系统中存在mariaDB数据,
执行卸载如有mysql同理卸载方法相同
remove mariadb-libs-5.5.52-1.el7.x86_64
安装依赖环境 ,我们直接使用yum安装,依次执行
yum install -y perl.x86_64 yum install -y libaio.x86_64 yum install -y net-tools.x86_64 yum install -y libtinfo* yum install -y libncurses*
下载国内的MySQL安装包(之所以用国内的是因为下载比较快,下面用的是清华大学的镜像资源)
wget -P /tmp http://mirrors.ustc.edu.cn/mysql-ftp/Downloads/MySQL-5.7/mysql-community-common-5.7.31-1.el7.x86_64.rpm wget -P /tmp http://mirrors.ustc.edu.cn/mysql-ftp/Downloads/MySQL-5.7/mysql-community-libs-5.7.31-1.el7.x86_64.rpm wget -P /tmp http://mirrors.ustc.edu.cn/mysql-ftp/Downloads/MySQL-5.7/mysql-community-client-5.7.31-1.el7.x86_64.rpm wget -P /tmp http://mirrors.ustc.edu.cn/mysql-ftp/Downloads/MySQL-5.7/mysql-community-server-5.7.31-1.el7.x86_64.rpm
然后按照顺序安装mysql的依赖,依次执行
rpm -ivh mysql-community-common-5.7.31-1.el7.x86_64.rpm rpm -ivh mysql-community-libs-5.7.31-1.el7.x86_64.rpm rpm -ivh mysql-community-client-5.7.31-1.el7.x86_64.rpm rpm -ivh mysql-community-server-5.7.31-1.el7.x86_64.rpm
重启下mysql服务
systemctl restart mysqld.service
查看mysql服务状态
systemctl status mysqld.service
查看下默认的临时密码,我的密码是: >dgp,9q&?ikW
grep 'temporary password' /var/log/mysqld.log
测试登录
mysql -u root -p
然后输入密码,登录成功,
修改密码并开启远程连接
由于新版本的mysql升级了密码安全策略,如果一直使用默认密码,
很多功能都限制,包括修改安全策略,开启远程连接等功能;
所以还是要先修改密码,密码要求有大小写字母,数字,特殊字符的组合;先登录
mysql -u root -p
然后修改密码
ALTER USER 'root'@'localhost' IDENTIFIED BY '~1QAZxsw2'
修改允许远程连接
use mysql; update user set Host = '%' where Host = 'localhost' and User='root'; flush privileges;
开放3306端口开启3306 端口
firewall-cmd --zone=public --add-port=3306/tcp --permanent
重启防火墙
firewall-cmd --reload
查看防火墙状态 显示success 即成功开启
systemctl status firewalld
查看指定端口状态 显示 success 即端口成功开启
firewall-cmd --query-port=6379/tcp
之后使用数据库连接工具即可连接成功;