centos7通过yum安装mysql5.7以上版本

星辰之舞酱 2024-09-12 ⋅ 9 阅读

1.检查并卸载mariadb

yum remove *mariadb*

遇到要求输入直接y/n 直接输入y回车

2.下载并安装mysql

mysql源地址:https://repo.mysql.com/
找到自己需要的版本,把版本名和 mysql源地址拼接起来,列如:我下载的是mysql80-community-release-el7.rpm,所以拼接起来就是filei下载地址 https://repo.mysql.com/mysql80-community-release-el7.rpm
image

wget https://repo.mysql.com/mysql80-community-release-el7.rpm
yum -y install mysql80-community-release-el7.rpm

3.安装并启动mysql服务器

yum -y install mysql-community-server
systemctl start  mysqld.service
systemctl enable  mysqld.service
systemctl daemon-reload

查看运行状态

systemctl status mysqld.service

4.修改mysql默认密码

提示:在mysql5.7以后,密码不能设置过于简单的,否则会出现ERROR:Your password does not satisfy the current policy requirements,解决方法就是调整MySQL密码验证规则,修改 policy 和 length 的值(在 4.3位置)。

4.1首先查看mysql登录密码

因为第一次安装使用,安装mysql时会自动生成一个临时密码存在mysqld.log文件中,我使用的时yum安装,所以直接查看/var/log/msyqld.log. 如果你是使用源码包安装 就去解压包里面找mysqld.log文件.这里是以我安装为例

vim /var/log/msyqld.log

image

4.2.登录

xxxx的地方填写 mysql密码,但这里输入密码时明文的(不推荐)

mysql -u root -p xxxxx   

image

或者 不写密码,然后回车后,会让你输入密码,此时输入密码是隐藏 (推荐)

mysql -u root -p   

image
看到下图说明登陆成功了
image

4.3.修改密码

如果你想要把密码修改成简单的,调整MySQL密码验证规则,修改 policy 和 length 的值。如果在修改 policy 和 length 的值,可能会报错ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
如下图image
那就先输入以下命令: "你的密码" 一定要先设置复杂一些,后面在修改为简单的

ALTER USER 'root'@'localhost' IDENTIFIED BY '你的密码'

4.3.1 MySQL 5.7 进行如下设置:

set global validate_password_policy=0;
set global validate_password_length=1;

4.3.2MySQL 8.0 调整密码验证规则:

set global validate_password.policy=0;
set global validate_password.length=1;

image

4.3.3重设密码(这时可以设置简单密码)

ALTER USER 'root'@'localhost' IDENTIFIED BY '你的密码';

5.开启远程访问

查看mysql远程访问权限配置

--mysql5.7使用这个
select host, user, authentication_string, plugin from user;

--mysql8以上使用下面这个
select host, user, authentication_string, plugin from mysql.user;

image

--创建允许所有主机使用root访问的记录,并指定密码
CREATE USER 'root'@'%' IDENTIFIED BY '密码';

--赋予这个配置特权
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%';

--刷新权限
FLUSH PRIVILEGES;

image
再次查看mysql远程访问权限配置,看是否添加

--mysql5.7使用这个
select host, user, authentication_string, plugin from user;

--mysql8以上使用下面这个
select host, user, authentication_string, plugin from mysql.user;

image

6.如果是使用的阿里云或者腾讯云,开启3306端口

image


全部评论: 0

    我有话说: