使用xampp访问mysql数据库_从另一台计算机访问XAMPP MySql数据库

bd96500e110b49cbb3cd949968f18be7.png

So a friend of mine and I are using both xampp on ubuntu, if that helps, to connect between each other's website, We both created the same php file to connect, so we use de IP of the other, but then it says an error

Warning: mysql_connect() [function.mysql-connect]: Host 'coke-laptop.local' is not allowed to connect to this MySQL server in /opt/lampp/htdocs/connection.php on line 2

Could not connect: Host 'coke-laptop.local' is not allowed to connect to this MySQL server

We have this code on the connection.php file:

$link = mysql_connect('10.100.161.37','root','');

if (!$link) {

die('Could not connect: ' . mysql_error());

}

//echo 'Connected successfully';

$db_selected = mysql_select_db('Prueba', $link);

if (!$db_selected) {

die ('Can\'t use Prueba : ' . mysql_error());

}

// This could be supplied by a user, for example

$firstname = 'fred';

$lastname = 'fox';

// Formulate Query

// This is the best way to perform an SQL query

// For more examples, see mysql_real_escape_string()

$query = sprintf("SELECT * FROM Agencia");

// Perform Query

$result = mysql_query($query);

// Check result

// This shows the actual query sent to MySQL, and the error. Useful for debugging.

if (!$result) {

$message = 'Invalid query: ' . mysql_error() . "\n";

$message .= 'Whole query: ' . $query;

die($message);

}

// Use result

// Attempting to print $result won't allow access to information in the resource

// One of the mysql result functions must be used

// See also mysql_result(), mysql_fetch_array(), mysql_fetch_row(), etc.

while ($row = mysql_fetch_assoc($result)) {

echo $row['ID'] . " ";

echo $row['Nombre'] . "\n\r";

}

// Free the resources associated with the result set

// This is done automatically at the end of the script

mysql_free_result($result);

mysql_close($link);

?>

If we use the IP just like that, we can enter each others xampp normal welcome page.

解决方案

Check you have enabled remote access to the MySQL server. Open the my.cnf file (probably found inside xampp/etc/), go to the [mysqld] section and add the following (using your own ip address instead of the example)

bind-address=192.168.1.100

If there is a line that says skip-networking, comment that out so it looks like this:

# skip-networking

then restart the MySQL server

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值