mysqlWhat should I do if I forget my password? This article mainly introduces in detail the solution for MySQL forgotten password, which has certain reference value. Interested friends can refer to
The solution for MySQL forgotten password:
[root@localhost ~]# mysql -uroot -p ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)
If this occurs, it is usually because MySQL has not started up
[root@localhost ~]# mysql -uroot -p ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
When this occurs, it is usually because the password is entered incorrectly
Solution Method:
1. Stop MySQL
[root@localhost ~]# service mysqld stop Stopping mysqld: [ OK ]
2. Modify the configuration file, in the last line Add the following content
skip-grant-tables //跳过授权直接进入数据库
3. Restart MySQL
[root@localhost ~]# service mysqld start [root@localhost ~]# mysql -uroot -p mysql>
4. Restart MySQL Set password
mysql> use mysql //密码存放在MySQL中,需要进入 mysql> desc user; //查看user表中的字段 密码一般存在password表中 +------------------------+-----------------------------------+------+-----+-----------------------+-------+ | Field | Type | Null | Key | Default | Extra | +------------------------+-----------------------------------+------+-----+-----------------------+-------+ | Host | char(60) | NO | PRI | | | | User | char(16) | NO | PRI | | | | Password | char(41) | NO | | | | mysql> update user set password=password('passw0rd') where user="root"; //设置密码为passw0rd mysql> flush privileges; //刷新
5. Thenlog outlog in again
[root@localhost ~]# mysql -uroot -ppassw0rd mysql>
The above is the detailed content of Sharing the solution for forgetting mysql password. For more information, please follow other related articles on the PHP Chinese website!