phpmyadmin 同步

发布于 2024-10-19 04:48:27 字数 344 浏览 0 评论 0原文

我在网络酒店上有一个远程服务器,我想与本地服务器同步。

我的计划是通过主从关系来执行此操作,但网络主机作为虚拟服务器运行,所以问题一是,是否可以将我的服务器部分设置为主服务器? (主机对此不太了解)

我的另一个但不太棒的想法是通过主机或本地服务器上的 phpmyadmin 手动同步(它们都运行 mysql/phpmyadmin,但我更喜欢如果我可以从本地同步到主机) )

当我尝试从主机或本地同步时,出现以下错误:

“无法连接到目标/源”

我该如何解决这个问题?我是数据库互连的新手,所以我是否必须在本地或远程的任何地方启用任何功能?

I have a remote server on webhotel which i want to synchronize with my local server.

My plan was to either do this though the master - slave relation but the webhost is running as a virtual server, so question one is, is it possible to set my portion of the server up to master server? (The host didnt know much about this)

My other but less awesome idea was to manually synchronize through phpmyadmin on either the host or the local server (They are both running mysql/phpmyadmin, but i would prefer if i could sync from local to host)

When i try to sync either from host or from local i get the following error:

"Cannot connect to target/source"

How do I get around this? I am a novice with DB interconnections so do i have to enable anything anywhere on either local or remote?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

九局 2024-10-26 04:48:27

您似乎在这里遇到了一些问题,

超时

我将从这里开始,因为您可能遇到权限问题。我建议首先确保您的本地 IP 地址有权连接到远程 MySQL 数据库,反之亦然,根据您的设置,您可以在 phpMyAdmin、托管控制台(例如 cPanel)或通过 shell 访问进行配置。我建议设置一个单独的用户,并使用强密码进行远程访问。
您的本地互联网连接上应该有一个静态 IP 地址,如果没有,请联系您的互联网服务提供商并安排一个。

在 phpMyAdmin 中,如果您有足够的访问权限,请通过“用户权限”选项卡并在“登录信息”下设置“主机”。出于明显的安全原因,我不会推荐“任何主机”设置。

在 cPanel 中的“数据库”下,您应该找到“远程 mySQL”,您可以在其中设置 IP 地址。

最后在 SSH 中,

  1. 使用您最喜欢的编辑器(例如 VI 或 Nano)打开 mySQL 配置文件,在 Ubuntu 上它位于“/etc/mysql/my.conf”,
  2. 注释掉“bind-address = 127.0.0.1”,这样看起来例如“#bind-address = 127.0.0.1”,
  3. 使用“/etc/init.d/mysql restart”重新启动mySQL,
  4. 使用“mysql -u root -p”登录mySQL,
  5. 对于新用户,“CREATE USER 'MY_USERNAME '@'localhost' IDENTIFIED BY 'MY_PASSWORD'"
  6. 后跟“将 'MY_DATABASE'.* 上的所有权限授予 'MY_USERNAME'@'12.34.56.78' IDENTIFIED BY 'MY_PASSWORD';” - 注意,将IP“12.34.56.78”替换为您的实际IP地址。
  7. 您现在应该可以确认查询是否正确。
  8. 最后使用“quit”命令退出 mysql,并使用“/etc/init.d/mysql restart”重新启动

注意:我建议将两个 mySQL 安装设置为远程访问。

我现在建议通过在本地计算机上运行一个小脚本来测试这一点,例如

<?php
$host = 'mysql_remoteip';
$user = 'mysql_username';
$pass = 'mysql_password';
$db = 'mysql_database';

$link = mysql_connect($host, $user, $pass) or die("Can not connect." . mysql_error());
mysql_select_db($db) or die("OOPS! I can not connect to the remote mySQL database, I was given the following error: ".mysql_error());
$sql = "SELECT column FROM table WHERE column='my_var'";
$result = mysql_query($sql);
while($row = mysql_fetch_array($result)) {
if(empty($row['column']) {
echo "WHOOPS! I could not get information from the mySQL, was there data for me to retrieve in the database?";
} else {
echo "The data I retrieved is:<br />"
echo $row['column'];
}
}
?>

注意:数据库中应该有数据,脚本才能正常工作,没有数据的结果将显示一条消息,表明脚本无法检索数据,这仍然会确定您现在是否有权访问数据库,但不能确保它 100% 可操作。

主或从

是的,这是可能的,只要您有足够的访问权限

在 phpMyAdmin 中:

  1. 在“复制”选项卡下,您将找到一个向导,为您提供在 mySQL 配置文件中设置此设置的代码(在 Ubuntu 上,它位于“/etc/mysql/my.conf”),
  2. 单击链接来配置主服务器,
  3. 在表单中输入信息,将代码复制
  4. 到您的配置文件(上面的位置)并添加代码由 phpMyAdmin 提供,
  5. 更新配置文件后,重新启动 mySQL 并单击 phpMyAdmin 中的“执行”按钮,这将确认更改。
  6. 现在再次在“复制”选项卡下单击链接以配置从服务器
  7. ,确保您在 phpMyAdmin 中有唯一的服务器 ID您的配置文件,如果没有将 phpMyAdmin 提供的行添加到文件的 [mysqld] 部分中
  8. 完成所需的信息并单击 Go

这应该会设置您的复制。

同步

如果所有其他方法均失败,则在 phpMyAdmin 中转到“同步”选项卡,输入信息即可离开,您只需在下一页上确认同步,2 秒后即可完成了,就是这么简单。

对于生产服务器,我个人有一个主/从复制设置,但对于开发,当我需要“实时”数据来复制错误或问题时,我会进行同步,这是因为我只需要每 6-12 个月同步一次。如果我需要本地实时数据,那么我会设置主/从复制

You seem to have a couple of issues here,

TIME OUT

I would start here as you may have a permissions problem. I would recommend first ensuring that your local IP address has permission to connect to your remote mySQL database and vice versa, depending on your setup you may be able to configure this in phpMyAdmin, a hosting consule such as cPanel or via shell access. I would suggest setting up a separate user with a strong password for remote access.
You should have a static IP address on your local internet connection, if you do not have one contact your Internet Service Provider and arrange one.

In phpMyAdmin, if you have sufficient access, via the "user privileges" tab and setting the "host" under "login information". I would not recommend the "any host" setting for obvious security reasons.

In cPanel, under "databases" you should find "remote mySQL" where you can set your IP address.

Finally in SSH,

  1. open the mySQL configuration file with your favorite editor such as VI or Nano, on Ubuntu it is located at "/etc/mysql/my.conf",
  2. comment out "bind-address = 127.0.0.1" so it looks like "#bind-address = 127.0.0.1",
  3. restart mySQL with "/etc/init.d/mysql restart",
  4. log into mySQL with "mysql -u root -p",
  5. for a new user, "CREATE USER 'MY_USERNAME'@'localhost' IDENTIFIED BY 'MY_PASSWORD'"
  6. followed with "GRANT ALL PRIVILEGES ON 'MY_DATABASE'.* TO 'MY_USERNAME'@'12.34.56.78' IDENTIFIED BY 'MY_PASSWORD';" - note, replace the IP "12.34.56.78" with your actual IP address.
  7. You should now have confirmation along the lines of query ok.
  8. Finally exit mysql with the "quit" command and restart with "/etc/init.d/mysql restart"

NOTE: I would recommend setting up both mySQL installations for remote access.

I would now recommend testing this by running a small script on your local machine, something like

<?php
$host = 'mysql_remoteip';
$user = 'mysql_username';
$pass = 'mysql_password';
$db = 'mysql_database';

$link = mysql_connect($host, $user, $pass) or die("Can not connect." . mysql_error());
mysql_select_db($db) or die("OOPS! I can not connect to the remote mySQL database, I was given the following error: ".mysql_error());
$sql = "SELECT column FROM table WHERE column='my_var'";
$result = mysql_query($sql);
while($row = mysql_fetch_array($result)) {
if(empty($row['column']) {
echo "WHOOPS! I could not get information from the mySQL, was there data for me to retrieve in the database?";
} else {
echo "The data I retrieved is:<br />"
echo $row['column'];
}
}
?>

NOTE: you should have data in the database for the script to work correctly, a result with no data will display a message that the script could not retrieve the data, this will still establish if you now have access to the database or not but doesn't ensure it is 100% operational.

MASTER OR SLAVE

Yes, it is possible, providing you have sufficient access

In phpMyAdmin:

  1. under the "replication" tab you will find a wizard to provide you with the code to set this in the mySQL configuration file (on Ubuntu it is located at "/etc/mysql/my.conf"),
  2. click on the link to configure the master server
  3. enter the information in the form, copy the code
  4. go to your configuration file (location above) and add the code provided by phpMyAdmin
  5. once you update the configuration file restart mySQL and click the go button in phpMyAdmin, this will confirm the changes
  6. Now again under the "replication" tab click the link to configure the slave server
  7. make sure, you have unique server-id in your configuration file, if not add the line provided by phpMyAdmin into [mysqld] section of the file
  8. Complete the required information and click Go

This should set up your replication.

SYNCHRONIZE

If all else has failed then in phpMyAdmin go to the "synchronize" tab, enter the information and away you go, you just need to confirm the sync on the next page and 2 seconds later you're done, it is that easy.

For production servers I personally have a master/slave replication set-up but for development I sync when I need "live" data to replicate an error or problem, this is because I only need to sync once every 6-12 months. If I need live data locally then I would set up the master/slave replication

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文