1 |
Michael Sullivan wrote: |
2 |
|
3 |
>> Why bother? User accounts are stored in the db. Just move the whole thing. |
4 |
>> |
5 |
>> /etc/inti.d/mysql stop |
6 |
>> rsync -av --delete /var/lib/mysql/ newbox01:/var/lib/mysql/ |
7 |
>> |
8 |
> And this method will preserve all granted permissions with their |
9 |
> passwords? That would be great! |
10 |
|
11 |
Moving the entire Mysql database store is very simple. Mysql puts all |
12 |
data in /var/lib/mysql by default under Gentoo. You can even go in there |
13 |
and poke around to see all the databases in individual directories. |
14 |
Assuming you're using Mysql 5.0.26 on both databases with similar |
15 |
my.conf files you should have no problems just rsync-ing the directory |
16 |
and then starting Mysql on the new server. You can run into issues with |
17 |
Innodb if data files are different sizes on each server. That's the |
18 |
usual gotcha since Gentoo has changed it a few times between releases. |
19 |
|
20 |
>> Or you can dump the mysql table and just copy the sql lines that you |
21 |
>> care about if you're moving databases individually. |
22 |
>> |
23 |
>> mysqldump -u root -p --skip-opt --databases mysql > mysql-db-20070436.sql |
24 |
>> |
25 |
>> Then cut and paste any access lines from db and user into the new db. |
26 |
> |
27 |
> How do I get those? |
28 |
|
29 |
All passwords, account privileges, etc are stored in the mysql db within |
30 |
Mysql. Notice the distinction there. All Mysql databases store user, |
31 |
access, etc in a db called mysql. On disk that would be in |
32 |
/var/lib/mysql/mysql/ and through command line you can see the data by |
33 |
doing: |
34 |
|
35 |
mysql -u root -p |
36 |
use mysql; |
37 |
select * from db; |
38 |
select * from user; |
39 |
|
40 |
So if you wanted to pull things out without thinking too much you can |
41 |
just dump the mysql database with all the user accounts out into a text |
42 |
file and then import only the parts you care about. Here some sample |
43 |
data from one of my servers. |
44 |
|
45 |
-- |
46 |
-- Dumping data for table `db` |
47 |
-- |
48 |
|
49 |
INSERT INTO `db` VALUES |
50 |
('localhost','sqlgrey','sqlgrey','Y','Y','Y','Y','Y','Y','N','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y'); |
51 |
INSERT INTO `db` VALUES |
52 |
('localhost','postfix','postfixadmin','Y','Y','Y','Y','Y','N','N','N','N','N','N','N','N','N','N','N','N' |
53 |
); |
54 |
|
55 |
|
56 |
-- |
57 |
-- Dumping data for table `user` |
58 |
-- |
59 |
|
60 |
INSERT INTO `user` VALUES |
61 |
('localhost','sqlgrey','12231231313131231231312313123123131231C','N','N','N','N','N','N','N','N','N |
62 |
','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','','','','',0,0,0,0); |
63 |
INSERT INTO `user` VALUES |
64 |
('localhost','postfixadmin','1312312312312333432423131231312313123131','N','N','N','N','N','N','N','N','N |
65 |
','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','','','','',0,0,0,0); |
66 |
|
67 |
So in these examples mysql.user defines the user accounts and mysql.db |
68 |
defines the accounts and what access they are allowed per database. The |
69 |
big hash is the MD5 password. You can log into your new Mysql instance, |
70 |
use mysql, and then paste the above lines in to add the some access. |
71 |
|
72 |
Additionally you can dump just the whole mysql db and import it from |
73 |
the old db to the new db. |
74 |
|
75 |
mysqldump -u root -p --databases mysql > mysqldb-20070426.sql |
76 |
|
77 |
on the new server |
78 |
mysql -u root -p |
79 |
drop database mysql; |
80 |
exit; (do not restart Mysql at this point or you'll be locked out) |
81 |
mysql -u root -p < mysqldb-20070426.sql |
82 |
mysql -u root -p |
83 |
flush privileges; (this will load the new mysql you imported) |
84 |
exit; |
85 |
|
86 |
kashani |
87 |
-- |
88 |
gentoo-user@g.o mailing list |