首先 如果安装过需要把mysql清理干净
//yum安装方式下载 1.查看已安装的mysql 命令:rpm -qa | grep -i mysql 2.卸载mysql 命令:yum remove mysql-community-server-5.6.36-2.el7.x86_64 查看mysql的其它依赖:rpm -qa | grep -i mysql //卸载依赖 yum remove mysql-libs yum remove mysql-server yum remove perl-DBD-MySQL yum remove mysql //查看还有无mysql watch mysql cd /usr/lib/mysql //总之一定要清楚干净
下面是安装
cd /usr/local/src # 下载MySQL的官方repo源 wget http://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm # 安装Yum Repository rpm -ivh mysql57-community-release-el7-11.noarch.rpm # 安装MySQL服务器 yum -y install mysql-server mysql-devel #使用该条命令!
安装完成后,使用mysqladmin --version 或者 mysql --version
查看数据库版本如下:
查看MySQL运行状态:service mysqld status 开启MySQL运行服务:service mysqld start 关闭MySQL与性服务:service mysqld stop
二、设置MySQL8数据库密码
1、启动MySQL
systemctl start mysqld
2、修改MySQL密码并允许远程连接
在(/etc/my.cnf)5.7是my.cnf 8.0是这个
/etc/my.cnf.d/mysql-server.cnf文件最后一行添加skip-grant-tables
,重启mysql(systemctl restart mysqld),跳过登入权限验证;
vim /etc/my.cnf.d/mysql-server.cnf
使用mysql -u root
登陆
mysql> use mysql; mysql> update user set host='%' where user='root'; mysql> update user set authentication_string="" where user="root"; mysql> flush privileges; mysql> ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY '密码必须加字符'; mysql> flush privileges; mysql> exit;
去除免密码登陆
修改mysql配置,注释步骤2的语句 skip-grant-tables
重启服务 service mysqld restart 然后就可以使用新密码登录了
防火墙放行3306端口
如果你的防火墙已经关闭,可忽略此操作。
# 永久开放3306端口 firewall-cmd --permanent --zone=public --add-port=3306/tcp # 重启防火墙 systemctl restart firewalld # 检测设定是否生效 iptables -L -n | grep 3306 1:查看防火状态 systemctl status firewalld service iptables status 2:暂时关闭防火墙 systemctl stop firewalld service iptables stop 3:永久关闭防火墙 systemctl disable firewalld chkconfig iptables off 4:重启防火墙 systemctl restart firewalld.service systemctl enable firewalld service iptables restart
MySQL的repo源
为了防止每次进行yum操作时其自动更新,移除MySQL的repo源
yum -y remove mysql57-community-release-el7-11.noarch
# 查看MySQL是否自启 systemctl is-enabled mysqld # 开启自启 systemctl enable mysqld # 关闭自启 systemctl disable mysqld
修改密码看这个https://zhuanlan.zhihu.com/p/141778941
参考:
https://www.jianshu.com/p/0cdf95b3ef27
https://www.jianshu.com/p/df8888f27292
https://zhuanlan.zhihu.com/p/141778941
https://blog.csdn.net/qq_41829904/article/details/92966943