我有一个.sql文件,其中包含phpMyAdmin的导出。我想使用命令行将其导入到其他服务器。
我安装了Windows Server 2008 R2。我将.sql文件放在C驱动器上,并尝试了以下命令
database_name < file.sql
它不起作用。我遇到语法错误。
我如何才能毫无问题地导入此文件?我需要先创建数据库吗?
我有一个.sql文件,其中包含phpMyAdmin的导出。我想使用命令行将其导入到其他服务器。
我安装了Windows Server 2008 R2。我将.sql文件放在C驱动器上,并尝试了以下命令
database_name < file.sql
它不起作用。我遇到语法错误。
我如何才能毫无问题地导入此文件?我需要先创建数据库吗?
当前回答
对于Windows操作系统,可以使用以下命令从SQL转储导入数据。
C: \Program Files\MySQL\MySQL Server 5.7\bin>MySQL-u<>-p<>DBName<filelocation\query.sql
其中-u是用户名,-p是MySQL密码。然后输入密码并等待数据导入。
其他回答
导入数据库
转到驱动器:d:MySQL登录c: \xamp\mysql\bin\mysql-u root-p它将要求pwd。输入:压水堆选择数据库使用DbName;提供文件名\.DbName.sql
易于理解的只需在cmd中使用此命令:
use databasename
\. C:/test/data.mysql
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
如果在窗口上使用XAMPP,首先必须手动创建数据库,然后运行以下命令:
cd C:\xampp\mysql\bin &&
mysql -u YOUR_USERNAME -p YOUR_DATABASE_NAME < PATH_TO_YOUR_SQL_FILE\YOUR_SQL_FILE.sql
然后输入密码
您可以使用:
mysql -u<user> -p<pass> <db> < db.sql
例子:
mysql -uroot -proot db < db.sql