在命令行中使用 XAMPP 导入 mysql 数据库

发布于 2024-11-07 14:55:29 字数 246 浏览 0 评论 0 原文

我有这个命令:

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

但我收到以下错误:

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

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'

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

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

发布评论

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

评论(17

反目相谮 2024-11-14 14:55:29

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

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

此外,我刚刚编写了一个 关于 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:

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

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

辞旧 2024-11-14 14:55:29

转到 xampp shell 命令行
并运行

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

Go to the xampp shell command line
and run

mysql -h localhost -u username databasename < dump.sql
望笑 2024-11-14 14:55:29

您可能还需要指定主机。从你的说法来看,你是在 Windows 上运行的。试试这个:

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

或者

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

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

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"
流绪微梦 2024-11-14 14:55:29
mysql -h localhost -u username databasename < dump.sql

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

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

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

一个人的旅程 2024-11-14 14:55:29

/opt/lampp/bin/./mysql -u dbusername -p dbname < sql文件路径.sql

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

梅窗月明清似水 2024-11-14 14:55:29

它的工作原理:

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

例如 C:\

It works:

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

C:\ is for example

ゝ杯具 2024-11-14 14:55:29

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

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

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

mysql -h localhost -u root Databasename <@data11.sql
无可置疑 2024-11-14 14:55:29

Daniel 发布的这个命令就像 charm 一样,

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

只需输入数据库用户名和数据库名称,不带这些备份

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

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

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

我不咬妳我踢妳 2024-11-14 14:55:29

毫无疑问,它确实有效:

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

但有时你会发现“MySql Server has go a way”
为此,您需要将 mysql/bin/my.ini max_allowed_pa​​cket = 64M 更改为 my.ini

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.ini max_allowed_packet = 64M to my.ini

情话难免假 2024-11-14 14:55:29

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

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

也可以写成:

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

另外,你不需要添加-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.

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.

Thanks

如日中天 2024-11-14 14:55:29

该过程很简单 -

  1. 将数据库移动到所需的文件夹,例如 /xampp/mysql 文件夹。

  2. 打开cmd并导航到上述位置

  3. 使用命令导入数据库 - "mysql -u root -p dbpassword newDbName

  4. 检查表进行验证。

The process is simple-

  1. Move the database to the desired folder e.g. /xampp/mysql folder.

  2. Open cmd and navigate to the above location

  3. Use command to import the db - "mysql -u root -p dbpassword newDbName < dbtoimport.sql"

  4. Check for the tables for verification.

谈情不如逗狗 2024-11-14 14:55:29

在 Windows 中,将 MySQL 文件(即 example.sql)放置在 C:\xampp\mysql\bin 中。

打开 XAMPP 控制面板,然后启动 Shell:

cd c:\xampp\mysql\bin
mysql --default-character-set=utf8 -h localhost -u username databasename < example.sql

注意:使用--default-character-set=utf8 可以帮助防止特殊字符的编码问题。

然后,从 C:\xampp\mysql\bin 中删除 MySQL 文件。

In Windows, place the MySQL file (i.e. example.sql) in C:\xampp\mysql\bin.

Open the XAMPP Control Panel, and launch Shell:

cd c:\xampp\mysql\bin
mysql --default-character-set=utf8 -h localhost -u username databasename < example.sql

Note: Using --default-character-set=utf8 can help to prevent encoding issues with special characters if you intend on working with UTF-8.

Afterwards, remove the MySQL file from C:\xampp\mysql\bin.

很糊涂小朋友 2024-11-14 14:55:29

您是否按照受控步骤排除故障:

(1) 脚本看起来没问题吗?

DOS E:\trials\SoTrials\SoDbTrials\MySQLScripts
type ansi.sql
show databases

(2) 你能连接到你的数据库吗(即使没有指定主机)?

DOS E:\trials\SoTrials\SoDbTrials\MySQLScripts
mysql -u root -p mysql
Enter password: ********
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 9
Server version: 5.0.51b-community-nt MySQL Community Edition (GPL)
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

(3) 可以提供脚本吗? (希望有更多/更好的错误信息)

mysql> source ansi.sql
+--------------------+
| Database           |
+--------------------+
| information_schema |
| ...                |
| test               |
+--------------------+
7 rows in set (0.01 sec)
mysql> quit
Bye

(4)为什么它(仍然)不起作用?

DOS E:\trials\SoTrials\SoDbTrials\MySQLScripts
mysql -u root -p mysql < ansi.sql
Enter password: ********
Database
information_schema
...
test

我怀疑脚本的编码可能是罪魁祸首,但我遇到了 UTF8 或 UTF16 编码文件的语法错误:

ERROR 1064 (42000) at line 1: You have an error in your SQL syntax; check the manual that corresponds to your
MySQL server version for the right syntax to use near '´╗┐
show databases' at line 1

这可能是版本问题;所以我认为你应该确保脚本的编码。

Do your trouble shooting in controlled steps:

(1) Does the script looks ok?

DOS E:\trials\SoTrials\SoDbTrials\MySQLScripts
type ansi.sql
show databases

(2) Can you connect to your database (even without specified the host)?

DOS E:\trials\SoTrials\SoDbTrials\MySQLScripts
mysql -u root -p mysql
Enter password: ********
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 9
Server version: 5.0.51b-community-nt MySQL Community Edition (GPL)
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

(3) Can you source the script? (Hoping for more/better error info)

mysql> source ansi.sql
+--------------------+
| Database           |
+--------------------+
| information_schema |
| ...                |
| test               |
+--------------------+
7 rows in set (0.01 sec)
mysql> quit
Bye

(4) Why does it (still not) work?

DOS E:\trials\SoTrials\SoDbTrials\MySQLScripts
mysql -u root -p mysql < ansi.sql
Enter password: ********
Database
information_schema
...
test

I suspected that the encoding of the script could be the culprit, but I got syntax errors for UTF8 or UTF16 encoded files:

ERROR 1064 (42000) at line 1: You have an error in your SQL syntax; check the manual that corresponds to your
MySQL server version for the right syntax to use near '´╗┐
show databases' at line 1

This could be a version thing; so I think you should make sure of the encoding of your script.

红尘作伴 2024-11-14 14:55:29

我认为OP的问题并没有逃脱斜线。
在 Windows 上,类似以下的路径: "c:\user\folderss\myscript.sql" 在命令行中应写为:

 c:\\\user\\\folders\\\myscript.sql

或:

c:/user/folders/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:

 c:\\\user\\\folders\\\myscript.sql

or:

c:/user/folders/myscript.sql

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

梅窗月明清似水 2024-11-14 14:55:29

这是我尝试从 xampp 服务器中的 cmd 导入数据库
对我来说正确的命令是这个,你可以根据你的要求更改它。我还附上了我第一次从命令行导入数据库时​​遇到的错误。你可以看到我使用的最后一个命令,我将它粘贴到这里,它对我来说也是有效的。

mysql -h localhost -u root ovxsolut_windhs < C:\Users\eee\Downloads\ovxsolut_windhs.sql

d
输入图片此处描述

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.

mysql -h localhost -u root ovxsolut_windhs < C:\Users\eee\Downloads\ovxsolut_windhs.sql

d
enter image description here

调妓 2024-11-14 14:55:29

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"

流云如水 2024-11-14 14:55:29
mysql -h localhost -u username -p databasename < dump.sql
mysql -h localhost -u username -p databasename < dump.sql
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文