博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
mysql修改user_mysql修改用户密码
阅读量:4319 次
发布时间:2019-06-06

本文共 3336 字,大约阅读时间需要 11 分钟。

修改自己的密码(root用户,其它用户应该也差不多)

方法一:

[root@localhost /]# mysqladmin -u root -p password "root" #修改密码为root

Enter password: #输入旧密码

[root@localhost /]# mysql -uroot -p #尝试使用旧密码登录

Enter password:

ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)

[root@localhost /]# mysql -uroot -p #输入新密码root登录

Enter password:

Welcome to the MariaDB monitor. Commands end with ; or \g.

Your MariaDB connection id is 19

Server version: 5.5.52-MariaDB MariaDB Server

Copyright (c) 2000, 2016, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]>

方法二:

在mysql.user中使用update更新密码

方法三:

或者进入mysql后,使用set修改密码

[root@localhost /]# mysql -uroot -p #使用旧密码root登录

Enter password:

Welcome to the MariaDB monitor. Commands end with ; or \g.

Your MariaDB connection id is 19

Server version: 5.5.52-MariaDB MariaDB Server

Copyright (c) 2000, 2016, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> set password=password("123456"); #修改密码为123456,我一直很好奇为什么密码必须用password扩起来,后来知道了,新密码必须用password来加密

Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> quit

Bye

[root@localhost /]# mysql -uroot -p #使用新密码123456登录

Enter password:

Welcome to the MariaDB monitor. Commands end with ; or \g.

Your MariaDB connection id is 20

Server version: 5.5.52-MariaDB MariaDB Server

Copyright (c) 2000, 2016, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]>

root用户修改指定用户密码

方法一

MariaDB [(none)]> set password for 'bp'@'localhost'=password("123456");

Query OK, 0 rows affected (0.01 sec)

方法二:

MariaDB [(none)]> update mysql.user set password=password("123") where user='bp' and host='localhost'; #使用update修改密码,修改成功后,我打开另一个终端使用该用户登录数据库,发现无法使用新密码登录,但使用旧密码可以登录

Query OK, 1 row affected (0.00 sec)

Rows matched: 1 Changed: 1 Warnings: 0

MariaDB [(none)]> select user,host from mysql.user; #因为报错信息里面包含localhost,于是查看用户表信息有没有错,遗憾的是没有

+---------+-----------------------+

| user | host |

+---------+-----------------------+

| aa | % |

| aaa | % |

| root | 127.0.0.1 |

| root | ::1 |

| | localhost |

| aa | localhost |

| bb | localhost |

| bp | localhost |

| ggo | localhost |

| my | localhost |

| mytest | localhost |

| newuser | localhost |

| nome | localhost |

| root | localhost |

| | localhost.localdomain |

| root | localhost.localdomain |

+---------+-----------------------+

16 rows in set (0.00 sec)

MariaDB [(none)]> flush privileges; #后来想起来,是不是还要刷新权限。刷新之后,使用新密码可以登录

Query OK, 0 rows affected (0.00 sec)

方法三:grant修改密码

MariaDB [mytest]> grant select on mytest.test to 'bp'@'localhost' identified by 'linux';

Query OK, 0 rows affected (0.05 sec) #这个不需要刷新权限。。

mysql5.7修改密码

cat /var/log/mysqld.log|grep 'temporary password'

alter user 'root'@'localhost' identified by 'root';

忘记密码(需要重启服务器)

在/etc/my.cnf的mysqld里面增加skip-grant-tables (5.7以前的应该是skip-grant)

重启mysqld

mysql> update mysql.user set authentication_string=password(',,,abc123...') where user='root';  (旧版的应该是update mysql.user set password=password(',,,abc123...') where user='root';)

Query OK, 1 row affected, 1 warning (0.00 sec)

Rows matched: 1 Changed: 1 Warnings: 1

mysql> flush privileges;

Query OK, 0 rows affected (0.00 sec)

mysql> quit

重启服务器

转载地址:http://xgrzs.baihongyu.com/

你可能感兴趣的文章
Swagger在Laravel项目中的使用
查看>>
Laravel 的生命周期
查看>>
Nginx
查看>>
Navicat远程连接云主机数据库
查看>>
Nginx配置文件nginx.conf中文详解(总结)
查看>>
jxl写入excel实现数据导出功能
查看>>
linux文件目录类命令|--cp指令
查看>>
.net MVC 404错误解决方法
查看>>
linux系统目录结构
查看>>
git
查看>>
btn按钮之间事件相互调用
查看>>
Entity Framework 4.3.1 级联删除
查看>>
codevs 1163:访问艺术馆
查看>>
冲刺Noip2017模拟赛3 解题报告——五十岚芒果酱
查看>>
并查集
查看>>
sessionStorage
查看>>
代码示例_进程
查看>>
Java中关键词之this,super的使用
查看>>
学习进度
查看>>
“此人不存在”
查看>>