我有一个.sql文件,其中包含phpMyAdmin的导出。我想使用命令行将其导入到其他服务器。
我安装了Windows Server 2008 R2。我将.sql文件放在C驱动器上,并尝试了以下命令
database_name < file.sql
它不起作用。我遇到语法错误。
我如何才能毫无问题地导入此文件?我需要先创建数据库吗?
我有一个.sql文件,其中包含phpMyAdmin的导出。我想使用命令行将其导入到其他服务器。
我安装了Windows Server 2008 R2。我将.sql文件放在C驱动器上,并尝试了以下命令
database_name < file.sql
它不起作用。我遇到语法错误。
我如何才能毫无问题地导入此文件?我需要先创建数据库吗?
当前回答
Use:
mysql -u root -p password -D database_name << import.sql
有关详细信息,请使用MySQL帮助-MySQL-help。
我认为在我们的背景下,这些将是有用的选择:
[~]$ mysql --help
mysql Ver 14.14 Distrib 5.7.20, for osx10.12 (x86_64) using EditLine wrapper
Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.
Usage: mysql [OPTIONS] [database]
-?, --help Display this help and exit.
-I, --help Synonym for -?
--bind-address=name IP address to bind to.
-D, --database=name Database to use.
--delimiter=name Delimiter to be used.
--default-character-set=name Set the default character set.
-f, --force Continue even if we get an SQL error.
-p, --password[=name] Password to use when connecting to server.
-h, --host=name Connect to host.
-P, --port=# Port number to use for connection or 0 for default to, in order of preference, my.cnf, $MYSQL_TCP_PORT, /etc/services, built-in default (3306).
--protocol=name The protocol to use for connection (tcp, socket, pipe,
-s, --silent Be more silent. Print results with a tab as separator, each row on new line.
-v, --verbose Write more. (-v -v -v gives the table output format).
-V, --version Output version information and exit.
-w, --wait Wait and retry if connection is down.
如果我们正在导入一个大型数据库,而没有进度条,那有什么好玩的呢。使用管道查看器并查看通过管道传输的数据
对于Mac,brew install pv
对于Debian/Uuntu,apt-get-install-pv。
有关其他信息,请参阅pv-管道查看器
pv import.sql | mysql -u root -p password -D database_name
1.45GiB 1:50:07 [339.0KiB/s] [=============> ] 14% ETA 11:09:36
1.46GiB 1:50:14 [ 246KiB/s] [=============> ] 14% ETA 11:09:15
1.47GiB 1:53:00 [ 385KiB/s] [=============> ] 14% ETA 11:05:36
其他回答
mysqldump的一个常见用法是备份整个数据库:
mysqldump db_name > backup-file.sql
您可以像这样将转储文件加载回服务器:
Unix
mysql db_name < backup-file.sql
在Windows命令提示符中相同:
mysql -p -u [user] [database] < backup-file.sql
PowerShell(PowerShell)
cmd.exe /c "mysql -u root -p db_name < backup-file.sql"
MySQL命令行
mysql> use db_name;
mysql> source backup-file.sql;
Use:
mysql -u root -p password -D database_name << import.sql
有关详细信息,请使用MySQL帮助-MySQL-help。
我认为在我们的背景下,这些将是有用的选择:
[~]$ mysql --help
mysql Ver 14.14 Distrib 5.7.20, for osx10.12 (x86_64) using EditLine wrapper
Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.
Usage: mysql [OPTIONS] [database]
-?, --help Display this help and exit.
-I, --help Synonym for -?
--bind-address=name IP address to bind to.
-D, --database=name Database to use.
--delimiter=name Delimiter to be used.
--default-character-set=name Set the default character set.
-f, --force Continue even if we get an SQL error.
-p, --password[=name] Password to use when connecting to server.
-h, --host=name Connect to host.
-P, --port=# Port number to use for connection or 0 for default to, in order of preference, my.cnf, $MYSQL_TCP_PORT, /etc/services, built-in default (3306).
--protocol=name The protocol to use for connection (tcp, socket, pipe,
-s, --silent Be more silent. Print results with a tab as separator, each row on new line.
-v, --verbose Write more. (-v -v -v gives the table output format).
-V, --version Output version information and exit.
-w, --wait Wait and retry if connection is down.
如果我们正在导入一个大型数据库,而没有进度条,那有什么好玩的呢。使用管道查看器并查看通过管道传输的数据
对于Mac,brew install pv
对于Debian/Uuntu,apt-get-install-pv。
有关其他信息,请参阅pv-管道查看器
pv import.sql | mysql -u root -p password -D database_name
1.45GiB 1:50:07 [339.0KiB/s] [=============> ] 14% ETA 11:09:36
1.46GiB 1:50:14 [ 246KiB/s] [=============> ] 14% ETA 11:09:15
1.47GiB 1:53:00 [ 385KiB/s] [=============> ] 14% ETA 11:05:36
导入到架构的最简单方法:
登录mysql并发出以下提到的命令。
mysql> use your_db_name;
mysql> source /opt/file.sql;
打开MySQL命令行键入mysql bin目录的路径,然后按Enter键将SQL文件粘贴到mysql服务器的bin文件夹中。在MySQL中创建数据库。使用要导入SQL文件的特定数据库。键入source databasefilename.sql并输入SQL文件上载成功。
试试看:
cd C:\xampp\mysql\bin
mysql -u root -p database_name --force < C:\file.sql