mysql什么时候需要flush privileges

mysql什么时候需要flush privileges,第1张

必须使用flush privileges的两种情况

1、改密码

2、授权超用户

flush privileges 命令本质上的作用是将当前user和privilige表中的用户信息/权限设置从mysql库(MySQL数据库的内置库)中提取到内存里。

MySQL用户数据和权限有修改后,希望在"不重启MySQL服务"的情况下直接生效,那么就需要执行这个命令。

通常是在修改ROOT帐号的设置后,怕重启后无法再登录进来,那么直接flush之后就可以看权限设置是否生效。而不必冒太大风险。

扩展资料:

mysql 修改密码后,注意flush privileges。

mysql 新设置用户或更改密码后需用flush privileges刷新MySQL的系统权限相关表,否则会出现拒绝访问,还有一种方法,就是重新启动mysql服务器,来使新设置生效。

具体例子:

1、用户root用户进入mysql再打开mysql数据库(use mysql)后。

create user stu identified by ‘stu’    ##创建一用户stu并添加密码为stu。

exit    ##退出测试。

2、用新用户重新进入mysql。

mysql -ustu -pstu   ##进入成功。

3、重新使用root用户进入mysql并打开mysql数据库。

update user set password=password (‘123456’) where user='stu'   ##更改stu用户密码为123456。

exit     ##再次退出测试。

4、直接以用户stu身份进入,用新密码进入看是否成功。

mysql -ustu -p123456  ##报错,密码不正确。

5、重新以root 用户登陆并进入mysql数据库,重新修改用户密码。

update user set password=password (‘123456’) where user='123456'   ##更改stu用户密码为123456

flush privileges   ##刷新MySQL的系统权限相关表。

exit

6.再次退出,并以stu用户123456密码进入,测试成功。

今日分享主题:mysql root账号如何重置密码

前两天发现我的 mysql 数据库突然无法登录,但是上周还使用得是正常的,经过一番查找还是没有找到问题的原因。

DBA 给我的解释:我怀疑主机重启后,某些文件(user.*)就丢了,不知道啥原因。我记得之前你也是重启后遇到过相同问题。

既然这样,只好重置 root 账号密码了。具体 *** 作步骤如下

Step1:停止 mysql 服务

命令:systemctl stop mysqld #停掉MySQL

命令:systemctl status mysqld #查看状态

Step2:修改/etc/my.cnf配置,添加 skip_grant_tables=1 启动设置,注意要在[mysqld]行所在的下面添加。

Step3:重启 mysql 并查看状态

systemctl start mysqld

systemctl status mysqld

Step4:使用 mysql 命令连接到 mysql 服务器,重新设置root密码

use mysql #进入mysql数据库 select * from user#查询user表 查看是否有root账号,如果没有就需要 *** 作如下insert into 语句:

如果 user 表里面有 root 账号,则直接可以重置密码。

命令如下:update user set authentication_string=password('test123') where user='root'

FLUSH PRIVILEGES#刷新授权列表

再输入 exit 退出mysql

Step5:将步骤2中/etc/my.cnf 文件中添加的 skip_grant_tables=1 启动设置去掉,再执行一个systemctl restart mysql 命令重启 mysql 服务。

Step6:使用重置后的密码再登录时问题解决。

安装完mysql-server

会提示可以运行mysql_secure_installation。运行mysql_secure_installation会执行几个设置:

a)为root用户设置密码

b)删除匿名账号

c)取消root用户远程登录

d)删除test库和对test库的访问权限

e)刷新授权表使修改生效

通过这几项的设置能够提高mysql库的安全。建议生产环境中mysql安装这完成后一定要运行一次mysql_secure_installation,详细步骤请参看下面的命令:

复制代码

代码如下:

[root@server1 ~]#

mysql_secure_installation

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS

RECOMMENDED FOR ALL MySQL

SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP

CAREFULLY!

In order to log into MySQL to secure it, we'll need the

current

password for the root user. If you've just installed MySQL,

and

you haven't set the root password yet, the password will be blank,

so

you should just press enter here.

Enter current password for root (enter for

none):<–初次运行直接回车

OK, successfully used

password, moving on…

Setting the root password ensures that nobody can log

into the MySQL

root user without the proper authorisation.

Set root

password? [Y/n] <–

是否设置root用户密码,输入y并回车或直接回车

New password: <– 设置root用户的密码

Re-enter new password: <– 再输入一次你设置的密码

Password updated

successfully!

Reloading privilege tables..

… Success!

By default, a

MySQL installation has an anonymous user, allowing anyone

to log into MySQL

without having to have a user account created for

them. This is intended only

for testing, and to make the installation

go a bit smoother. You should

remove them before moving into a

production environment.

Remove anonymous

users? [Y/n] <–

是否删除匿名用户,生产环境建议删除,所以直接回车

… Success!

Normally, root should only be

allowed to connect from 'localhost'. This

ensures that someone cannot guess

at the root password from the network.

Disallow root login remotely?

[Y/n]

<–是否禁止root远程登录,根据自己的需求选择Y/n并回车,建议禁止

… Success!

By default, MySQL

comes with a database named 'test' that anyone can

access. This is also

intended only for testing, and should be removed

before moving into a

production environment.

Remove test database and access to it? [Y/n] <– 是否删除test数据库,直接回车

- Dropping test

database…

… Success!


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zaji/8545414.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-17
下一篇 2023-04-17

发表评论

登录后才能评论

评论列表(0条)

保存