在命令行中使用 XAMPP 导入 mysql DB

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6042133/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 19:55:18  来源:igfitidea点击:

Import mysql DB with XAMPP in command LINE

mysqlimportxampp

提问by Mamadou

I have this command:

我有这个命令:

mysql -u #myusername -p #mypasswd MYBASE < c:\user\folderss\myscript.sql

But I get the following error:

但我收到以下错误:

Error
unknow command '\U'
unknow command '\m'
unknow command '\D'
unknow command '\L'

回答by joelhaus

For those using a Windows OS, I was able to import a large mysqldump file into my local XAMPP installation using this command in cmd.exe:

对于使用 Windows 操作系统的用户,我可以使用以下命令将大型 mysqldump 文件导入到本地 XAMPP 安装中cmd.exe

C:\xampp\mysql\bin>mysql -u {DB_USER} -p {DB_NAME} < path/to/file/ab.sql

Also, I just wrote a more detailed answerto another question on MySQL imports, if this is what you're after.

另外,我刚刚写了一个关于 MySQL 导入的另一个问题的更详细的答案,如果这是你所追求的。

回答by bittu

Go to the xampp shell command line and run

转到 xampp shell 命令行并运行

mysql -h localhost -u username databasename < dump.sql

回答by Andreas Krueger

You may also need to specify the host. From your statement, it looks like you run on Windows. Try this:

您可能还需要指定主机。从您的陈述来看,您似乎在 Windows 上运行。尝试这个:

mysql -h localhost -u #myusername -p #mypasswd MYBASE
      < c:/user/folderss/myscript.sql

Or

或者

mysql -h localhost -u #myusername -p #mypasswd MYBASE
       < "c:\user\folderss\myscript.sql"

回答by niral

mysql -h localhost -u username databasename < dump.sql

It works, try it. If password is blank no need to add the -pargs.

它有效,试试吧。如果密码为空,则无需添加-p参数。

回答by matinict

Copy Database Dump File at (Windows PC) D:\xampp\mysql\bin

将数据库转储文件复制到 (Windows PC) D:\xampp\mysql\bin

mysql -h localhost -u root Databasename <@data11.sql

回答by Shonubi Korede

this command posted by Daniel works like charm

丹尼尔发布的这个命令就像魅力一样

C:\xampp\mysql\bin>mysql -u {DB_USER} -p {DB_NAME} < path/to/file/ab.sql

just put the db username and db name without those backets

只需将 db 用户名和 db 名称放在没有那些 backets 的情况下

**NOTE: Make sure your database file is reside inside the htdocs folder, else u'll get an Access denied error

**注意:确保您的数据库文件位于 htdocs 文件夹内,否则您将收到拒绝访问错误

回答by Ratikanta Sahoo

/opt/lampp/bin/./mysql -u dbusername -p dbname < sqlfilepath.sql

/opt/lampp/bin/./mysql -u dbusername -p dbname < sqlfilepath.sql

回答by Yusif Sadiyev

It works:

有用:

mysql -u root -p db_name < "C:\folder_name\db_name.sql"

C:\is for example

C:\例如

回答by user3172663

No Doubt It does the trick:

毫无疑问,它可以解决问题:

C:\xampp\mysql\bin>mysql -u {DB_USER} -p {DB_NAME} < path/to/file/ab.sql

But some time you many find "MySql Server has Gone a way" For that you need to change mysql/bin/my.inimax_allowed_packet = 64M to my.ini

但有时你会发现“MySql Server has Gone a way”为此你需要更改mysql/bin/my.inimax_allowed_packet = 64M to my.ini

回答by Pupil

I think the commands are OK, issue is with the spaces. Please observe the spaces between -u and #myusername also between -p and #mypasswd.

我认为命令没问题,问题在于空格。请注意 -u 和 #myusername 之间的空格以及 -p 和 #mypasswd 之间的空格。

mysql -u #myusername -p #mypasswd MYBASE < c:\user\folderss\myscript.sql

Can also be written as:

也可以写成:

mysql -u#myusername -p#mypasswd MYBASE < c:\user\folderss\myscript.sql

Also, you need not add -p and the time of command, if your password is blank, it will not ask you for the password. If you have password to your database, it will ask for the password.

另外,你不需要加上 -p 和命令的时间,如果你的密码为空,它不会要求你输入密码。如果您有数据库的密码,它会询问密码。

Thanks

谢谢