MySql login password forgotten and password forgotten solution

MySql login password forgotten and password forgotten solution

Method 1:

MySQL provides a command line parameter to skip access control by starting the MySQL server with this command on the command line:

safe_mysqld --skip-grant-tables&

You can skip MySQL access control and anyone can access the MySQL database as an administrator in the console.

It should be noted that after changing the password, the MySQL server must be stopped and restarted for it to take effect.

Method 2:

You can reset the MySQL root password by following these steps:

1. First, make sure that the server is in a secure state, that is, no one can connect to the MySQL database at will.

Because during the period of resetting the MySQL root password, the MySQL database is completely in a state without password protection, other users can also log in and modify MySQL information at will. You can achieve a quasi-safe state for the server by closing the external port of MySQL and stopping Apache and all user processes. The safest state is to operate on the server console and unplug the network cable.

2. Modify MySQL login settings:

# vi /etc/my.cnf

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

Save and exit vi.

3. Restart mysqld

# /etc/init.d/mysqld restart 
Stopping MySQL: [ OK ] 
Starting MySQL: [ OK ]

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 


5. Change the MySQL login settings back

# vi /etc/my.cnf

Delete the skip-grant-tables just added to the [mysqld] section.

Save and exit vi.

6. Restart mysqld

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

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

2. Open cmd —–net start to check whether MySQL is started. If started, stop it with net stop mysql.

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

4. Skip the 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 sentence prompts you to re-enter the password.

6. In cmd, net start mysql

7. Done.

2. A solution to the password error problem in MySQL 4.1 and above

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

3. MySQL database repair

myisamchk -r -qd:\mysql\data\latin1\*

r stands for repair

q stands for quick

d:\mysql\data\latin1\* The * in the database represents all the files in it

Method 3:

If you forget your MYSQL root password, you can recover it by following the procedure below.

1. Send a kill command to mysqld server to shut down mysqld server (not kill -9). The file that stores the process ID is usually in the directory where the MYSQL database is located.

kill `cat /mysql-data-directory/hostname.pid`

You must be the UNIX root user or an equivalent user on the server you are running to perform this operation.

2. Start mysqld with the `--skip-grant-tables' option.

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

4. Load the privilege 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. Reinstall the same version of MySQL on another computer

2. Delete all the contents of \data\mysql in the MySQL installation directory on the computer where the password is forgotten (stop the MySQL service first)

3. Copy all the contents of \data\mysql in the MySQL installation directory on the newly installed computer to the directory just deleted

4. Start the MySQL service

PS: Let’s take a look at the solution to forgetting the Mysql password

The solution is as follows:

1. End the currently running MySQL process in the terminal.

# sudo /etc/init.d/mysql stop

2. Run in MySQL safe mode and skip permission verification.

# sudo /usr/bin/mysqld_safe --skip-grant-tables

3. Press ctrl+T to reopen a terminal and log in to mysql as root.

# mysql -u root

4. Change the root user password.

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

Note: The 'root' in brackets is the new password.

5. End MySQL safe mode and run MySQL in normal mode.

# sudo /etc/init.d/mysql restart

6. Try your new password to log in to MySQL

#myslq -u root -p

Enter the root password

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

After refreshing your account, log out.

mysql> quit;

You can refer to the following special introduction about MySQL on this site:

MySQL installation tutorials for various systems https://www.jb51.net/Special/917.htm

Mysql Root Password Operation Tips https://www.jb51.net/Special/846.htm

MySql database introductory tutorial https://www.jb51.net/Special/643.htm

Summary of database operation knowledge in MySQL https://www.jb51.net/Special/635.htm

The above is the solution to the problem of forgetting the MySql login password introduced by the editor. I hope it will be helpful to everyone. If you have any questions, please leave me a message and the editor will reply to you in time. I would also like to thank everyone for their support of the 123WORDPRESS.COM website!

You may also be interested in:
  • Initialize MySQL users (delete anonymous users)
  • How to delete anonymous users in MYSQL (to improve security)
  • Solution to MySQL server login error ERROR 1820 (HY000)
  • Solve the problem of changing the password when logging in for the first time after installing MySQL 8.0
  • Solution to the problem that the mysql8.0.11 client cannot log in
  • How to quickly log in to MySQL database without password under Shell
  • A brief discussion on the problem of forgotten mysql password and login error
  • PHP+MySQL method to realize user registration and login
  • Solution to adding a new user to mysql and not being able to log in
  • Mysql anonymous login cannot create a database problem solution

<<:  Example of how to start a container with multiple network interfaces using docker

>>:  Node.js sends emails based on STMP protocol and EWS protocol

Recommend

MySQL multi-instance configuration application scenario

Table of contents MySQL multiple instances Multi-...

10 Underused or Misunderstood HTML Tags

Here are 10 HTML tags that are underused or misun...

Detailed tutorial for installing mysql 8.0.12 under Windows

This article shares with you a detailed tutorial ...

Detailed explanation of Linux netfilter/iptables knowledge points

Netfilter Netfilter is a packet processing module...

Vue network request scheme native network request and js network request library

1. Native network request 1. XMLHttpRequest (w3c ...

HTML form component example code

HTML forms are used to collect different types of...

How to maintain MySQL indexes and data tables

Table of contents Find and fix table conflicts Up...

A very detailed tutorial on installing rocketmq under Docker Desktop

Install Docker Desktop Download address: Docker D...

How to install MySQL 5.7 on Ubuntu and configure the data storage path

1. Install MySQL This article is installed via AP...

Detailed explanation of WeChat Mini Program official face verification

The mini program collected user personal informat...

Share CSS writing standards and order [recommended for everyone to use]

CSS writing order 1. Position attributes (positio...

A detailed introduction to Linux memory management and addressing

Table of contents 1. Concept Memory management mo...

HTML Tutorial: Collection of commonly used HTML tags (6)

These introduced HTML tags do not necessarily ful...

Detailed explanation of React setState data update mechanism

Table of contents Why use setState Usage of setSt...