After the mysql password is forgotten, how to skip the password and log in again and change the password or how to set it if there is no my.ini file

I believe that there must be many friends like me who are struggling with how to change the password of MySQL, and how to log in successfully if the password is forgotten. Let me introduce the problem: the password for logging in to mysql is forgotten, and the MySQL I installed does not have what is said on the Internet. my.ini file if you have the same problem as me. So let's see how to solve it.

It’s very annoying to forget the password, and I can’t log in, (and I originally had the MySQL compressed package folder, and I downloaded another folder from the Internet) (It’s outrageous, I only found out that I downloaded mysql in the global search .)

After downloading from the webpage, there is no my.ini file in my compressed package , what should I do? What else can I do to configure it myself? After reading many articles on the Internet, I feel that I can do it again, so I started to configure it. In the end it still didn't work. (Trial and error engineering is always troublesome)

Not much to say, just create a text my.ini in the directory at the same level as bin, and create a data folder (used to put data)

The content inside is as follows, (remember to change the address below to the mysql address you put, don’t copy and paste directly)

[mysqld]
# Set port 3306
port=3306
# Set the installation directory of mysql ---------- is your file path -------------
basedir=D:\123 \mysql-8.0.29-winx64
# Set the data storage directory of the mysql database --------- is your file path data folder to create by itself
#datadir=D:\123\mysql-8.0.29- winx64\data
# Allow the maximum number of connections
max_connections=200
# Allow the number of connection failures.
max_connect_errors=10
#The character set used by the server is utf8mb4 by default
character-set-server=utf8mb4
#The default storage engine that will be used when creating a new table
default-storage-engine=INNODB
#The "mysql_native_password" plugin authentication is used by default
#mysql_native_password
default_authentication_plugin= mysql_native_password
[mysql]
# Set the default character set of mysql client
default-character-set=utf8mb4
[client]
# Set the default port used by the mysql client to connect to the server port
=3306
default-character-set=utf8mb4

After configuration, let's check whether the environment variable is configured properly. My path here is D:\123\mysql-8.0.29-winx64\bin, so I need to put this path in the environment variable, (this is very simple for me I won’t say much here, this should be common) (After all, many environment variables are needed)

OK, let's get down to business

First we open cmd as an administrator 

 After opening, first enter the following code (if you have already opened this service) first close the service

net stop mysql

Then enter the following code (this step is to skip the verification and log in to mysql directly without a password)

mysqld --console --skip-grant-tables --shared-memory

 Next, do not close this cmd, and then reopen a cmd as an administrator, and enter mysql directly to come in

 Then enter the following use mysql,

use mysql

 Use the following code to refresh the permissions, and then enter the command to change the password

flush privileges;

In the code, "123456" is the password I set, you can also change it to other

alter user root@localhost identified by '123456';

 After completion, close the cmd opened for the first time, then enter quit to exit, then open the mysql service, and then log in

quit
net start mysql
mysql -u root -p

The problem is solved here. 

Guess you like

Origin blog.csdn.net/qq_61897141/article/details/129973642