从另一台计算机访问XAMPP MySql数据库 [英] Accesing XAMPP MySql Database from Another Computer

查看:308
本文介绍了从另一台计算机访问XAMPP MySql数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,我的一个朋友和我正在ubuntu上同时使用xampp来连接彼此的网站,我们都创建了相同的php文件进行连接,因此我们使用了另一个的de IP,但后来说错了

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

在connection.php文件上有以下代码:

We have this code on the connection.php file:

<?php
$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);
?>

如果我们只是这样使用IP,则可以互相进入xampp的常规欢迎页面.

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

推荐答案

检查是否已启用对MySQL服务器的远程访问.打开my.cnf文件(可能在xampp/etc/中找到),转到[mysqld]部分并添加以下内容(使用您自己的IP地址而不是示例)

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

如果有一行显示skip-networking,请将其注释掉,使其看起来像这样:

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

# skip-networking

然后重新启动MySQL服务器

then restart the MySQL server

这篇关于从另一台计算机访问XAMPP MySql数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆