mysql8 配置密码和用户创建以及授权

一、mysql8 配置密码问题ERROR1819

但是新版 mysql 加入密码安全度检测机制,导致报错
解决方法如下
1.查看当前安全变量值

show VARIABLES LIKE 'validate_password%';

set global validate_password.policy=0;

set global validate_password.length=1;

最短还是为4位。

 

alter user 'root'@'localhost' identified by '123456';
flush privileges;

 

二、创建用户并授权或者取消授权

创建用户

use mysql;

create user 'root'@'%' identified by 'root__';
-- 查看新创建的用户
select * from user where user = 'username';

-- 查看权限
show grants for 'username'@'localhost';

 

分配权限

grant all privileges on database.table to 'user'@'%'; // 分配权限到表
grant all privileges on database.* to 'user'@'%'; // 分配权限到数据库
grant all privileges on *.* to 'user'@'%'; // 分配权限到所有数据库

超级用户 

-- grant:授权
-- all privileges:所有的权限
-- on *.*:在哪个数据库的那个表
-- to username@localhost:对哪个用户的哪个主机
-- with grant option:是不是将username用户自己本身的权限赋给其他账户
grant all privileges on *.* to 'username'@'localhost' with grant option;
-- 立即生效
flush privileges;

普通用户

-- usage:无权限,当你想创建一个没有权限的用户时候,指定usage
-- show:查看的权限,赋权限报错了,我也不知道咋回事
-- view:视图的权限(mysql8.0+赋权限出错)ERROR 3619 (HY000): Illegal privilege level specified for VIEW,如下图所示。
-- create temporary tables:创建临时表的权限
-- excute:执行的权限
grant usage,select,insert,update,delete,create temporary tables,execute on *.* to username@localhost;

 

三、SQLyog连接MySQL8.0报2058错误的完美解决方法

 

ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY 'root__';

 

引言

用SQLyog连接MySQL8.0(社区版:mysql-installer-community-8.0.15.0.msi),出现错误2058(Plugin caching_sha2_password could not be loaded:xxxx),通过查询资料了解了该错误的原因并在本文中提出了该问题的方案。

原因

该错误提示如下图所示:

具体原因:新的MySQL 8.0安装,在初始化数据目录时,将 ‘root'@'localhost'创建帐户,并且该帐户caching_sha2_password默认使用,密码的加密方法发生了改变,因此SQLyog不能正常解析,才报出如上错误。

解决方案

以管理员运行【开始】-【所有程序】-【MySQL】-【MySQL Server 8.0】-【MySQL 8.0 Command Line Client - Unicode】,如下图所示:

键入root账号的密码如下所示.

按照以下sql格式输入命令,其中password是指root账号的密码。

1
ALTER USER 'root' @ 'localhost' IDENTIFIED WITH mysql_native_password BY 'password' ;

执行该命令,结果为Query OK说明修改成功,如下图所示。

用SQLyog重新连接MySQL,可以成功连接。此时查看mysql数据库中的user表,发现root账号的插件名称发生了变化,如下所示。

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章