Re: Copy mySQL database...

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



At 08:52 AM 2/3/2005, you wrote:

I just need to make a duplicate copy of a mySQL database (I have to
reinstall some web software and I am afraid it will overwrite the existing
database, so i would like to make a backup of it)...

Any classes, scripts, etc out there to do this?

This is more of a question for the mysql mailing list unless you MUST use PHP to do it. In that case, I would suggest phpmyadmin....just my preference.
Besides mysqldump and a few other things. You can also just copy the directory to a new directory if you have root access. Just make sure that you keep the same permissions.
cd /var/lib/mysql (assuming this is where your databases are)
mkdir backuptest (this would be the name of the new directory)
cp -pr test/* backuptest (this would copy the database "test" to the new directory you just created)


It would be a good idea to stop the database first then do a myisamchk.
myisamchk --silent --force --fast --update-state -O key_buffer=64M \
        -O sort_buffer=64M -O read_buffer=1M -O write_buffer=1M \
        /var/lib/mysql/*/*.MYI

Those "\" backslash characters are to tell you that the command is all one line (without the backslashes).
After you have done all of this, then restart the database. If you are moving to a new machine with the data, then you can either use the mysqldump of the database or tar/gzip up the directory before you restart mysqld and untar/ungzip it onto the new machine. I am not going to guarantee that the last method will always work for you, but I have done it in the past from linux to linux, linux to windows and windows to linux with no problem. If you are moving it to a new server, you will need to make sure to setup the access permissions again in the mysql database. Also, you can use the backuptest database by doing the same thing if you are not root and root doesn't have full privileges on every database. Strange, but I have seen a setup like that.


Steve

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux