Home  >  Article  >  Backend Development  >  Centos - Linux terminal can connect to mysql database, but cannot connect to mysql through php program

Centos - Linux terminal can connect to mysql database, but cannot connect to mysql through php program

WBOY
WBOYOriginal
2016-10-10 11:56:171147browse

I can connect to the data through the xshell terminal:
But when I try to connect to the database online through a php (www.discountfollow.com/a.php) test file under the official domain name, the prompt:
the database is error: Access denied for user 'root'@'www.discountfollow.com' (using password: YES)
What is the reason for this problem? Thanks. . .

Reply content:

I can connect to the data through the xshell terminal:
But when I try to connect to the database online through a php (www.discountfollow.com/a.php) test file under the official domain name, the prompt:
the database is error: Access denied for user 'root'@'www.discountfollow.com' (using password: YES)
What is the reason for this problem? Thanks. . .

I once encountered a pitfall that database users can only monitor on 127.0.0.1, but not on localhost
Create a new database,

<code>CREATE DATABASE testdb;
</code>

You create a new database ordinary user,

<code>CREATE USER 'dba'@'127.0.0.1' IDENTIFIED BY '123456';
</code>

Authorization,

<code>Grant select, insert, update, delete on testdb.* to dba@'127.0.0.1' ;
</code>

Then use dbauser to connect testdbdatabase on 127.0.0.1

If the connection cannot be made, what is the error message? Debug based on error information, such as wrong address or wrong password. Port error etc.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn