linux mysql 超级用户_Linux下MySQL忘记超级用户口令的解决办法

解决办法一

MySQL忘记超级用户口令的解决办法

如果MySQL正在运行,首先杀之: killall -TERM mysqld。

启动MySQL:

代码如下

bin/safe_mysqld --skip-grant-tables &

就可以不需要密码就进入MySQL了

然后就是

代码如下

>use mysql

>update user set password=password("new_pass") where user="root";

>flush privileges;

重新杀MySQL,用正常方法启动MySQL 。

解决方法二

最安全的状态是到服务器的Console上面操作,并且拔掉网线。

2.修改MySQL的登录设置:

# vi /etc/my.cnf

在[mysqld]的段中加上一句:skip-grant-tables

例如:

代码如下

[mysqld]

datadir=/var/lib/mysql

socket=/var/lib/mysql/mysql.sock

skip-grant-tables

保存并且退出vi。

3.重新启动mysqld

代码如下

# /etc/init.d/mysqld restart

Stopping MySQL: [ OK ]

Starting MySQL: [ OK ]

4.登录并修改MySQL的root密码

代码如下

# /usr/bin/mysql

Welcome to the MySQL monitor. Commands end with ; or g.

Your MySQL connection id is 3 to server version: 3.23.56

Type 'help;' or 'h' for help. Type 'c' to clear the buffer.

mysql> USE mysql ;

Reading table information for completion of table and column names

You can turn off this feature to get a quicker startup with -A

Database changed

mysql> UPDATE user SET Password = password ( 'new-password' ) WHERE User = 'root' ;

Query OK, 0 rows affected (0.00 sec)

Rows matched: 2 Changed: 0 Warnings: 0

mysql> flush privileges ;

Query OK, 0 rows affected (0.01 sec)

mysql> quit

Bye

5.将MySQL的登录设置修改回来

代码如下

# vi /etc/my.cnf

将刚才在[mysqld]的段中加上的skip-grant-tables删除

保存并且退出vi。

6.重新启动mysqld

代码如下

# /etc/init.d/mysqld restart

Stopping MySQL: [ OK ]

Starting MySQL: [ OK ]

恢复方法:

通过运行mysqld_safe 启动命令,跳过账号密码检查,这样不用账号、密码即可登陆数据库,从而可以重新设置mysql数据库的root超级账号、密码。

演示如下:

首先,用putty等ssh工具,登陆服务器,运行

01

代码如下

./etc/init.d/mysqld stop

service mysqld stop

把mysql停止,

接着,运行

/usr/bin/mysqld_safe --skip-grant-tables

启动mysql,这样运行后即可跳过权限检查。无需账号、密码即可登陆数据库,如下图:

 6576e11eccd1f1c350d2aaa379e2b5ca.pngselectable="true" outfunc="null" initialized="true" status="2" zoomfile="data/attachment/forum/201204/18/12052110j9eekungzrxa1a.jpg" file="data/attachment/forum/201204/18/12052110j9eekungzrxa1a.jpg" inpost="1" />

最后,进入mysql库的user表,修改数据库root超级账号的密码,如下图;

 7245d6c07eb1f4edd23947a31f00f176.png

02a9e25e16e91abdb5f38b820c11c29d.png

请注意,在编辑root的页面中,password这一行的函数这项里要选择加密方式。

修改后,重起服务器

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值