CentOS安装Mysql步骤
-
下载wget命令
yum -y install wget
-
在线下载安装包
wget https://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm
-
安装Mysql
rpm -ivh mysql57-community-release-el7-8.noarch.rpm
-
安装MySQL服务(这个过程比较慢,耐心等待)
cd /etc/yum.repos.d/ yum -y install mysql-server
-
启动MySQL服务
systemctl start mysqld.service #或 systemctl start mysqld
-
查找默认密码
grep "password" /var/log/mysqld.log
-
使用默认密码登录
mysql -uroot -p
-
更改密码时,如果想降低密码的复杂度优先执行此步骤。
#密码校验强度降低为低风险 set global validate_password_policy=LOW; #修改设置密码的长度 set global validate_password_length=6;
-
更改密码
ALTER USER 'root'@'localhost' IDENTIFIED BY '123456'; #退出MySQL exit;
到此步,MySQL已顺利安装完成,接下来配置远程访问MySQL
-
执行以下命令开启远程访问限制 (在MySQL中执行)
#192.168.0.1换成自己的IP地址,password为设置MySQL远程登录的密码 grant all privileges on *.* to 'root'@'192.168.0.1' identified by 'password' with grant option;
-
开启防火墙,但防火墙添加开放端口3306
#开启防火墙 systemctl start firewalld.service # 开放3306端口 firewall-cmd --zone=public --add-port=3306/tcp --permanent #配置立即生效 firewall-cmd --reload ####如有需要,关闭某个端口 #关闭3306端口 firewall-cmd --zone=public --remove-port=3306/tcp --permanent #查看防火墙状态 firewall-cmd --state
好的教程:
-
https://blog.csdn.net/weixin_42140801/article/details/107859925?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522162925229016780269871176%2522%252C%2522scm%2522%253A%252220140713.130102334..%2522%257D&request_id=162925229016780269871176&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2alltop_positive~default-1-107859925.first_rank_v2_pc_rank_v29&utm_term=centos7%E5%AE%89%E8%A3%85mysql&spm=1018.2226.3001.4187
-
https://blog.csdn.net/Bb15070047748/article/details/106245223?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522162925229016780269871176%2522%252C%2522scm%2522%253A%252220140713.130102334..%2522%257D&request_id=162925229016780269871176&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2alltop_positive~default-2-106245223.first_rank_v2_pc_rank_v29&utm_term=centos7%E5%AE%89%E8%A3%85mysql&spm=1018.2226.3001.4187