Get the App
SLTechnology News&Howtos  ›  Database  › 

How to solve the error code 1045 in MySql

Shulou Source: shulou.com Published: 2022-05-31 18:10:57 09月29日 Update

This article introduces the "MySql error code 1045 how to solve" the relevant knowledge, in the actual case of the operation process, many people will encounter such a dilemma, and then let the editor lead you to learn how to deal with these situations! I hope you can read it carefully and be able to achieve something!

Error code 1045

Access denied for user 'root'@'localhost' (using password:YES)

The solution is to reset the root user password. On Windows platform, the steps are as follows:

1. Log in to the system as a system administrator

If the MySQL server is running, stop it.

If it is a server running as a Windows service, go to Service Manager: start menu-> Control Panel-> Administrative tools-> Services

If the server is not running as a service, you may need to use Task Manager to force it to stop.

Create a text file and put the following commands on a single line:

SET PASSWORD FOR 'root'@'localhost' = PASSWORD (' MyNewPassword')

Save the file with any name. In this case, the file is C:\-init.txt.

4. Enter the DOS command prompt: start menu-> run-> cmd

Suppose you have installed MySQL to C:\ mysql. If you installed MySQL to another location, please adjust the following command accordingly.

From the DOS command prompt, execute the command:

C:\ > C:\ mysql\ bin\ mysqld-nt-- init-file=C:\ mysql-init.txt

When the server starts, the contents of the file named by the "--init-file" option (function: read the SQL command from the specified file at startup) are executed, and the root password is changed. When the server starts successfully, you should delete C:\ mysql-init.txt.

Stop the MySQL server and restart it in normal mode. If you run the server as a service, you should start it from the Windows services window. If you start the server manually, you can use commands as you would normally do.

Attached:

Other methods

Method 1: (recommended)

Mysql > use mysql

Mysql > UPDATE user SET Password=PASSWORD ('your new password') where USER='root'

Mysql > FLUSH PRIVILEGES

Mysql > quit

Method 2:

Directly use the username and password provided in the [client] section of the / etc/mysql/debian.cnf file:

# mysql-udebian-sys-maint-p

Enter password:

Mysql > UPDATE user SET Password=PASSWORD ('newpassword') where USER='root'

Mysql > FLUSH PRIVILEGES

Mysql > quit

# mysql-uroot-p

Enter password:

Mysql >

Another way.

Windows:

1. The administrator logs in to the system, stops the mysql service or ends the mysqld-nt process

two。 Enter the command line and go to the directory where mysql is installed. Suppose the installation directory is d:\ mysql\, and CMD enters the command line

3. Run d:\ mysql\ bin\ mysqld-nt-- skip-grant-tables to start mysql and turn off permission check

4. Run d:\ mysql\ bin\ mysqladmin-u root flush-privileges password "newpassword" to reset the root password

5. Restart the mysql service

This is the end of the content of "how to solve the error code 1045 in MySql". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Tags: Services commands servers runs files administration passwords methods code errors content users systems methods more directories knowledge administrators menus prompts Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MySQL Shulou Technology Shulou Tech Info macOS Redmi