MySQL Access denied for user Root@localhost Error Resolution Summary

Source: Internet
Author: User
Tags flush mysql in socket

Error code 1045

Access denied for user ' root ' @ ' localhost ' (using Password:yes)

The workaround is to reset the root password by following the steps in the Windows platform:

1, as a system administrator login to the system;

2, 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-> management tools-> Services

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

3. Create 1 text files and place 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:mysql-init.txt.

4, enter the DOS command prompt: Start menu-> run-> cmd

Assume that you have installed MySQL to C:mysql. If you have MySQL installed in another location, please adjust the following command accordingly.

At the DOS command prompt, execute the command:

C:> c:mysqlbinmysqld-nt--init-file=c:mysql-init.txt

When the server starts, executes the contents of the file named by the "--init-file" option, which reads the SQL command from the specified file at startup, and changes the root user password. After the server has successfully started, you should delete the C:mysql-init.txt.

5, stop the MySQL server, and then 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 the command as you normally would.

You should be able to connect using the new password.

My system is Ubuntu6.06, recently installed good MySQL in the MySQL tool, always have the error tip:

# mysql-uroot-p

Enter Password:

ERROR 1045 (28000): Access denied for user ' root ' @ ' localhost ' (using Password:no)

Use the method described on the web to modify the password of the root user:

The code is as follows

# mysqladmin-uroot-p password ' newpassword '

Enter Password:

Mysqladmin:connect to server at ' localhost ' failed

Error: ' Access denied for user ' root ' localhost ' (using Password:yes) '

Now finally I found the solution, as follows (please test method three, thank you!) ):

Method One:

The code is as follows

#/etc/init.d/mysql Stop

# Mysqld_safe--user=mysql--skip-grant-tables--skip-networking &

# mysql-u Root MySQL

mysql> UPDATE user SET Password=password (' NewPassword ') where user= ' root '

mysql> FLUSH privileges;

Mysql> quit

#/etc/init.d/mysql Restart

# mysql-uroot-p

Enter Password: < Enter the new password newpassword>

Another article about Linux bugs

Red Hat Enterprise Linux 5 server mysql boot error: Error 1045 (28000): Access denied for user ' root ' @ ' localhost ' (using Password:no)

Reason 1-startup command error:

I started with the Direct input command: MySQL start

The correct startup commands are:

/etc/rc.d/init.d/mysql start

Reason 2-config file error:

Check the following my.cnf for etc:

[Client]

The code is as follows

#password = Your_password

Port = 3306

Socket =/usr/mysql-data/mysql.sock

# here follows entries for some specific programs

# The MySQL server

[Mysqld]

Port = 3306

Socket =/usr/mysql-data/mysql.sock

Reason 3-Startup file error:

Need to modify MySQL startup script/etc/rc.d/init.d/mysql,

Which datadir=? Check the line!

Reason 4-The premise is that you are using PHP connection when the error!

The value of the/etc/php.ini modification Mysql.default_socket is set to:

Mysql.default_socket=/var/lib/mysql/mysql.sock

Back to the end set up a connection: Ln-s/var/lib/mysql/mysql.sock/tmp/mysql.sock

(in/etc/php.ini mysql.default_socket this file, the description of the value of Mysql.default_socket is this,

;D efault socket name for the local MySQL connects. If empty, uses the built-in MySQL defaults.

This value is empty at first, which means that if we don't change it, PHP will use the default values built into MySQL.

Attention:

You also encounter the need for service MySQL star to start the service MySQL stop to stop.

There is also a direct use of MySQL can not find the command, the error is "Bash:mysql:command not found" can be directly **mysql in the installation directory of the Bin folder with the absolute path to run the command, and some need to add./mysql to execute.

MySQL modified password method has several

Method One 

Using phpMyAdmin

(graphical management of MySQL database Tools), this is the simplest, directly with SQL statements to modify the MySQL Database Library user table, but do not forget to use the password function, insert the user with the Insert command, modify the user with the update command, delete the deletion with the delete command. A detailed description of the data table User field is available later in this section.

Method Two 

Use Mysqladmin. Input

Mysqladmin-u root-p OldPassword newpasswd

After executing this command, you need to enter the original password of root, so that the root password will be changed to NEWPASSWD. Again, change the command root to your username, and you can change your password.

Of course, if your mysqladmin doesn't connect to MySQL,

Server, or you have no way to execute mysqladmin, this method is invalid, and mysqladmin cannot empty the password.

The following methods are used at the MySQL prompt and must have the root permissions of MySQL:

Method Three  

Mysql> INSERT into Mysql.user (Host,user,password) VALUES ('% ', ' system ', Password (' manager '));

Mysql> FLUSH Privileges

Specifically, this is adding a user named system with a password of manager. Note that you want to use the password function, and then use flush privileges to perform the validation.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.