从不同的服务器访问数据库 [英] Accessing DataBases from different servers

查看:129
本文介绍了从不同的服务器访问数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我拥有一个托管在两个不同服务器server1和server2上的网站网络。

我需要能够从站点中的PHP脚本访问存储在server1上的MySQL数据库中的数据寄存在server2上。



假设一个用户在server1上的site1上注册,并且他的数据被插入到server1上的DataBase中。现在,该用户将能够使用相同的注册登录server2上的site2。

这意味着server2上的PHP脚本需要访问server1上的MySQL数据库。我不想将用户数据复制到server2上的数据库,因为用户也可能在site1上编辑他或她的用户信息。



我想能够在不编辑服务器数据的情况下共享这些数据(如 http://www.cyberciti.biz/tips/how-do-i-enable-remote-access-to-mysql-database-server.html )。
到目前为止,我还没有能够找到一个可靠的方法来实现这一点,有谁知道如何使用PHP(或JavaScript)来做到这一点,但我更喜欢系统为每个人工作,无论如何JS已启用)?



谢谢!

解决方案

通过允许您的其他服务器主机名连接到您的数据库来实现这一点。



在MySQL命令提示符或phpmyadmin中执行查询:

GRANT ALL ON databasename。* TO username @'ipaddress'IDENTIFIED BY'somepassword';



http:// www.cyberciti.biz/tips/how-do-i-enable-remote-access-to-mysql-database-server.html


I have a network of websites hosted on two different servers, server1 and server2.
I need to be able to access the data stored in a MySQL DataBase on server1 from a PHP script in a site hosted on server2.

Say a user registers on site1 on server1 and his data is inserted into the DataBase on server1. Now, that user would be able to log in on site2 on server2 with the same registration.
That would mean the PHP script on server2 needs access to the MySQL DB on server1. I don't want to copy the user data over to a DB on server2, because the user might also edit his or her user information on site1.

I'd like to be able to share this data without editing the server's data (as in http://www.cyberciti.biz/tips/how-do-i-enable-remote-access-to-mysql-database-server.html). So far, I haven't been able to figure out a secure way of achieving this, does anyone know how to do this using PHP (or JavaScript, but I'd prefer the system to work for everyone, regardless if JS is enabled)?

Thank you!

解决方案

You can achieve this by allowing your other servers hostname to connect to your database.

In a MySQL command prompt or phpmyadmin execute the query:

GRANT ALL ON databasename.* TO username@'ipaddress' IDENTIFIED BY 'somepassword';

http://www.cyberciti.biz/tips/how-do-i-enable-remote-access-to-mysql-database-server.html

这篇关于从不同的服务器访问数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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