![]() |
MySQL grant tables - how can I import them from another DB?
I'm setting up a new MySQL instance intended to replace a previous one. Both are version 5.1 running on Ubuntu. Nothing is to be changed except which host they are running on.
I believe, in theory, I could simply shut down the old one (briefly), copy all the files to the new one, and start both, and this would include the grant tables, and everything else. And if I don't see an alternative, this is what I will do. I do make a full backups using "mysqldump --all-databases" 3 times a day and send them over to backup servers. So I have the data. But I don't see any grant tables in this. So if I create new grant tables on the new server, they won't be a replica of what the old server has ... and importing the backup data won't make the grant tables be that way, either, since the grant tables aren't (apparently) in this data. FYI, I'm also now concerned I don't have a backup of the grant tables. Is there a "proper" way to replicate/import the grant tables from one server to another? Are they in a separate file I could just copy (during a database shutdown to be sure all is in sync)? |
Are you talking about the db table in the mysql data base? That plus the user table in mysql pretty much has what you need, methinks.
Hope this helps some. |
Quote:
|
I went ahead and shutdown MySQL and rsync'd everything to the new server. It was down for only about 20 seconds to let rsync copy all the data out. Once I got apparmor updated (forgot to do that for the first couple of tries to start MySQL on the new server) on the new server it worked. The apparmor change was because everything in /var/lib/mysql had been moved to /home/mysql (on both old and new). The new site seems to be running fine (just not yet live to the world).
|
Sounds like you got there.
The mysql data base has the login, password and data base permissions in the table user; you can unload that table and load it into a new data base to set up your users (watch for the first column, host, though). If you do that in a text file, you can edit the host column manually with, oh, vi or whatever ails ya. The other table, db, is where permission go when you grant. Similarly, you can unload that to a text file, edit the host column if necessary, then load it into the mysql data base. You may want to take a look-see at the host column in both of those tables and change the name (or address) if needed from the old box to the new box (assuming that your site is accessing MySQL via a network connection -- localhost should work just fine without any fiddling around). You can do the change with a simple SQL "update table" statement. Hope this helps some. |
Quote:
|
What I have done when I've moved a database from one instance of MySQL to another (my blog database) is this:
If you are doing this in a situation in which the database will be used in conjunction with php, you may have to increase the upload and import limits in php.ini. By default they are set to 8MB. |
There is, near the bottom of the mysqldump manual page a section (this looks like what you want to do):
Code:
mysqldump is also very useful for populating databases by copying data from one Code:
create database if not exists bugs; Doing this grant.sql thing turns out to be the easiest way I've found to deal with the (slight) goofiness of MySQL (because the users and permission don't go with the individual data bases but are kept in the mysql data base). It's not that difficult to keep it up-to-date; when I add a new user I simply add a couple of lines to that file then run it Code:
mysql --user=mysql --password='mysqlpassword' mysql < grant.sql Anyway, glad to know you got going. Hope this helps some. |
I went ahead and marked this thread SOLVED so others could find these suggestions. I ended up shutting the servers down (to get clean states) and replicating the entire file tree for MySQL to the new server. So I didn't get a chance to actually test these.
|
All times are GMT -5. The time now is 09:13 PM. |