分类: Mysql/postgreSQL
2008-04-30 12:02:51
mysql 数据备份和恢复方法
mysqldump
备份整个数据库
mysqldump -u root -ppassword databasename >data.sql
备份某个或多个表
mysqldump -u root -ppassword databasename table1name table2name >data.sql
只备份数据结构
mysqldump -u root -ppassword databasename --no-data >data.sql
恢复
mysql -u root -ppassword --database=databasename
备份:/usr/local/mysql/bin/mysqldump --add-drop-table --all-databases --opt -f -uroot -pabc > /back/mysql-back.sql
tar czvf /back/mysql-back.tgz /back/mysql-back.sql//整个数据库
/usr/local/mysql/bin/mysqldump --add-drop-table --opt -f -uroot -p123 ywrc > /home/back/www/ywrc.sql
tar czvf /home/back/www/tar/ywrc-back.tgz /home/back/www/ywrc.sql//单个数据库
恢复mysql ywrc < ywrc.sql
%mysqldump samp_db >/usr/archives/mysql/samp_db.1999-10-02
%mysqldump samp_db | gzip >/usr/archives/mysql/samp_db.1999-10-02.gz
%mysqldump samp_db student score event absence >grapbook.sql
%mysqldump samp_db member president >hist-league.sql
%mysqladmin -h boa.snake.net create samp_db
%mysqldump samp_db | mysql -h boa.snake.net samp_db
%mysqldump --add-drop-table samp_db | mysql -h boa.snake.net samp_db
% ls -t -r -1 update.[0-9]* | xargs cat | mysql --one-database db_name
%mysql --one-database db_name < update.392
%mysql --one-database db_name < update.393