修改MySQL的登录密码设置

(在root用户下进行)

1.  # gedit  /etc/my.cnf
在[mysqld]的段中加如下语句
[mysqld]
skip-name-resolve
skip-grant-tables
2.  重新启动mysql
# /etc/init.d/mysql restart
3.  登录并修改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.
4.  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’ ; //被这句搞死,不能直接password=‘*****’,而要使用password=password(‘*****’),*****是明文,存储时候是密文,其实很简单。。。
Query OK, 0 rows affected (0.00 sec)
Rows matched: 2 Changed: 0 Warnings: 0
4.  mysql> flush privileges ; / /刷新MySQL的系统权限相关表
Query OK, 0 rows affected (0.01 sec)
5.  mysql> quit
Bye
6.  将MySQL的登录设置修改回来
# gedit  /etc/my.cnf
将刚才在[mysqld]的段中加上的语句删除
7.   重新启动mysql
# /etc/init.d/mysql restart
8.   顺利登陆啦!!

One thought on “修改MySQL的登录密码设置”

  1. 比起使用sql操作mysql的用户表,使用mysqladmin要简单一些
    mysqladmin -u root -p password ‘******’

Leave a Reply

Your email address will not be published. Required fields are marked *