使用 mysqldump.exe 将 mysql 数据库从本地主机复制到远程服务器

发布于 2024-09-01 05:58:39 字数 412 浏览 8 评论 0原文

我想将 mysql 数据库从本地计算机复制到远程服务器。

我正在尝试使用 mysql dump 命令。互联网上的所有示例都建议执行类似的操作。

初始 mysql> 只是我登录后得到的提示。

mysql> mysqldump -u user -p pass myDBName | NewDBName.out;

但是当我这样做时,我得到You have an error in your SQL语法;检查对应的手册...以在'mysqldump -u user -p pass myDBName | 附近使用NewDBName.out'

由于我已经登录,是否需要使用 -u 和 -p?不这样做会给我同样的错误。你能看出哪里出了问题吗?

I want to copy a mysql database from my local computer to a remote server.

I am trying to use the mysql dump command. All the examples on the internet suggest doing something like

The initial mysql> is just the prompt I get after logging in.

mysql> mysqldump -u user -p pass myDBName | NewDBName.out;

But when I do this I get You have an error in your SQL syntax; check the manual that corresponds ... to use near 'mysqldump -u user -p pass myDBName | NewDBName.out'

Since I have already logged in do I need to use -u and -p? Not doing so gives me the same error. Can you see what is wrong?

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

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

发布评论

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

评论(3

握住我的手 2024-09-08 05:58:39

除了 Alexandre 所说的之外,您可能不想通过管道 (|) 输出到 NewDBName.out,而是将其重定向到那里 (>)。

因此,从 Windows/Unix 命令行:

mysqldump -u user -p pass myDBName > NewDBName.out

请注意,如果某些列中有较大的二进制字段(例如 BLOBS),您可能需要设置一个附加选项(我认为它是 --hex-blob,但可能还有另一个选项)也)。如果这适用于您,请添加评论,我将研究该设置。

In addition to what Alexandre said, you probably don't want to pipe (|) output to NewDBName.out, but rather redirect it there (>).

So from the Windows/Unix command line:

mysqldump -u user -p pass myDBName > NewDBName.out

Note that if you have large binary fields (e.g. BLOBS) in some columns you may need to set an additional option (I think it was --hex-blob, but there might have been another option too). If that applies to you, add a comment and I'll research the setting.

等待我真够勒 2024-09-08 05:58:39

mysqldump 不是您在 mysql 会话中执行的 SQL 语句,而是应该从操作系统 shell 启动的不同二进制文件。

有几种使用它的方法。其中之一是将 mysqldump 的输出通过管道传输到另一个 MySQL 实例:

echo CREATE DATABASE remote_db | mysql -h remote_host -u remote_user -premote_password
mysqldump -h source_host -u root -ppassword source_db | mysql -h remote_host -u remote_user -premote_password -D remote_db

mysqldump is not an SQL statement that you execute inside a mysql session but a distinct binary that should be started from your OS shell.

The are a few ways to use this. One of them is to pipe the output of mysqldump to another MySQL instance:

echo CREATE DATABASE remote_db | mysql -h remote_host -u remote_user -premote_password
mysqldump -h source_host -u root -ppassword source_db | mysql -h remote_host -u remote_user -premote_password -D remote_db
-黛色若梦 2024-09-08 05:58:39

我最近不得不转储大量数据。我在一个 200Mb 的数据库中发现,许多表中有 10,000 多条记录,如下所示。我使用 linux 'time' 命令来获取实际时间。

12 分钟使用:
mysqldump -u 用户 -p pass myDBName > db-backups.sql

7分钟克隆数据库:
mysqldump -u 用户 -p 传递 myDBName | mysql -u user -p pass cloneDBName

在不到一秒的时间内:
mysqlhotcopy -u user -p pass myDBName cloneDBName

最后一个让我大吃一惊,但是您必须在数据库服务器所在的本地登录。我个人认为这比远程转储要快得多,您可以压缩 .sql 文件并手动传输它。

I have had to dump large sets of data recently. From what I have found on a 200Mb database with 10,000+ records in many of the tables is the following. I used the linux 'time' command to get actual time.

12 minutes using:
mysqldump -u user -p pass myDBName > db-backups.sql

7 minutes to clone the database:
mysqldump -u user -p pass myDBName | mysql -u user -p pass cloneDBName

And in less than a second:
mysqlhotcopy -u user -p pass myDBName cloneDBName

The last one blew my mind, but you have to be logged in locally where the database server resides. Personally I think this is much faster than remotely doing a dump, the you can compress the .sql file and transfer it manually.

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