Today I encountered two problems: Can't connect to MySQL server and Access denied for user!

Source: Internet
Author: User

Problem 1: the local host connection is normal, but you cannot log on to the MySQL database from other computers!

The following is an excerpt from/etc/mysql/my. cnf:


# Instead of skip-networking the default is now to listen only on
# localhost which is more compatible and is not less secure.
bind-address = 10.0.0.1 # 127.0.0.1

It indicates that MySQL is set to only listen on localhost by default. Therefore, if the login MySQL Client and MySQL Server are not on the same computer, MySQL will not respond. Therefore, you need to modify the bind-address here to the external IP address of this computer.

Problem 2: ERROR 1045 (28000): Access denied for user 'root' @ '10. 0.0.1 '(using password: YES )!

This is also quite interesting. First, let's look at the information in the original system table:


mysql> USE mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed

mysql> SELECT Host FROM user WHERE user='root';
+-----------+
| Host      |
+-----------+
| sharkwang |
| localhost |
+-----------+
2 rows in set (0.00 sec)

Well, in addition to localhost, there is actually a sharkwang, And I used IP instead of hostname to connect to it!

Therefore, there are two solutions:

1. Modify the/etc/hosts file on the computer where the MySQL Client is located and add the hosting between hostname and IP address.

Logon method: shell> mysql-h <mysql_server_hostname>-u root-p

2. Add a record to the user table of the MySQL database. For details, refer:

SELECT * FROM user WHERE User = 'root' AND Host = 'localhost'

Then, change the Host value to the MySQL Server's external IP address.

Logon method: shell> mysql-h <mysql_server_ip>-u root-p

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.