How do I have Wordpress keep its database in the same directory as other files (for sharing via Dropbox)?

0

1

I am working on a Wordpress site with another person. At the moment the Wordpress files are on a shared Dropbox folder, which allows both of us to see all the files we need to work on. However, Wordpress databases are not there, I've created them on my PC but the other person cannot see them.

Is there a standard, simple way to have Wordpress keep its database files in the same directory where all the other files are stored?

user1301428

Posted 2013-03-13T21:55:07.997

Reputation: 2 985

3What database are you using for WordPress? Unless you use something like a SQLite database, you will not be able to sync it. MySQL will never sync. – TFM – 2013-03-16T13:10:16.917

Are you talking about whole WordPress installation or backed up archived databases? I know that if you want others to collaborate, you would have to invite them by typing in their emails. This is done through Dropbox web interface. – Boris_yo – 2013-03-16T13:21:56.393

@TFM MySQL, I would like to have my local databases on Dropbox together with all the other Wordpress files – user1301428 – 2013-03-16T21:12:14.533

@Boris_yo I would like to have the whole Wordpress installation on Dropbox, databases included – user1301428 – 2013-03-16T21:12:55.983

1Sorry, but this is not a good idea and is just not going to work the way you want it to. In particular, I'm afraid it's quite impossible with MySQL. You'd be better served setting up a server or a cheap shared web hosting account somewhere to host your site in development (or at least the MySQL server). – tgies – 2013-03-20T07:46:49.607

@tgies I didn't think that changing the path to my MySQL databases would be so difficult... – user1301428 – 2013-03-20T09:52:55.617

1@user1301428 That's not the difficult part. The issue is that it's a Dropbox folder. Dropbox is going to go absolutely crazy and thrash around trying to keep the file in sync, and if you ever try to access the database at the same time as the other user, you're going to have concurrency issues. – tgies – 2013-03-20T13:50:16.233

Answers

1

As I said in the comments, you really don't want to do this and I doubt it's going to work that well. You should really look into hosting an Internet-accessible MySQL server on a dedicated server/VPS, or on your or your collaborator's development machine. And if you do this, you need to be sure at the very least that only one of you has the database loaded at a time; I don't know how well Dropbox would handle syncing a bunch of concurrent updates to a database but my gut tells me it'd end in disaster.

That said, here is how you can tell MySQL to keep database files in an arbitrary directory, in this case your Dropbox shared directory.

You need to locate MySQL's configuration file. This is called my.cnf on most platforms, my.ini on Windows. To locate that file, see the answers here.

Having found the configuration file, open it and find a line starting with datadir. This is where your databases are now. Navigate to that directory and copy its contents to a new folder on your Dropbox. Now, change the datadir directive to refer to the path to your Dropbox, and restart MySQL.

tgies

Posted 2013-03-13T21:55:07.997

Reputation: 995

Concurrency is not an issue, we would work on the database one at the time. What about setting up a local virtualized web server? – user1301428 – 2013-03-22T11:09:11.530

Setting up a shared development web and MySQL server would be the way to go. – tgies – 2013-03-22T13:57:26.203

2

You don't want to store the live database files in Wordpress, as recovering them will provide all sorts of grief and provide a false level of security. (For a number of reasons including that MySQL is not ACID compliant, the probable performance hit and because databases are not closed when making this backup, and recovery is harder even if you can get the data)

You would be better off - from a reliability, stability and recoverability point of view to back up the database using a cronjob to regularly do database dumps to your Dropbox folder. Thats what programs like MYSQLDUMP are there for (and they are part of the MySQL package - not an aftermarket add-on) You can schedule these dumps using CRONTAB.

For sharing access to the database, the correct behaviour is to set the database up on a port which can be connected too by both developers simultaneously. The whole point of databases is to abstract storage from code - so that multiple people can act on the data [more-or-less] simultaneously.

davidgo

Posted 2013-03-13T21:55:07.997

Reputation: 49 152

But if I set up the database on a port, the database itself must be on a web server to be always accessible I guess. So why shouldn't Dropbox be a good solution? – user1301428 – 2013-03-22T11:07:23.273

1I guess you want to use a local mysql installation on both machines, using the mysql data from dropbox? On machine A something changes table X, and table Y depends on that table. This is not synced immediately, but takes some time. At the same time, machine B uses the same table. It changes something that is synced a little later, something that corrupts table Y on machine A. – SPRBRN – 2013-03-22T15:48:02.863

1The database speaks a totally different language to a web server, and is an application with a defined set of interfaces designed to handle concurrent writes etc, not a simple file. Dropbox is not a solution because it does not run the application. The database does need to be always accessible, but does not need to be (and in large installations almost never is) on a web server. – davidgo – 2013-03-22T19:03:19.533

2

I am not going to suggest you that its not good to treat databases like files when you need to work on it. Assuming, you know what you are doing, just locate datadir key ([mysqld] section) in my.cnf or my.ini (use mysqld --help --verbose to get location info) and change its value to Wordpress directory. Restart MySQL server. Done! You don't need to touch Wordpress configuration at all.

Apple II

Posted 2013-03-13T21:55:07.997

Reputation: 3 669

It's a development scenario! Who cares about what's safe? Worst possible outcome here is that the OP learns not to run several instances of mysqld on the same back-end files. – Ярослав Рахматуллин – 2013-03-23T09:27:58.863

1

You might want to look at alternative solutions.

First, dropbox is a decent way to share files, but at best would be for one person sharing across multiple locations. I don't even know where to begin with the conflicts that you're going to run into trying to use dropbox as your source management system. Look into git or svn. svn is pretty user friendly with tortoise on windows, and there are places that offer free repos.

As for mysql, trust people here when they say you don't want to do this. You will trash your data, and quickly put it in an inoperable state. Since your using dropbox, reverting back to a operable state will be extremely difficult or impossible, depending on how well you did backups and timed them.

Your going to host the website somewhere, no? Don't they provide a mysql db for you to use? If so, you should check and see if you can expose ports for remote managing it, or just manage it through the hosts phpmySQL interface. Unless your making structure changes, you probably don't need to be in deep with the database anyways. You say that you have the DB on your machine but your friend can't access it, maybe you can open a port for him?

Finally, even if you did get the files to sync without trashing your data, he's still going to have to setup a MySQL instance on his side to do something with the datafiles. MySQL consists of two parts, the software and the data, you can't just dump the data into dropbox (or any sharing method) and have it be available to someone else who has access to the datafiles. If I'm mistaken and he does have mysql server configured, why can't he just install his own set of tables?

Mike

Posted 2013-03-13T21:55:07.997

Reputation: 111

"why can't he just install his own set of tables?" He could, and he could import them every time there is an update I guess. I was just looking for a completely automatic solution. – user1301428 – 2013-03-23T08:33:28.077