php和数据库问题
我一直在我的计算机上的我自己的 xampp 服务器上使用我自己的数据库和所有内容开发一个网站,到目前为止,它非常顺利,令人惊讶。现在我想将其上传到主机,我找到了一个免费的网络主机,并且我能够通过 dreamweaver/ftp 上传该网站。我将数据库导出到 SQL 查询中,然后在实时数据库上运行该查询,以便它们具有相同的数据。
我很好奇,保持这些数据库同步的最佳方法是什么?
1)在我的 header.php 中,我为本地数据库指定了一些连接变量,并且必须确保在将 header.php 上传到站点时更改它们,以便它们具有远程数据库的正确连接变量。也许如果我的托管服务器上有一个文件,并且本地服务器上有一个文件指定了连接信息并且永远不会弄乱它们?
2)如果我更改本地数据库中的某些内容,我必须复制 SQL 并在远程数据库中运行它。有没有好的方法来处理这个问题?
再次感谢!
I've been working on a website on my own xampp server on my computer with my own database and everything and so far it's been pretty smooth, surprisingly. Now I want to upload it to a host, and I found a free web host and I was able to upload the site through dreamweaver/ftp. I exported my DB into an SQL query and than ran that query on the live DB so that they would have the same data.
I'm curious, what's the best way to keep these DB's in sync?
1) In my header.php, I specify some connection variables for my local db and I have to make sure to change them when I upload header.php to the site so they have the correct connection variables for the remote db. Maybe if I had a file on my hosting server and a file on my local server that specified the connection information and just never messed with them?
2) If I change something in my local DB, I have to copy the SQL and run it in my remote one as well. Is there a good way to handle this?
Thanks again!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
http://www.databasejournal。 com/features/mysql/article.php/3355201/Database-Replication-in-MySQL.htm
http://www.databasejournal.com/features/mysql/article.php/3355201/Database-Replication-in-MySQL.htm
对于#1,您可以这样做(大多数人采用的路线),或者让配置文件在加载服务器特定配置之前检查 IP。如果 IP 是 127.0.0.1,则加载开发配置。如果是主机的 IP,则会加载不同的配置。
我个人不知道有更好的方法来处理#2。所以,这个答案一定是不完整的。
For #1, you can either do that--the route most people take--or make the config file check the IP before loading server specific configuration. If the IP is 127.0.0.1, you load your development configuration. If it is the IP of the host, it loads a different config.
I personally do not know of a better way to handle #2. So, this answer will have to be incomplete.
1:是的,使用服务器特定信息创建 config.php 文件,并在需要时包含它。这是非常普遍和正常的。理想情况下,您可以将此文件与其他文件稍微分开,以便轻松获取所有应用程序文件并将它们复制到实时服务器,而无需复制配置文件。在某个地方保留实时配置文件的备份,因为有一天您会覆盖它,如果您不必费力去找出实时数据库密码是什么,这对您的心脏会好得多。
2:有一些自动化的方法可以处理这个问题,但它们非常复杂。我通常做的是创建一个名为changes.sql之类的空文本文件。当我对开发数据库进行更改时,我将 CREATE TABLE 和 ALTER TABLE 等查询粘贴到changes.sql 文件中。这样,当我准备更新实时站点时,我就拥有一个文件,其中包含我需要对实时服务器进行的所有更改。完成更新后,我将 Changes.sql 文件保存在某处,并为下一个更改创建一个新的空文件。
更多 2:您还可以转储整个开发数据库并实时复制它。不过,大多数网站在实时服务器上都有数据,这些数据不应被销毁或复制到开发人员中——用户信息、订单、登录跟踪、用户评论等。因此,您通常不想用开发数据替换所有实时数据。
1: Yes, create a config.php file with the server-specific information and include it when you need it. This is incredibly common and normal. Ideally, you can keep this file a little separate from your other files so that it's easy to grab all of your application files and copy them to the live server without also copying the config file. Keep a backup of your live config file somewhere, because one day you will overwrite it, and it's much better for your heart if you don't have to scramble to figure out what the live database password was.
2: There are some automated ways of handling this, but they're very complicated. What I usually do is create an empty text file named changes.sql or something. As I make changes to the dev database, I paste the CREATE TABLE and ALTER TABLE, etc. queries into the changes.sql file. This way I have one file with all the changes I need to make to the live server when I'm ready to update the live site. After I do the update, I save the changes.sql file somewhere and create a new empty file for the next changes.
More 2: You can also just do a dump of the whole dev database and copy it live. Most sites, though, have data on the live server that should not be destroyed or copied to dev - user information, orders, login tracking, user comments, whatever. So you generally do no not want to just replace all your live data with dev data.
我通常将模板内容与数据库连接、全局变量内容和会话内容分开,并使用“init.php”或“config.php”等包含文件。当您更新内容时,很可能不需要覆盖该文件。
我使用linux,所以我使用'mysqldump'来获取.sql文件,上传到服务器,然后只需上传'mysql -u user -p databasename
数据库.sql'。如果有一种我不知道的更快的方法,那就太好了。
I usually keep the template stuff separate from the db connection, global variable stuff, and session stuff with an include file like 'init.php' or 'config.php'. When you update your stuff, most likely you won't need to overwrite that file.
I use linux, so I use 'mysqldump' to get a .sql file, upload to server, then just upload 'mysql -u user -p databasename < database.sql'. It would be great if there was a quicker way that I don't know of.