Home > Database > Mysql Tutorial > linux下mysql修改root密码_MySQL

linux下mysql修改root密码_MySQL

WBOY
Release: 2016-06-01 13:01:18
Original
1007 people have browsed it

方法一:用set password命令

首先,登陆mysql

mysql -u root -p
Copy after login

然后执行set password命令

set password for root@localhost = password('654321');
Copy after login

上面例子,将root密码更改为654321


方法二:使用mysqladmin

格式为:mysqladmin -u用户名 -p旧密码 password 新密码

mysqladmin -uroot -p123456 password "654321"
Copy after login

上面例子,将root密码由123456更改为654321


方法三:更改mysql的user表

首先,登陆mysql

mysql -uroot -p
Copy after login

然后操作mysql库的user表,进行update
mysql> use mysql;
mysql> update user set password=password('654321') where user='root' and host='localhost';
mysql> flush privileges;
Copy after login

方法四:忘记密码的情况下

首先停止mysql服务

service mysqld stop
Copy after login

以跳过授权的方式启动mysql

mysqld_safe --skip-grant-tables &
Copy after login

以root用户登录mysql

mysql -u root
Copy after login

操作mysql库的user表,进行update

mysql> use mysql;
mysql> update user set password=password('654321') where user='root' and host='localhost';
mysql> flush privileges;
mysql> quit
Copy after login

重启mysql服务

service mysqld restart
Copy after login

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template