centos7环境下mysql8.0.13安装、root密码重置及用户远程连接授权

环境:centos7

           mysql8.0.13


一、下载mysql的源包

在mysql官网下载yum源rpm安装包。下载链接:https://dev.mysql.com/downloads/file/?id=477146

二、 使用xftp工具上传至linux中

三、安装mysql的下载源

执行命令  yum localinstall mysql80-community-release-el7-1.noarch.rpm 进行安装 

四、 在线安装mysql

执行命令:yum install mysql-community-server

如图表示安装成功:

五、启动mysql

启动执行命令:service mysqld start

注:停止命令:service mysqld stop

      查看状态命令:service mysqld status

六、给root用户设置密码

1、 在/var/log/mysqld.log下查看临时密码

2.、登录到数据库:

      mysql -u root -p回车

      输入临时密码(输入时可能不会显示出来,输入完直接回车就行

如图:

 3、 修改密码

注意:mysql5.7.6以后废弃了user表中的password字段和 password() 方法,用authentication_string代替password。所以凡是利用password和password()修改密码的都不正确。

用临时密码登录到服务端后,必须马上修改密码,不然会报如下错误:

1

2

mysql> select user();

ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.

如果只是修改为一个简单的密码,会报以下错误:

1

2

mysql> ALTER USER USER() IDENTIFIED BY '12345678';

ERROR 1819 (HY000): Your password does not satisfy the current policy requirements

注意:mysql8.0以上密码策略限制必须要大小字母写加数字特殊符号

故设置密码如下:

执行语句:

mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY '新密码(必须包含:数字大小写字母特殊字符)'; 

如图:

 4、 测试密码是否设置成功

输入quit退出mysql,重新执行2步骤,输入新密码登录。

七、远程连接授权

官方远程连接授权说明:https://dev.mysql.com/doc/refman/8.0/en/grant.html

注意: MySQL 安装完成后只支持 localhost 访问,我们必须设置一下才可以远程访问。

输入以下命令发现均报错:

mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'Root123!' WITH GRANT OPTION;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'IDENTIFIED BY 'Root123!' WITH GRANT OPTION' at line 1
mysql> GRANT ALL ON *.* TO 'root'@'%';
ERROR 1410 (42000): You are not allowed to create a user with GRANT

mysql>  grant all privileges on *.* to 'root'@'%' with grant option;
ERROR 1410 (42000): You are not allowed to create a user with GRANT
 

可执行如下命令修改root远程连接权限:

mysql> update user set host = "%" where user='root';

查看用户权限:

mysql> select host, user, authentication_string, plugin from user;

root的host为%,表示可以进行远程连接。

温馨提示:可参考博客https://m.imooc.com/article/91572?block_id=tuijian_wz查看遇到的其他问题。

八、创建用户和授权

用户创建:

mysql> create user 'linhaijing'@'%' identified by '520Lhj520Lhj*';
授权:

mysql> grant all privileges on *.* to 'linhaijing'@'%' with grant option;

查看用户权限:

mysql> select host, user, authentication_string, plugin from user;

即新创建的用户也可以实现远程连接。

九、本地Navicat远程连接 linux上的mysql

如果报未知连接错误:查看linux防火墙是否关闭

如果报错误:2059 Authentication plugin 'caching_sha2_password'cannot be loaded

可参考https://blog.csdn.net/jinhaijing/article/details/83421189解决

连接成功如下:

猜你喜欢

转载自blog.csdn.net/jinhaijing/article/details/83349104
今日推荐