Home > Database > Mysql Tutorial > body text

Linux 环境 MySQL 备份各种方法

WBOY
Release: 2016-06-07 17:04:35
Original
1086 people have browsed it

注意这里是Ubuntu 11.04版本MySQL 5.1 。Windows下的估计有区别。。自己研究去吧!!1.登录MySQL后用BACKUP、RESTORE命令不推荐使

注意这里是Ubuntu 11.04版本MySQL 5.1 。Windows下的估计有区别。。自己研究去吧!!

1.登录MySQL后用BACKUP、RESTORE命令不推荐使用,后面的版本可能会移除。。所以还是别用了!

2。用mysqldump命令备份。假设在firstdb下有个test 表。则运行

mysqldump -uUERNAME -pPASSWORD -hHOSTNAME firstdb test > test.sql

登录后mysql后运行:drop table test ;

现在恢复 : mysql -uUSRNAME -pPASSWORD -hHOSTNAME firstdb

这样原来的test就恢复了。。

当然mysqldump很多参数。。自己man去吧!

3、用select into 做备份

登录mysql后运行:select * from test into outfile "test.dat";

清空表:truncate test ;

恢复可以: load data infile "test.dat" into table test ;

当然还可以用mysqlimport命令代替load data 。。在bash下运行:

mysqlimport  -uUSERNAME -pPASSWROD -hHOSTNAME firstdb test.dat ;

这样就可以恢复了。。

不过注意在linux下的权限问题。。这个不解释。。mysql的权限管理用户是一个系统用户--mysql,具体查看相关linux 权限的书籍!

4.利用mysqlhotcopy命令

用法和mysqlimport类似。。这是一个perl脚本。。查看help就会用了。。

5.使用二进制更新的日志文件恢复数据到最近位置。

这个要求打开log-bin选项,在/etc/mysql/my.cnf 下设置。。利用正则表达式很容易就可以找到log-bin选项,,把注释去了就可以了。当然也可以自己加上。

然后利用mysqlbinlog  XXXX-bin.XXX 就可以恢复了。。默认应该是放在/var/log/mysql 。。自己利用find命令找。。

6最后一种方法不多说。。直接把整个数据库拷贝。。。利用cp 命令复制到其他目录或文件系统。。恢复也容易。。。

linux

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!