是否可以使用PHP备份SQL而不依赖?如果没有,哪个最好?

时间:2022-03-31 22:43:31

After a huge MySQL blunder on a production server (my fault, and yes I have learned), I am now looking at creating a dump of the MySQL database before I do a critical operation (about 15 queries to the db, insert/update/selects). I know phpMyAdmin can 'dump' the database to SQL queries, but I think this may be a feature of it, not a feature of MySQL?

在生产服务器上出现巨大的MySQL错误之后(我的错,并且我已经学会了),我现在正在考虑在执行关键操作之前创建MySQL数据库的转储(对数据库进行大约15次查询,插入/更新/选择)。我知道phpMyAdmin可以“转储”数据库到SQL查询,但我认为这可能是它的一个特性,而不是MySQL的一个特性?

So, is there a way to do this using MySQL, and if not (which I suspect), what would be the best way to dump the db to a file on the server on command? Preferably as a tarball of the whole DB in ready to import SQL format.

那么,有没有办法使用MySQL来做到这一点,如果没有(我怀疑),在命令上将db转储到服务器上的文件的最佳方法是什么?最好作为整个DB的tarball准备导入SQL格式。

Thank You!

4 个解决方案

#1


You are looking for the mysqldump function, I believe:

您正在寻找mysqldump函数,我相信:

mysqldump my_database > database.dump

#2


MySQL dump will do it, and you can pipe it to gzip so it stores better:

MySQL转储会做到这一点,你可以将它管道到gzip,以便更好地存储:

mysqldump --opt -Q -h[server] -u[username] -p[password] [dbname] | gzip > [file].sql.gz

And to restore you unzip it and:

并恢复你解压缩它:

mysql -h[server] -u[username] -p[password] [dbname] < [file].sql

#3


I've used this for a few years now, why re-create the wheel :)

我已经用了几年了,为什么要重新制作*:)

http://worldcommunity.com/opensource

#4


Another good route is to use something like sqlyog to automate backups. I run this on a local Windows machine I have to do backups of all my remote servers.

另一个好方法是使用sqlyog之类的东西来自动备份。我在本地Windows机器上运行它,我必须备份所有远程服务器。

#1


You are looking for the mysqldump function, I believe:

您正在寻找mysqldump函数,我相信:

mysqldump my_database > database.dump

#2


MySQL dump will do it, and you can pipe it to gzip so it stores better:

MySQL转储会做到这一点,你可以将它管道到gzip,以便更好地存储:

mysqldump --opt -Q -h[server] -u[username] -p[password] [dbname] | gzip > [file].sql.gz

And to restore you unzip it and:

并恢复你解压缩它:

mysql -h[server] -u[username] -p[password] [dbname] < [file].sql

#3


I've used this for a few years now, why re-create the wheel :)

我已经用了几年了,为什么要重新制作*:)

http://worldcommunity.com/opensource

#4


Another good route is to use something like sqlyog to automate backups. I run this on a local Windows machine I have to do backups of all my remote servers.

另一个好方法是使用sqlyog之类的东西来自动备份。我在本地Windows机器上运行它,我必须备份所有远程服务器。