首页
学习
活动
专区
圈层
工具
发布
社区首页 >专栏 >Mysql5.7 用户授权和密码修改

Mysql5.7 用户授权和密码修改

作者头像
Linux运维技术之路
发布于 2022-06-07 09:00:44
发布于 2022-06-07 09:00:44
1.7K0
举报

一、修改密码方法:

方法1:

代码语言:javascript
复制
set global validate_password_policy=LOW;
alter user 'root'@'localhost' identified by 'test';

方法2:

代码语言:javascript
复制
set global validate_password_policy=LOW;
set password for 'root'@'localhost'=password('test');

方法3:

代码语言:javascript
复制
set global validate_password_policy=LOW;
update mysql.user set authentication_string=password('test') where user='root' and Host = 'localhost';

刷新权限

代码语言:javascript
复制
flush privileges;

查询用户,主机名,加密字符串

代码语言:javascript
复制
select user,host,authentication_string from mysql.user;

二、用户授权

代码语言:javascript
复制
create database db_test;
create user 'demo'@'%' identified by 'test';
grant select,insert,delete,update on db_test.* to 'demo'@'%' ;
select user,host,authentication_string from mysql.user;
flush prvileges;

三、数据库开启主从后,从库为了防止别人误修改文件,开启只读模式,导致密码不能正确修改

代码语言:javascript
复制
mysql> update mysql.user set authentication_string=password('qaws213gt') where user='itdemo' and Host = '%';
ERROR 1290 (HY000): The MySQL server is running with the --super-read-only option so it cannot execute this statement
mysql> set global read_only=0;
Query OK, 0 rows affected (0.00 sec)

查询是否开启只读模式 read_only 为1 ,开启

代码语言:javascript
复制
mysql> select @@read_only;
+-------------+
| @@read_only |
+-------------+
|           1 |
+-------------+
1 row in set (0.00 sec)

解决方法:关闭只读模式

代码语言:javascript
复制
mysql> set global read_only=0;
Query OK, 0 rows affected (0.00 sec)
mysql> update mysql.user set authentication_string=password('demo') where user='itdemo' and Host = '%';
Query OK, 1 row affected, 1 warning (0.04 sec)
Rows matched: 1  Changed: 1  Warnings: 1
mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)
本文参与 腾讯云自媒体同步曝光计划,分享自微信公众号。
原始发表:2020-03-13,如有侵权请联系 cloudcommunity@tencent.com 删除
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档