The user name and password are incorrect when the mysql password is correctly connected.

Source: Internet
Author: User

1. Use the following code to test the normal operation after installing the mysql database:

The code is as follows: Copy code

<?
$ Cn = mysql_connect ("localhost", "root", "root") or die ('database Server Password Error! ');
If ($ cn)
{
Echo 'success ';
}
Else
{
Echo 'fail ';
}
?>

2. After installing the phpcms configuration today, the connection prompt "Database Server Password Error" is displayed. This indicates that the Database connection is incorrect, but the connection to mysql in cmd is successful.

3. I thought about the hosts file I modified.

Open C: \ Windows \ System32 \ drivers \ etc \ and find the following

127.0.0.1 www.111cn.net

Then I was wondering if the above mysql_connect ("localhost", "root", "root") would not have localhost, but if it was specified in hosts, it would have connected to www.111cn.net, so I corrected it.


127.0.0.1 localhost
: 1 localhost

Save and connect to mysql. The above code is output.

Success


The problem is solved in this way. The reason is also simple because locahost is used. If you modify it, you will be connected to another station. If you do not want to modify hosts, you can change the mysql connection to 127.0.0.1.

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.