简体   繁体   English

从另一台计算机访问XAMPP MySql数据库

[英]Accesing XAMPP MySql Database from Another Computer

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 所以我的一个朋友和我在ubuntu上使用xampp,如果有帮助,在彼此的网站之间建立连接,我们都创建了相同的php文件进行连接,所以我们使用另一个的IP,但后来它说错了

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: 我们在connection.php文件中有这个代码:

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

If we use the IP just like that, we can enter each others xampp normal welcome page. 如果我们像这样使用IP,我们可以输入xampp正常的欢迎页面。

Check you have enabled remote access to the MySQL server. 检查是否已启用对MySQL服务器的远程访问。 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) 打开my.cnf文件(可能在xampp / etc /中找到),转到[mysqld]部分并添加以下内容(使用您自己的IP地址而不是示例)

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 ,请注释掉,如下所示:

# skip-networking

then restart the MySQL server 然后重启MySQL服务器

It looks like your MySQL database isn't allowing you to connect remotely with the credentials you provided. 看起来您的MySQL数据库不允许您使用您提供的凭据远程连接。 You will need to configure a remote user to connect. 您需要配置远程用户才能进行连接。 Try looking into MySQL Grants . 尝试研究MySQL Grants

For Example: 例如:

GRANT SELECT, INSERT ON database.* TO 'someuser'@'somehost';

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何从另一台计算机远程数据库mysql XAMPP? - how to remote database mysql XAMPP from another computer? 从另一个驱动器上的文档根目录连接到XAMPP MySQL数据库 - Connect to XAMPP MySQL Database from Document Root on another Drive 使用 XAMPP 通过 MySQL 和 phpMyAdmin 从本地网络内的另一台计算机访问本地网站 - Accessing a local website from another computer inside the local network using XAMPP through MySQL & phpMyAdmin 使用PHP从MySQL InnoDB数据库[XAMPP]提取结果在我的计算机上比在其他计算机上花费的时间更长 - Fetching results from MySQL InnoDB database [XAMPP] with PHP takes a lot longer on my computer than on those of others 如何将 wordpress 站点(本地在 xampp 上)从一台计算机转移到另一台计算机 - How to transfer wordpress site (locally on xampp) from one computer to another 如何从另一台计算机或设备访问XAMPP虚拟主机? - How to access XAMPP virtual host from another computer or device? 如何将我的MySQL数据库传输到另一台计算机? - How to transfer my MySQL database to another computer? 在另一台计算机上备份mysql数据库 - Backing up mysql database on another computer 通过互联网IP地址从一台计算机访问xampp到另一台计算机 - Access xampp from one computer to another computer via internet ip address MySQL数据库xampp - MySQL database xampp
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM