2010-08-17 20 views
5

Vì vậy, một người bạn của tôi và tôi đang sử dụng cả hai xampp trên ubuntu, nếu điều đó giúp, để kết nối giữa trang web của nhau, chúng tôi đã tạo ra cùng một tệp php để kết nối, vì vậy chúng tôi sử dụng de IP của người kia, nhưng sau đó nó nói lỗiXảy ra cơ sở dữ liệu MySql XAMPP từ một máy tính khác

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 

chúng tôi có mã này vào 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); 
?> 

Nếu chúng tôi sử dụng địa chỉ IP giống như vậy, chúng ta có thể nhập mỗi người khác xampp trang chào mừng bình thường.

+0

bạn đã trao 'than cốc-laptop.local' quyền truy cập vào cơ sở dữ liệu? I E. có người dùng cho máy chủ lưu trữ đó có thể truy cập cơ sở dữ liệu không? – Stephen

Trả lời

9

Kiểm tra bạn đã kích hoạt truy cập từ xa đến máy chủ MySQL. Mở file my.cnf (có thể tìm thấy bên trong xampp/etc /), đi đến phần [mysqld] và thêm dòng sau (sử dụng địa chỉ IP riêng của bạn thay vì ví dụ)

bind-address=192.168.1.100 

Nếu có một dòng mà nói skip-networking, nhận xét rằng ra để nó trông như thế này:

# skip-networking 

sau đó khởi động lại máy chủ MySQL

1

Dường như cơ sở dữ liệu MySQL của bạn không cho phép bạn kết nối từ xa bằng thông tin xác thực bạn đã cung cấp. Bạn sẽ cần phải cấu hình một người dùng từ xa để kết nối. Thử nhìn vào MySQL Grants.

Ví dụ:

GRANT SELECT, INSERT ON database.* TO 'someuser'@'somehost'; 
Các vấn đề liên quan