签到成功

知道了

CNDBA社区CNDBA社区

Maridb忘记用户密码处理方法

2017-12-06 11:41 2881 0 原创 Maridb
作者: Expect-乐

关于Maridb介绍:http://www.cndba.cn/Expect-le/article/2370

问题

[root@MariDB-Master ~]# mysql -uroot -p123456

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

无法登陆mysql

处理方法

2.1   停止mysql

[root@MariDB-Master ~]# /etc/init.d/mysql stop

Shutting down MySQL..                                      [  OK  ]

或者service mysql stop

2.2   忽略授权,重新打开mysql

[root@MariDB-Master ~]# mysqld_safe --skip-grant-tables --user=mysql &

[1] 2440

[root@MariDB-Master ~]# 171206 11:21:20 mysqld_safe Logging to '/usr/local/mysql/data/MariDB-Master.err'.

http://www.cndba.cn/Expect-le/article/2371
http://www.cndba.cn/Expect-le/article/2371

171206 11:21:20 mysqld_safe Starting mysqld daemon with databases from /usr/local/mysql/data

 

[root@MariDB-Master ~]#

[root@MariDB-Master ~]#

#查看一下是否启动成功

[root@MariDB-Master ~]# ps -ef|grep mysql

root      2440  2313  0 11:21 pts/0    00:00:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --skip-grant-tables --user=mysql

mysql     2563  2440  1 11:21 pts/0    00:00:00 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --skip-grant-tables --log-error=/usr/local/mysql/data/MariDB-Master.err --pid-file=MariDB-Master.pid --socket=/tmp/mysql.sock --port=3306

root      2599  2313  0 11:21 pts/0    00:00:00 grep mysql

2.3   修改密码

MariaDB [mysql]> set password=password("123");

ERROR 1290 (HY000): The MariaDB server is running with the --skip-grant-tables option so it cannot execute this statement

这里注意不能使用这种方法修改密码。

正确修改方法:

MariaDB [mysql]> update user set password=password("cndba") where user='root' and host='localhost';

Query OK, 1 row affected (0.05 sec)

Rows matched: 1  Changed: 1  Warnings: 0

 

http://www.cndba.cn/Expect-le/article/2371
http://www.cndba.cn/Expect-le/article/2371

#刷新权限

MariaDB [mysql]> flush privileges;

Query OK, 0 rows affected (0.01 sec)

 

MariaDB [mysql]> quit;

Bye

2.4   关闭当前已safe打开的mysql

注意:密码是刚刚修改的密码。

[root@MariDB-Master ~]# mysqladmin -uroot -pcndba shutdownhttp://www.cndba.cn/Expect-le/article/2371

[1]  +  Done                    mysqld_safe --skip-grant-tables --user=mysql

 

http://www.cndba.cn/Expect-le/article/2371

2.5   重新正常打开mysql

[root@MariDB-Master ~]# /etc/init.d/mysql start service mysql start

Starting MySQL.171206 11:26:55 mysqld_safe Logging to '/usr/local/mysql/data/MariDB-Master.err'.

171206 11:26:55 mysqld_safe Starting mysqld daemon with databases from /usr/local/mysql/data

                                                           [  OK  ]

2.6   再次登录

#首先尝试错误密码

[root@MariDB-Master ~]# mysql -uroot -p123

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

 

http://www.cndba.cn/Expect-le/article/2371

#正确密码,登录成功

[root@MariDB-Master ~]# mysql -uroot -pcndba

http://www.cndba.cn/Expect-le/article/2371

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

Your MariaDB connection id is 11

Server version: 10.2.10-MariaDB-log MariaDB Server

 

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

 http://www.cndba.cn/Expect-le/article/2371

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

http://www.cndba.cn/Expect-le/article/2371

 

MariaDB [(none)]>

至此密码修改完成。

版权声明:本文为博主原创文章,未经博主允许不得转载。

maridb 密码

用户评论
* 以下用户言论只代表其个人观点,不代表CNDBA社区的观点或立场
Expect-乐

Expect-乐

关注

Without the continuous bitter cold, there can be no fragrant plum blossom

  • 336
    原创
  • 6
    翻译
  • 100
    转载
  • 41
    评论
  • 访问:1567053次
  • 积分:1957
  • 等级:核心会员
  • 排名:第4名
精华文章
    最新问题
    查看更多+
    热门文章
      热门用户
      推荐用户
        Copyright © 2016 All Rights Reserved. Powered by CNDBA · 皖ICP备2022006297号-1·

        QQ交流群

        注册联系QQ