如何最好地优化备份 MySQL 数据库的方式?

发布于 2024-11-25 12:54:00 字数 569 浏览 1 评论 0原文

我有几个网站托管在 VPS 上,目前正在通过 cron 运行 shell 脚本来执行数据库备份,如下所示:

mysqldump -uusername1 -prootpassword dbname1 > /backup/dbname1.bak
mysqldump -uusername2 -prootpassword dbname2 > /backup/dbname2.bak
mysqldump -uusername3 -prootpassword dbname3 > /backup/dbname3.bak

我对此过程有一些担忧。

首先,我使用根服务器密码来执行 mysqldump,并且该文件以明文形式存储在服务器上(不可公开访问或任何其他内容,但如果我出于某种原因授予其他用户访问服务器的权限,显然会出现问题或其他)。我使用 root 是因为它比跟踪创建数据库的每个人并询问他们特定的数据库密码更简单。

其次,只有当人们告诉我他们已经添加了一个数据库时,这个过程才有效(这在大多数情况下都很好,我们在这里没有做任何超级复杂的事情)。我更愿意备份所有内容,而不必担心我忽略了某些内容。

I have several websites hosted on a VPS and am currently performing database backups by running a shell script via cron that looks something like this:

mysqldump -uusername1 -prootpassword dbname1 > /backup/dbname1.bak
mysqldump -uusername2 -prootpassword dbname2 > /backup/dbname2.bak
mysqldump -uusername3 -prootpassword dbname3 > /backup/dbname3.bak

I have a couple of concerns about this process.

Firstly, I'm using the root server password to perform mysqldump, and the file is being stored in clear text on the server (not publicly accessible or anything, but there are obviously concerns if I grant other users access to the server for one reason or another). I'm using root because it's simpler than tracking everybody that creates a database down and asking them for their specific db passwords.

Secondly, this process only works if people inform me that they've added a database (which is fine for the most part, we're not doing anything super complicated over here). I would prefer to have a backup of everything without worrying that I've overlooked something.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

夏雨凉 2024-12-02 12:54:00

您始终可以转储所有数据库:

mysqldump --all-databases | gzip -9 > /backup/dbs.bak.gz

这样您就不必跟踪有哪些数据库。缺点是恢复变得有点复杂。

至于使用 root,您没有理由不能创建另一个有权进行备份的帐户 - 除了初始设置之外,您不应该使用 root 帐户进行任何其他操作。

You could always just dump ALL the databases:

mysqldump --all-databases | gzip -9 > /backup/dbs.bak.gz

That'd free you from having to keep track of which dbs there are. The downside is that restoring gets a bit more complicated.

As for using root, there's no reason you couldn't create another account that has permissions to do backups - you should never use the root account for anything other than initial setup.

雨后咖啡店 2024-12-02 12:54:00

我使用这个脚本: http://sourceforge.net/projects/automysqlbackup/ 它工作得很好。此外,您还应该添加一个具有全局 SELECT 和 LOCK TABLES 权限的备份 MySQL 用户。这样你就不需要每个人的用户名和密码/

I use this script: http://sourceforge.net/projects/automysqlbackup/ It works perfectly. Also, you should add a backup MySQL user that has global SELECT and LOCK TABLES permissions. That way you don't need everyone's username and password/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文