2010-08-17 164 views
5

所以我的一個朋友和我在ubuntu上都使用xampp,如果有幫助,在彼此的網站之間進行連接,我們都創建了相同的php文件來連接,所以我們使用de IP其他的,但後來它說錯誤從另一臺計算機訪問XAMPP MySql數據庫

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文件驗證碼:

<?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正常的歡迎頁面。

+0

你提供給數據庫'焦炭laptop.local'訪問?即該主機的用戶可以訪問數據庫嗎? – Stephen 2010-08-17 21:47:14

回答

9

檢查已啓用MySQL服務器的遠程訪問。打開my.cnf文件(裏面XAMPP的/ etc /可能會發現),轉到[mysqld]部分,並添加以下內容(使用自己的IP地址,而不是實例)

bind-address=192.168.1.100 

如果有這樣一行skip-networking,評論說出來,所以它看起來是這樣的:

# skip-networking 

然後重新啓動MySQL服務器

1

它看起來像你的MySQL數據庫不允許你遠程連接你提供的憑據。您將需要配置遠程用戶進行連接。嘗試調查MySQL Grants

例如:

GRANT SELECT, INSERT ON database.* TO 'someuser'@'somehost'; 
相關問題