标签:
逻辑备份
mysqldump -uroot -paixocm sx > my.sql
mysqldump -uroot -paixocm sx -l > my.sql 备份时加锁
mysqldump -uroot -paixocm --databases ds sx > my.sql
mysqldump -uroot -paixocm --all-databases > my.sql
mysqldump -uroot -paixocm sx t1 t2 > my.sql
================================================================
备份单个数据库:mysqldump -uroot -p -B dbname > dbname.sql
备份全部数据库:mysqldump -uroot -p --all-databases > all.sql
备份表: mysqldump -uroot -p -B dbname --table tablename > tablename.sql
恢复数据库:mysql -uroot -p < name.sql
恢复表:mysql -uroot -p dbname < name.sql (必须指定数据库)
====================================================================
导入
mysqldump -uroot -paixocm sx < my.sql
mysql>source my.sql
物理备份
冷拷贝:先停掉服务(不适用于innodb引擎)
cp
热拷贝
mysqlhotcopy(只用于myisam引擎、只能在服务器端使用、自动加锁)
mysqlhotcopy -u root -p aixocm --socket=/var/run/mysqld/mysql5.socket ds /tmp/
导出
select * from t1 into outfile ‘/tmp/f1.txt‘ fields terminated by ‘,‘ enclosed by ‘"‘;
select * from t1 into outfile ‘/tmp/f1.txt‘ fields terminated by ‘,‘ optionally enclosed by ‘"‘;
mysqldump -uroot -paixocm -T /tmp sx t1 --fields-terminated-by "," --fields-optionally-enclosed-by ‘"‘
导入(表要存在)
load data
mysql>load data infile ‘/tmp/t1.txt‘ into table ds.t1 fields terminated by ‘,‘ enclosed by ‘"‘ ;
最后加 ignore 3 lines; 不要最前3行
最后加 (id, addr, name); 列的顺序
mysqlimport
mysqlimport -uroot --socket=/var/run/mysqld/mysql5.socket ds /tmp/t1.txt --fields-terminated-by "," --fields-optionally-enclosed-by ‘"‘
二进制
/mysql/bin/mysqlbinlog --database=fox --start-date="2013-01-22 5:00:00" --stop-date="2013-01-22 9:00:00" /mysql/data/mysql-bin.000001 | /mysql/bin/mysql -u root -p123456 -f
标签:
原文地址:http://www.cnblogs.com/wsl222000/p/4950409.html