The ultimate solution to mysql8.0 ERROR 1045 (28000): Access denied for user 'ODBC'@'localhost' (using password: NO)

When you enter mysql in the command line mode in the Windows system, an error is prompted:
ERROR 1045 (28000): Access denied for user 'ODBC'@'localhost' (using password: NO) Please
insert image description here
confirm first, the password you are using MySQL version, use the command mysql --version, note that there are 2 minus signs before the version,
insert image description here
first of all, declare that the MySQL version I use is:
mysql Ver 8.0.27 for Win64 on x86_64 (MySQL Community Server - GPL)
Others, MySQL Version, whether you can use the method I provided to solve it has not been tested yet,
but if you are the same version as me, using my method will definitely solve the problem you encounter.

Next, explain the principle
of the ERROR 1045 (28000): Access denied for user 'ODBC'@'localhost' (using password: NO)
problem.
Here, first explain the error message word by word. If you are not interested, please Skip and read on.

ERROR 1045 (28000):
The error and its code are given, this is not important,

Access denied for user:
access, denied, user,
the keyword here is user, user,
that is to say, this error message explains why this error occurs, and the root cause is that the wrong one is used A user tries to log in to MySQL,

(using password: NO):
This is useless, don’t look at it, it means: (using password: no)

'ODBC'@'localhost':
This is the ODBC user,
that is to say, when you do not specify a login user, when Windows connects to the MySQL database, it will use this ODBC user to connect to the MySQL database, regardless of your MySQL database Whether there is such an ODBC user, the Windows system will use this ODBC user to try to connect to the MySQL database. Personally, it should be that the Windows system is more familiar with ODBC. After all, there are many ODBC-related interfaces in Windows (Open Database Connection (Open Database Connection
) Database Connectivity, ODBC))
So, if you don’t want to use mysql -uroot -proot to log in to the MySQL database with two parameters (-u, -p), you just want to enter the MySQL console by directly typing the command mysql , you need to tell MySQL that you don’t want to use the ODBC user selected for you by the Windows system to connect to MySQL, you want to use a user you are familiar with to log in to MySQL, and when logging in, you don’t want to enter too many parameters, just use You can log in to the MySQL console with a mysql command,
so how to tell MySQL?

You need to know the operating mechanism of MySQL.
In the Windows environment, the startup of MySQL is to call the mysql service you installed in the Windows system. The
location of this service is Control Panel\All Control Panel Items\Windows Tools\Services (My terminal is the Windows home version)
If you can’t find it, please search it on Baidu.

insert image description here
insert image description hereOpen the service and find the mysql service. If you have installed different versions of MySQL many times, there may be other names, such as mysql57, mysql80, etc. Anyway, you know it is mysql. Right click and find
insert image description here
this mysql service, in the pop-up drop-down menu, click, properties,
insert image description hereyou can see, the mysql service, the final call is the mysqld.exe application program in the MySQL installation path, in the bin,
insert image description here
and this mysqld .exe application, when it starts, it will find a file at the first time, my.ini,
this my.ini file will tell mysqld what to do when it starts,
so we only need to configure my.ini The file can tell and direct MySQL how to do it, and we can log in to the MySQL console with only one command mysql without entering various tedious parameters. Therefore, the key to the problem lies in
this my.ini file is up.
The next step is to find the file my.ini.

It is very strange that the version of MySQL I downloaded from the MySQL official website does not have a my.ini file in its installation directory,
so, through a full search, I found this my.ini file in a directory,
C:\ ProgramData\MySQL\MySQL Server 8.0\my.ini
insert image description herecan be opened (using Notepad) and edited, but an error is reported when saving,

insert image description hereGood solution, copy the my.ini file from C:\ProgramData\MySQL\MySQL Server 8.0\, paste it to the Windows desktop, then edit and save it, and finally paste the edited and saved My.ini file Go back to the original directory,
C:\ProgramData\MySQL\MySQL Server 8.0\
The system will prompt to replace or skip the file, click to replace the file in the target (R), insert image description herethen click, continue, it can be completed, bypass Edit and save the my.ini file with Windows system permissions.
insert image description hereHowever, trying to log in to MySQL still reports an error,

Edited the My.ini file, but it didn’t work, not because our theory was wrong, but because the location of the my.ini file is wrong. Take another look at the
startup path of the mysql service.
insert image description here
Obviously, the mysql service needs to be started. is the mysqld.exe application,

insert image description here

And this application mysqld.exe will look for the my.ini file it needs in the MySQL installation path where it is located,
namely:
C:\Program Files\MySQL\MySQL Server 8.0\

insert image description here

And the directory where we found the My.ini file is:
C:\ProgramData\MySQL\MySQL Server 8.0
insert image description here

Obviously, what we need to do now is to move the edited my.ini file to the installation path where the mysqld.exe application is located, but please note that it is not under the same directory as the mysqld.exe application, but mysqld.exe in the directory above the parent directory bin of the application,
that is, C:\Program Files\MySQL\MySQL Server 8.0\

insert image description here
insert image description here
Check, is the current user, the root we want,
mysql> select user();
insert image description here
yes,

The problem is solved,
and there is no need to stop and start the MySQL service,
(net stop mysql, net start mysql)
does not need to be in [mysqld] in my.ini, skip-grant-tables
can solve the problem according to my method, Are you happy!

Here, let me add, edit the place and content that need to be changed in the my.ini file,
open the my.ini file, and find [mysql] (note that it is not mysqld, but mysql)

insert image description here
Then, enter the username and password we want MySQL to use for login.
Please note that here, the account number and password must be filled in, otherwise, the original error will be reported.

In fact, this problem has troubled me for some days. It has been more than half a year. During this period, I found a lot of posts on the Internet, all of which were copy-pasted. After receiving an explanation from a great god, I suddenly realized that yes, I had a new understanding and understanding of the startup process of MySQL, so I immediately did an experiment, and it went smoothly and directly succeeded. I will share it with you right away, hoping to help everyone. Avoid detours, I was really troubled at the beginning, and I almost smashed the computer. Thank you for the guidance of these great articles on the Internet, which protected my office terminal.
Paste the decisive article I saw and share it with everyone,

insert image description here
January the 06th 2022 Wednesday

Guess you like

Origin blog.csdn.net/m0_47505062/article/details/122342121