我有两个服务器名为server1和server2.both有不同的静态IP地址。我想从server1访问server2数据库。我安装了PHPmyadmin.In Server1操作系统是Ubuntu,在server2 fedora12。
我已经完成了这个..mysql错误13即将到来
server2中的my.cnf包含
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
user=mysql
# Default to using old password format for compatibility with mysql 3.x
# clients (those using the mysqlclient10 compatibility package).
old_passwords=1
# Disabling symbolic-links is recommended to prevent assorted security risks;
# to do so, uncomment this line:
# symbolic-links=0
# To allow mysqld to connect to a MySQL Cluster management daemon, uncomment
# these lines and adjust the connectstring as needed.
#ndbcluster
#ndb-connectstring="nodeid=4;host=localhost:1186"
[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
[ndbd]
# If you are running a MySQL Cluster storage daemon (ndbd) on this machine,
# adjust its connection to the management daemon here.
# Note: ndbd init script requires this to include nodeid!
connect-string="nodeid=2;host=localhost:1186"
[ndb_mgm]
# connection string for MySQL Cluster management tool
connect-string="host=localhost:1186"
答案 0 :(得分:3)
首先,您需要在MySql Server2上启用远程访问。
然后你就可以这样做:
mysql_connect("xxx.xxx.xxx.xxx", "username", "password") or die(mysql_error());
答案 1 :(得分:1)
如果您的问题是与远程mysql数据库的连接,那么您可以尝试以下代码:
$link = mysql_connect('example.com:3307', 'mysql_user', 'mysql_password');
曾为我工作过一次!
答案 2 :(得分:0)
尝试使用以下内容在connect_server2.php
上创建server1
文件:
<?
$server2 = '1.2.3.4'; // the IP of server2
echo mysql_connect($server2, 'username', 'password') ? 'you have been connected' : 'cannot connect to server2';
?>
答案 3 :(得分:0)
这取决于您希望如何访问server2上的数据库。
假设你只是想通过mysql客户端连接试试这个:
mysql -h <server2ip or hostname> -u <username> -p
在提示时输入密码。
如果你想通过php尝试这样的话,用server2中的ip替换server_ip,用mysql server2中的值替换username和password:
<?php
$link = mysql_connect('server_ip', 'user', 'password');
if (!$link) {
die('Error connecting to db: ' . mysql_error());
}
echo 'Successful conntected to database';
mysql_close($link);
?>