PHP远程连接mysql
时间:2021-07-01 10:21:17
帮助过:1人阅读
use mysql;
Database changed
mysql> SELECT `Host`,`
User`
FROM `
user`;
+-----------+--------+
| Host
| User |
+-----------+--------+
| 127.0.
0.1 | houtai
|
| 127.0.
0.1 | root
|
| ::
1 | root
|
| localhost
| houtai
|
| localhost
| root
|
+-----------+--------+
5 rows
in set (
0.00 sec)
mysql> UPDATE `
user`
SET `Host`
= ‘%‘ WHERE `
User`
= ‘root‘ LIMIT
1;
Query OK, 1 row affected (
0.00 sec)
Rows matched: 1 Changed:
1 Warnings:
0
mysql> SELECT `Host`,`
User`
FROM `
user`;
+-----------+--------+
| Host
| User |
+-----------+--------+
| % | root
|
| 127.0.
0.1 | houtai
|
| 127.0.
0.1 | root
|
| ::
1 | root
|
| localhost
| houtai
|
+-----------+--------+
5 rows
in set (
0.00 sec)
mysql> flush
privileges;
远程写个PHP脚本测试:
<?php
$con = mysqli_connect("IP","root","密码");
if (!$con)
{
die(‘Could not connect: ‘ . mysql_error());
}
else echo"connect ok!"
?>
服务器要关闭防火墙: iptables -F (service iptables stop)
显示: connect ok!
PHP远程连接mysql
标签: