Home > Database > Mysql Tutorial > body text

Detailed explanation of forgotten MySql login password and solutions to forgotten passwords (picture)

黄舟
Release: 2017-03-23 13:54:58
Original
1786 people have browsed it

This article mainly introduces MySqlSolutions for forgotten login passwords and forgotten mysql The quick solution to the password is very good and has reference value. Friends who need it can refer to it

Method 1:

## MySQL provides command line parameters to skip

access control. Start the MySQL server with this command on the command line:

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

You can skip the access control of MySQL and anyone can control it. Enter the

MySQL database as an administrator.

It should be noted that after changing the password, you must stop and restart the MySQL server for it to take effect

Method 2:

You can follow the steps below to reset the MySQL root password:

1. First, confirm that the server is in a safe state, that is, No one can connect to the MySQL database arbitrarily

Because during the period of resetting the MySQL root password, the MySQL database is completely unprotected by a password, and other users can also log in and modify the MySQL database at will. Information. You can close MySQL's external port and stop Apache and all user processes to achieve a quasi-safe state. The safest state is to operate on the server's Console and unplug the network cable. #2. Modify MySQL login settings:

# vi /etc/my.cnf
Copy after login
Copy after login

Add a sentence in the [mysqld] section: skip-grant-tables

For example:

[mysqld] 
datadir=/var/lib/mysql 
socket=/var/lib/mysql/mysql.sock 
skip-name-resolve 
skip-grant-tables
Copy after login

Save and exit vi.

##3. Restart mysqld

# /etc/init.d/mysqld restart 
Stopping MySQL: [ OK ] 
Starting MySQL: [ OK ]
Copy after login
4. Log in and change the MySQL root password

#

# /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. 
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' ; 
Query OK, 0 rows affected (0.00 sec) 
Rows matched: 2 Changed: 0 Warnings: 0 
mysql> flush privileges ; 
Query OK, 0 rows affected (0.01 sec) 
mysql> quit 
Bye
Copy after login


##5. Modify the login settings of MySQL back

# vi /etc/my.cnf
Copy after login
Copy after login
Replace the [mysqld] Delete the skip-grant-tables added in the section
Save and exit vi.

6. Restart mysqld

# /etc/init.d/mysqld restart 
Stopping MySQL: [ OK ] 
Starting MySQL: [ OK ] 
windows
Copy after login

1. Log in to the system as the system administrator. .

2. Open cmd--net start to see if mysql is started. If it is started, stop net stop mysql.

3. My mysql is installed in d:\usr\local. \mysql4\bin.

4. Skip permission check and start mysql.

d:\usr\local\mysql4\bin\mysqld-nt –skip-grant-tables

5. Reopen cmd. Go to d:\usr\local\mysql4\bin:

d:\usr\local\mysql4\bin\mysqladmin -uroot flush-privileges password “newpassword”

d:\usr\local\mysql4\bin\mysqladmin -u root -p shutdown This prompts you to re-enter your password.​

6. Net start mysql in cmd ​

7. Done.

2, A solution to the password error problem in MySQL4.1 or above

# SET PASSWORD FOR 'some_user'@'some_host' = OLD_PASSWORD(‘newpwd'); 
# FLUSH PRIVILEGES;
Copy after login

3, Mysql database repair

myisamchk -r -q d:\mysql\data\latin1\*
Copy after login

r represents repair

q Represents fast

d:\mysql\data\latin1\*In the database*Represents all the files in it

Method three:

If you forget your MYSQL root password, you can restore it through the following process. 1. Send the kill command to mysqld server to shut down the mysqld server (not kill -9). The file storing the process ID is usually in the directory where the MYSQL database is located.

kill `cat /mysql-data-directory/hostname.pid`
Copy after login
You must be the root user of UNIX or the equivalent user on the SERVER you are running to perform this operation.

2. Use the `--skip-grant-tables' parameter to start mysqld.

3. Use the `mysql -h hostname mysql' command to log in to the mysqld server, and use the grant command to change the password. You can also do this: `mysqladmin -h hostname -u user password 'new password''.
(In fact, you can also use use mysql; update user set password =password('yourpass') where user='root' to do it.)


4. Load the permission table: ` mysqladmin -h hostname flush-privileges' , or use the SQL command `FLUSH PRIVILEGES'. (Of course, you can also restart mysqld here.)



Method 4: (Be sure to back up first)

1, restart Install the same version of MySQL on another computer2, delete all the contents of \data\mysql in the MySQL installation directory on the computer that has forgotten the password (stop the MySQL service first)

3,Copy新装的电脑上MySQL安装目录中\data\mysql的全部内容 to 刚刚删除的目录中

4,启动MySQL服务

PS:下面看下Mysql忘记密码解决方案

解决方法如下:

1、终端中结束当前正在运行的MySQL进程。

# sudo /etc/init.d/mysql stop
Copy after login

2、用mysql安全模式运行并跳过权限验证。

# sudo /usr/bin/mysqld_safe --skip-grant-tables
Copy after login

3、ctrl+T重开一个终端以root身份登录mysql。

# mysql -u root
Copy after login

4、修改root用户口令。

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('root') where User ='root';
Query OK, 3 rows affected (0.00 sec)
Rows matched: 3 Changed: 3 Warnings: 0
mysql> exit
Copy after login

注意:括号里的'root'就是新密码。

5、结束mysql安全模式,用正常模式运行mysql。

# sudo /etc/init.d/mysql restart
Copy after login

6、试试你新修改的口令登陆MySQL

#myslq -u root -p
Copy after login

输入密码 root

mysql> show grants for 'root'@'127.0.0.1'; 
mysql> flush privileges;
Copy after login

刷新账户后,退出。

mysql> quit;
Copy after login

The above is the detailed content of Detailed explanation of forgotten MySql login password and solutions to forgotten passwords (picture). For more information, please follow other related articles on the PHP Chinese website!

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