首页 > 代码库 > Mysql root密码忘记怎么搞

Mysql root密码忘记怎么搞

首先不得不说本人有点二,这都能忘.....

方法一:

# /etc/init.d/mysqld stop

# mysqld_safe --user=mysql --skip-grant-tables --skip-networking &

# mysql -uroot mysql

mysql> update user set Password=Password(‘newpassword‘) where User=‘root‘;

mysql> flush privileges;

mysql> quit

# /etc/init.d/mysql restart

# mysql -uroot -p
enter password:


方法二:

修改MySQL的登录设置:
# vi /etc/my.cnf
在[mysqld]的段中加上一句:skip-grant-tables

如下:

    [mysqld]         
    datadir=/var/lib/mysql
    socket=/var/lib/mysql/mysql.sock
    user=mysql       
    skip-grant-tables

重启mysql

# /etc/init.d/mysqld restart
Stopping mysqld:                                           [  OK  ]
Starting mysqld:                                           [  OK  ]

无密码登录:

# mysql

mysql> use mysql;update user set Password=Password(‘root‘) where User=‘root‘; 
mysql> flush privileges;

退出,修改/etc/my.conf,删除skip-grant-tables,重启mysql。搞定


Mysql root密码忘记怎么搞