无法将php站点连接到mysql数据库?

时间:2016-07-11 07:56:27

标签: php mysql hosting

您好我用mysql开发了一个php网站。它在localhost上完美运作。我托管了我的网站并更改了数据库配置文件,

<?php 
    define("dbhost", "128.199.145.183");
    define("dbuser", "root");
    define("dbpass", "xxxxxxx");
    define("dbname", "database");

    $dbc = new mysqli(dbhost,dbuser,dbpass,dbname);

 ?> 

但它无效。我的网站工作正常,当我尝试登录时,我收到了HTTP 500错误。我该如何解决这个问题?

1 个答案:

答案 0 :(得分:1)

root数据库用户默认情况下无法远程访问数据库。

您可以通过查看mysql.user table

来验证这一点
use mysql;
select * from user;

检查root是否具有%

的ip访问权限

我建议,在主机上创建另一个用户权限有限的用户%(可以远程访问数据库)

您可以像这样创建用户:

use mysql; 
create user testing@'%' indentified by 'testing_password';
grant all on *.* to testing; // you can specify databases or specific permissions
flush privileges;