码迷,mamicode.com
首页 > 数据库 > 详细

PHP远程连接mysql

时间:2016-10-15 16:43:12      阅读:205      评论:0      收藏:0      [点我收藏+]

标签:

http://blog.chinaunix.net/uid-23215128-id-2951624.html

# mysql -uroot
mysql> 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

标签:

原文地址:http://www.cnblogs.com/carbon3/p/5964387.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!