Remote access to MySQL

Source: Internet
Author: User
Tags flush

Problem description

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


First, modify the root user's password
Method One:

/etc/init.d/mysql stopmysqld_safe--user=mysql--skip-grant-tables--skip-networking &//Skip permissions Mysql-u root mysql**

mysql> UPDATE user SET Password=password (' NewPassword ') where user= ' root ';
mysql> FLUSH privileges;
Mysql> quit

/etc/init.d/mysql restartmysql-uroot-p

Enter Password: < Enter the newly set password newpassword>

Method Two
Use Mysqladmin. Input

Mysqladmin-u root-p OldPassword newpasswd
After executing this command, you need to enter the root's original password so that the root password will be changed to NEWPASSWD. Similarly, you can change your password by changing the root of the command to your username.
Of course if your mysqladmin is not connected to MySQL server, or you have no way to execute mysqladmin, then this method is invalid, and mysqladmin cannot empty the password.

The following methods are used at the MySQL prompt and must have root privileges for MySQL:

Method Three
Mysql> INSERT into Mysql.user (Host,user,password) VALUES ('% ', ' admin ', Password (' admin '));
Mysql> FLUSH Privileges
This is the addition of a user, username and password for admin. Note that you use the password function, and then you use the flush privileges to perform the acknowledgment.

Method Four
As with method Three, just use the Replace statement
Mysql> REPLACE into Mysql.user (Host,user,password) VALUES ('% ', ' system ', Password (' manager '));
Mysql> FLUSH Privileges

Method Five
Using the Set Password statement
mysql> SET PASSWORD for [email protected] "%" = PASSWORD (' manager ');
You must also use the password () function, but you do not need to use flush privileges to perform acknowledgments.

Method Six
Use Grant ... The identified by statement to authorize.
Mysql> Grant all privileges the [email protected] identified by ' Admin123 ' with GRANT option;
Mysql> FLUSH Privileges
Here the password () function is unnecessary and does not require the flush privileges to perform the acknowledgment.
PASSWORD () function is for password word encryption, in the program MySQL automatic interpretation.

Remote access to MySQL

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: 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.