在命令行中使用 XAMPP 导入 mysql 数据库
我有这个命令:
mysql -u #myusername -p #mypasswd MYBASE < c:\user\folderss\myscript.sql
但我收到以下错误:
Error
unknow command '\U'
unknow command '\m'
unknow command '\D'
unknow command '\L'
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(17)
对于那些使用 Windows 操作系统的用户,我可以使用
cmd.exe
中的此命令将大型 mysqldump 文件导入到本地 XAMPP 安装中:此外,我刚刚编写了一个 关于 MySQL 导入的另一个问题的更详细答案(如果这就是您所追求的)。
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
:Also, I just wrote a more detailed answer to another question on MySQL imports, if this is what you're after.
转到 xampp shell 命令行
并运行
Go to the xampp shell command line
and run
您可能还需要指定主机。从你的说法来看,你是在 Windows 上运行的。试试这个:
或者
You may also need to specify the host. From your statement, it looks like you run on Windows. Try this:
Or
有效,尝试一下。
如果密码为空,则无需添加
-p
参数。It works, try it.
If password is blank no need to add the
-p
args./opt/lampp/bin/./mysql -u dbusername -p dbname < sql文件路径.sql
/opt/lampp/bin/./mysql -u dbusername -p dbname < sqlfilepath.sql
它的工作原理:
例如
C:\
It works:
C:\
is for example将数据库转储文件复制到(Windows PC)
D:\xampp\mysql\bin
Copy Database Dump File at (Windows PC)
D:\xampp\mysql\bin
Daniel 发布的这个命令就像 charm 一样,
只需输入数据库用户名和数据库名称,不带这些备份
**注意:确保您的数据库文件位于 htdocs 文件夹内,否则您将收到拒绝访问错误
this command posted by Daniel works like charm
just put the db username and db name without those backets
**NOTE: Make sure your database file is reside inside the htdocs folder, else u'll get an Access denied error
毫无疑问,它确实有效:
但有时你会发现“MySql Server has go a way”
为此,您需要将 mysql/bin/my.ini
max_allowed_packet = 64M 更改为 my.ini
No Doubt It does the trick:
But some time you many find "MySql Server has Gone a way"
For that you need to change mysql/bin/my.ini
max_allowed_packet = 64M to my.ini
我认为命令没问题,问题在于空格。
请注意 -u 和 #myusername 之间以及 -p 和 #mypasswd 之间的空格。
也可以写成:
另外,你不需要添加-p和命令时间,如果你的密码为空,它不会要求你输入密码。
如果您有数据库密码,它会要求输入密码。
谢谢
I think the commands are OK, issue is with the spaces.
Please observe the spaces between -u and #myusername also between -p and #mypasswd.
Can also be written as:
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.
Thanks
该过程很简单 -
将数据库移动到所需的文件夹,例如 /xampp/mysql 文件夹。
打开cmd并导航到上述位置
使用命令导入数据库 - "mysql -u root -p dbpassword newDbName
检查表进行验证。
The process is simple-
Move the database to the desired folder e.g. /xampp/mysql folder.
Open cmd and navigate to the above location
Use command to import the db - "mysql -u root -p dbpassword newDbName < dbtoimport.sql"
Check for the tables for verification.
在 Windows 中,将 MySQL 文件(即
example.sql
)放置在C:\xampp\mysql\bin
中。打开 XAMPP 控制面板,然后启动 Shell:
然后,从
C:\xampp\mysql\bin
中删除 MySQL 文件。In Windows, place the MySQL file (i.e.
example.sql
) inC:\xampp\mysql\bin
.Open the XAMPP Control Panel, and launch Shell:
Afterwards, remove the MySQL file from
C:\xampp\mysql\bin
.您是否按照受控步骤排除故障:
(1) 脚本看起来没问题吗?
(2) 你能连接到你的数据库吗(即使没有指定主机)?
(3) 可以提供脚本吗? (希望有更多/更好的错误信息)
(4)为什么它(仍然)不起作用?
我怀疑脚本的编码可能是罪魁祸首,但我遇到了 UTF8 或 UTF16 编码文件的语法错误:
这可能是版本问题;所以我认为你应该确保脚本的编码。
Do your trouble shooting in controlled steps:
(1) Does the script looks ok?
(2) Can you connect to your database (even without specified the host)?
(3) Can you source the script? (Hoping for more/better error info)
(4) Why does it (still not) work?
I suspected that the encoding of the script could be the culprit, but I got syntax errors for UTF8 or UTF16 encoded files:
This could be a version thing; so I think you should make sure of the encoding of your script.
我认为OP的问题并没有逃脱斜线。
在 Windows 上,类似以下的路径:
"c:\user\folderss\myscript.sql"
在命令行中应写为:或:
因此
"\u"
来自"c:\user"
被解释为命令。请参阅: http://dev.mysql.com/doc/refman /5.5/en/mysql-commands.html 了解更多信息
I think the OP's problem was not escaping the slashes.
on windows a path like:
"c:\user\folderss\myscript.sql"
should in the command line be written like either:or:
therefore
"\u"
from"c:\user"
was interpreted as a command.see: http://dev.mysql.com/doc/refman/5.5/en/mysql-commands.html for more info
这是我尝试从 xampp 服务器中的 cmd 导入数据库
对我来说正确的命令是这个,你可以根据你的要求更改它。我还附上了我第一次从命令行导入数据库时遇到的错误。你可以看到我使用的最后一个命令,我将它粘贴到这里,它对我来说也是有效的。
here is my try to import database from cmd in xampp server
the correct command for me is this you can change it with your requirements.and i also attached Errors that i face first time importing db from command line.you can see last command that i use and i paste it here also its working fro me.
C:\xampp\mysql\bin>mysql -u {DB_USER} -p {DB_NAME} <路径/到/文件/文件名.sql
mysql -u root -p dbname< “C:\Users\sdkca\Desktop\mydb.sql”
C:\xampp\mysql\bin>mysql -u {DB_USER} -p {DB_NAME} < path/to/file/filename.sql
mysql -u root -p dbname< "C:\Users\sdkca\Desktop\mydb.sql"