mysql忘记root密码

来源:互联网 发布:matlab 2017b mac 编辑:程序博客网 时间:2024/05/01 23:31

[root@cookie ~]# find / -name 'my.cnf'   //查找my.cnf文件位置
/etc/my.cnf
[root@cookie ~]# vim /etc/my.cnf         //编辑my.cnf文件
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
user=mysql
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
old_passwords = 1
default-character-set = utf8
skip-grant-tables             //添加skip-grant-tables
[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid


[root@cookie ~]# /etc/init.d/mysqld restart    //mysql重启
Stopping mysqld:                                           [  OK  ]
Starting mysqld:                                           [  OK  ]


[root@cookie ~]# mysql -p      //直接登录,无需密码
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.1.73 Source distribution
Copyright (c) 2000, 2013, 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> 
mysql> 
mysql> update mysql.user  set password=password('v1GLrOSgdmus5yTLM9guI8CecqG2') where user='root';
Query OK, 3 rows affected (0.00 sec)
Rows matched: 3  Changed: 3  Warnings: 0
mysql> 
mysql> 
mysql> exit
Bye
[root@cookie ~]#
[root@cookie ~]# vim /etc/my.cnf 
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
user=mysql
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
old_passwords = 1
default-character-set = utf8
#skip-grant-tables              //注释掉skip-grant-tables
[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid


[root@cookie ~]# /etc/init.d/mysqld restart
Stopping mysqld:                                           [  OK  ]
Starting mysqld:                                           [  OK  ]


[root@cookie ~]# mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.1.73 Source distribution
Copyright (c) 2000, 2013, 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> 
mysql> 


0 0
原创粉丝点击