Home >Database >Mysql Tutorial >linux清除MYSQL密码_MySQL

linux清除MYSQL密码_MySQL

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-06-01 13:45:421064browse

bitsCN.com

 

1.先以root用户登录系统;

2.关闭MYSQL服务或进程:service mysqld stop / killall mysqld;

3.特权启动MYSQL: /usr/local/mysql/bin/mysqld_safe --skip-grant-tables & or mysqld_safe --skip-grant-tables --skip-networking & (注:参数--skip-grant-tables为跳过授权表;--skip-networking为不监听TCP/IP连接);

4.然后可以不需要密码进入MySQL:mysql -u root -p(要求输入密码时直接回车即可);

mysql>use mysql;

mysql>update user set password=password('new pw') where user='root' (注:'new pw' 就是你的新密码,其它照抄;

另一种写法:update mysql.user set password=password('new pw') where user='root';

5.更新下:

mysql>flush privileges;

mysql>quit;

6.结束刚启动过的MYSQL进程:killall mysqld or killall -9 mysqld.

7.正常启动MYSQL: service mysql start

8.用'new pw'登入:mysql -u root -p.

OK......

>>同时也可以这样做:

首先,修改MySQL的登录设置:

# vi /etc/my.cnf

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

例如:

[mysqld]

datadir=/var/lib/mysql

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

skip-grant-tables

保存并且退出vi。

然后,重新启动mysqld,进去修改密码,同上述方法;

最后,将MySQL的登录设置修改回来:

# vi /etc/my.cnf

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

保存并且退出vi。

再次登入MYSQL,一样OK......

本文出自 “colive” 博客

bitsCN.com
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn