Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/56.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用非本地主机用户通过php连接到mysql数据库_Php_Mysql - Fatal编程技术网

使用非本地主机用户通过php连接到mysql数据库

使用非本地主机用户通过php连接到mysql数据库,php,mysql,Php,Mysql,我有一个名为'test'@'111.11.11.111'的用户(例如) 当我打电话时 mysql_connect('localhost', //mysql is hosted locally (as far as php is concerned) 'test', //user is test 'password');//test's password 它会自动尝试登录“test”@“localhost”。正在尝试test@111.11.

我有一个名为'test'@'111.11.11.111'的用户(例如)

当我打电话时

mysql_connect('localhost', //mysql is hosted locally (as far as php is concerned)
              'test', //user is test
              'password');//test's password
它会自动尝试登录“test”@“localhost”。正在尝试
test@111.11.11.111
用户名的结果为
test@111.11.11.111@localhost
尝试登录

我可以告诉php或mysql登录'test'@'111.11.11.111'吗


编辑:mysql服务器托管在localhost上(从php的角度来看)。托管mysql数据库的服务器的IP不是111.11.11.111。用户是从IP地址111.11.11.111登录mysql服务器的,我不这么认为,设置用户可以从mysql服务器(在本例中为“111.11.11.111”)连接的位置是为了安全。据我所知,PHP无法覆盖该安全性。

您是否尝试使用111.11.11.111代替“localhost”?这应该会产生test@111.11.11.111

也许我误解了这个问题,但为什么您不能将connect语句更改为

mysql_connect('111.11.11.111','test','password');

是用户名test@111.11.11.111还是这种格式的?或者用户名是test,mysql安装在IP为111.11.11.111的机器上?你能再澄清一下你的问题吗?我的理解是mysql_connect的第一个参数是mysql服务器的位置,而不是用户的位置……这是正确的
localhost
只是一个预定义的字符串,它将映射到脚本运行所在的IP<代码>test@111.11.11.111表示它正试图以用户身份连接到111.11.11.111。“用户”的位置无关紧要。用户必须在运行mysql的同一台服务器上创建。因此,我的问题的答案是否,用户和mysql服务器必须存在于同一位置…我的理解是mysql_connect的第一个参数是mysql服务器的位置,不是用户的位置…数据库用户和数据库应该在同一台服务器上。