Question:
How to take a database backup for mysql in linux environment?
Sam
2008-05-19 02:00:13 UTC
i need code or any suggestions to take my project database backup in to any hard drive
Three answers:
anonymous
2008-05-20 14:52:50 UTC
Do a mysql dump



For example



mysqldump -u root -p (database_name) > database.sql



This will generate sql source which can be read back to recreate your database.
anonymous
2008-05-19 09:12:38 UTC
well there are two ways that are preferable u can

mysqldump --all-databases -p > /path/to/location.sql

don't forget the .sql



or u can mysqlhotcopy

which has similar syntax but uses the --user= --password= argument format



mysqldump is better for innobd tables which are transactional

as a pose to the mysql default storage engine myisam which are non transactional tables u would use mysqlhotcopy for those

if u use the bash shell which u should =)

u can just mysq and tab over to see all the tools that come with mysql



now optimally u should use those tools but in the case of myisam tables u can CP and tar them like any other files as u should know the mysql database file are in

/var/lib/db/mysql

and if u were to have the databases help and me they would be like this

/var/lib/db/mysql/help

&

/var/lib/db/mysql/me

u just copy the .MYI .MDB and .frm files and u should be good

ofcourse they should be owned by mysql user

chown mysql.mysql *

and when u restore the files in this method they just appear in the mysql shell

when u restore from dump file u should get a query OK status message

sometimes the db's are in usr/local/

but u can just grep ps -aux for mysql to get the location of the DB files

so thats 3 ways to get a mysql back up



mysqldump is nice because it recreates every command that it takes to make ur DB,,, and when u restore from this it runs these commands and recreates the DB structure



mysqlhotcopy merges files with whats in memory so u can run it while the db is running,, u run mysqldump while db is running but the backup isn't as intelligent,,, somehow i always liked mysqldump its easier =)



i don't suggest copying the files without shutting down the DB either can corrupt dataZ mysqldump and hotcopy work on a live DB

and the dump format will be truly protable as it will use the type of sql statements most DB's use,, also it can be dumped in XML format and Comma delimeted text if u choose making it more portable
anonymous
2008-05-19 09:13:13 UTC
If you are running Linux you can use the scp command to securely copy the whole of your mysql folder from the server to your own machine. Alternatively you may be able to copy the database from its' folder to your server FTP folder and then download it by FTP.


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...