MysqlAccessdeniedforuserroot @ localhost error solution Summary

Source: Internet
Author: User
MysqlAccessdeniedforuserroot @ localhost "solution summary. Below we will analyze some common error codes and provide solutions. If you need them, please refer to them.

Mysql Access denied for user \ 'root \ '@ \ 'localhost \' "solution summary. Below we analyze some common error codes and provide solutions, for more information, see.

Code 1045

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

The solution is to reset the root user password. The procedure is as follows on Windows:
1. log on to the system as a system administrator;
2. If the MySQL server is running, stop it.
If the server runs 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 the task manager to force it to stop.
3. Create a text file and place the following commands in a single line:
Set password for 'root' @ 'localhost' = PASSWORD ('mynewpassword ');
Save the file with any name. In this example, the file is C: mysql-init.txt.
4. Enter the doscommand prompt: Start Menu-> Run-> cmd
Suppose you have installed MySQL to C: mysql. If you install MySQL in another location, adjust the following commands.
Run the following command at the doscommand prompt:
C:> C: mysqlbinmysqld-nt -- init-file = C: mysql-init.txt
When the server is started, run the "-- init-file" option (function: Read SQL commands from the specified file at startup) to change the root user password. C: mysql-init.txt should be deleted when the server is successfully started.
5. 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 service window. If the server is started manually, the command can be used as usual.
The new password should be used for connection.


My system is Ubuntu6.06. The newly installed mysql always has an error prompt when entering the mysql tool:

# Mysql-uroot-p
Enter password:
ERROR 1045 (28000): Access denied for user 'root' @ 'localhost' (using password: NO)

Use the methods described on the Internet to change 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 I have found the solution as follows (Please test method 3 first, thank you !) :

Method 1:

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: <输入新设的密码newpassword>


Another article about linux errors


On the Red Hat Enterprise Linux 5 Server, when mysql is started, the following ERROR occurs: ERROR 1045 (28000): Access denied for user 'root' @ 'localhost' (using password: NO)
Cause 1-startup command error:
When I started, I directly entered the command: mysql start
The correct startup command is:
/Etc/rc. d/init. d/mysql start

Cause 2-configuration file error:
Check my. cnf in etc as follows:

[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


Cause 3-Startup File error:
You need to modify the MySQL STARTUP script/etc/rc. d/init. d/mysql,
Where datadir =? Check one row!

Cause 4-The premise is that you report an error when using php connection!
In/etc/php. ini, modify the mysql. default_socket value:
Mysql. default_socket =/var/lib/mysql. sock
Return to the terminal and set a connection: ln-s/var/lib/mysql. sock/tmp/mysql. sock
(In the/etc/php. ini file mysql. default_socket, the description of the mysql. default_socket value is as follows,
; Default socket name for local MySQL connects. If empty, uses the built-in MySQL defaults.
This value is blank at the beginning, that is, if we do not take the initiative to modify it, php will use the default value built in mysql)


Note: In addition, service mysql star is required to start service mysql stop before it can be stopped.
The command cannot be found directly using mysql. The error is "bash: mysql: command not found". You can run the command directly in the bin folder and absolute path in the mysql installation directory, also need to add. /mysql can be executed.


There are several ways to change the password of mysql

Method 1

Use phpMyAdmin

(Graphical MySql database management tool), this is the simplest, directly use SQL statements to modify the user table of the mysql database, but do not forget to use the PASSWORD function, Insert the user using the Insert command, modify the user's use of the Update command and Delete the use of the Delete command. This section describes the user field of a data table.

Method 2

Use mysqladmin. Input

Mysqladmin-u root-p oldpassword newpasswd

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

Of course, if your mysqladmin cannot connect to mysql

Or you cannot execute mysqladmin. This method is invalid, and mysqladmin cannot clear the password.

The following methods are used at the mysql prompt and must have the root permission of mysql:

Method 3

Mysql> insert into mysql. user (Host, User, Password) VALUES ('%', 'system', PASSWORD ('manager '));

Mysql> FLUSH PRIVILEGES

Specifically, this is to add a user with the username system and Password manager. Be sure to use the PASSWORD function, and then use FLUSH

PRIVILEGES for confirmation.

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.