您好,欢迎访问一九零五行业门户网

MySQL修改密码和忘记ROOT密码

前言:本文档介绍mysql修改用户密码的方法和忘记root密码后的处理方法。 一、三种修改密码的方式 1、修改当前用户的登录密码 脚本
前言:本文档介绍mysql修改用户密码的方法和忘记root密码后的处理方法。
一、三种修改密码的方式
1、修改当前用户的登录密码
脚本:set password=password('netpassword');
例: 
mysql> set password=password('root');
query ok, 0 rows affected (0.00 sec) 
2、使用set修改其他用户的密码,,通过root修改其他账号的密码
脚本:set password for
'user' @'host'=password('newpassword') 
例: 
mysql> select host,user from mysql.user;
+----------------+--------+
| host | user |
+----------------+--------+
| | test |
| % | john1 |
| % | mytest |
| 127.0.0.1 | root |
| 192.168.189.71 | john |
| 192.168.189.71 | john1 |
| ::1 | john |
| ::1 | root |
| localhost | john |
| localhost | root |
| mysql | root |
+----------------+--------+
11 rows in set (0.00 sec) 
mysql> set password for
-> 'john1' @'%'=password('john');
query ok, 0 rows affected (0.00 sec) 
3、使用update语句修改其他用户的密码,需要有修改mysql权限的用户,一般用root用户
脚本:
update mysql.user set
password=password('newpassword')
where
user='username'
and
host='host';
例: 
mysql> update mysql.user set
-> password=password('root')
-> where
-> user='root' and host='127.0.0.1';
query ok, 0 rows affected (0.02 sec)
rows matched: 0 changed: 0 warnings: 0
二、忘记root密码的处理方法
1、关闭数据库
脚本:[root@mysql etc]# service mysql stop 
2、使用脚本: mysqld_safe --skip-grant-tables 启动数据库 
使用/usr/bin/mysqld_safe --skip-grant-tables&启动数据库 
3、使用空密码进入数据库(mysql命令后直接回车) 
[root@mysql ~]# mysql
welcome to the mysql monitor. commands end with ; or \g.
your mysql connection id is 3
server version: 5.6.20-enterprise-commercial-advanced mysql enterprise server - advanced edition (commercial)
copyright (c) 2000, 2014, oracle and/or its affiliates. all rights reserved.
oracle is a registered trademark of oracle corporation and/or its
affiliates. other names may be trademarks of their respective
owners.
type 'help;' or '\h' for help. type '\c' to clear the current input statement.
mysql> 
4、使用update语句修改root密码 
mysql> update mysql.user set
-> password=password('root')
-> where
-> user='root' and host='localhost'; 
5、关闭数据库并重新以正常方式启动数据库 
[root@mysql ~]# service mysql restart;
shutting down mysql.. success!
starting mysql.. success!
[root@mysql ~]# mysql
error 1045 (28000): access denied for user 'root'@'localhost' (using password: no)
[root@mysql ~]# mysql -p
enter password:
welcome to the mysql monitor. commands end with ; or \g.
your mysql connection id is 2
server version: 5.6.20-enterprise-commercial-advanced mysql enterprise server - advanced edition (commercial)
copyright (c) 2000, 2014, oracle and/or its affiliates. all rights reserved. 
oracle is a registered trademark of oracle corporation and/or its
affiliates. other names may be trademarks of their respective
owners.
type 'help;' or '\h' for help. type '\c' to clear the current input statement.
mysql> 
显示可以成功登录,整个过程很简单。大功告成!!!
--------------------------------------分割线 --------------------------------------
ubuntu 14.04下安装mysql
《mysql权威指南(原书第2版)》清晰中文扫描版 pdf
ubuntu 14.04 lts 安装 lnmp nginx\php5 (php-fpm)\mysql
ubuntu 14.04下搭建mysql主从服务器
ubuntu 12.04 lts 构建高可用分布式 mysql 集群
ubuntu 12.04下源代码安装mysql5.6以及python-mysqldb
mysql-5.5.38通用二进制安装
--------------------------------------分割线 --------------------------------------
本文永久更新链接地址:
其它类似信息

推荐信息