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

时间:2021-01-24 02:47:55

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'

13 个解决方案

#1


25  

If you are on a Windows machine, I was just able to import a large mysqldump file into my local XAMPP installation using this command in cmd.exe:

如果您在Windows机器上,我可以使用cmd.exe中的这个命令将一个大型mysqldump文件导入到我的本地XAMPP安装中:

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.

另外,我刚刚写了一个关于MySQL导入的另一个问题的更详细的答案,如果这是您想要的。

#2


12  

Go to the xampp shell command line and run

转到xampp shell命令行并运行

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

#3


6  

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"

#4


3  

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的名字就行了

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

**注意:确保您的数据库文件位于htdocs文件夹中,否则您将获得一个拒绝访问错误

#5


2  

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

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

它的工作原理,试一试。如果密码为空,则无需添加-p args。

#6


1  

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和# mywd用户名之间的空格,也在-p和# passmymymyusername之间。

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

谢谢

#7


1  

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

但有时你会发现“MySql服务器有问题”,你需要改变MySql /bin/my。ini max_allowed_packet = 64M给my.ini

#8


1  

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

#9


0  

Do your trouble shooting in controlled steps:

在控制步骤中解决问题:

(1) Does the script looks ok?

(1)剧本看起来还好吗?

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

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

(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) 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?

(4)为什么它(仍然)有效?

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:

我怀疑脚本的编码可能是罪魁祸首,但是我得到了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

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

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

#10


0  

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:

我认为OP的问题并不是逃过了惩罚。在windows上有这样的路径:“c:\用户folderss\myscript”。sql“应该在命令行中被写成:

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

or:

或者:

c:/user/folders/myscript.sql

therefore "\u" from "c:\user" was interpreted as a command.

因此,“c:\user”中的“\u”被解释为命令。

see: http://dev.mysql.com/doc/refman/5.5/en/mysql-commands.html for more info

更多信息请参见:http://dev.mysql.com/doc/refman/5.5/en/mysql-commands.html

#11


0  

The process is simple-

这个过程很简单——

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

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

  2. Open cmd and navigate to the above location

    打开cmd并导航到上面的位置

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

    使用命令导入db -“mysql -u root -p dbpassword newDbName < dbtoimport.sql”

  4. Check for the tables for verification.

    检查表格以供核实。

#12


0  

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

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

#13


-1  

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

#1


25  

If you are on a Windows machine, I was just able to import a large mysqldump file into my local XAMPP installation using this command in cmd.exe:

如果您在Windows机器上,我可以使用cmd.exe中的这个命令将一个大型mysqldump文件导入到我的本地XAMPP安装中:

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.

另外,我刚刚写了一个关于MySQL导入的另一个问题的更详细的答案,如果这是您想要的。

#2


12  

Go to the xampp shell command line and run

转到xampp shell命令行并运行

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

#3


6  

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"

#4


3  

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的名字就行了

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

**注意:确保您的数据库文件位于htdocs文件夹中,否则您将获得一个拒绝访问错误

#5


2  

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

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

它的工作原理,试一试。如果密码为空,则无需添加-p args。

#6


1  

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和# mywd用户名之间的空格,也在-p和# passmymymyusername之间。

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

谢谢

#7


1  

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

但有时你会发现“MySql服务器有问题”,你需要改变MySql /bin/my。ini max_allowed_packet = 64M给my.ini

#8


1  

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

#9


0  

Do your trouble shooting in controlled steps:

在控制步骤中解决问题:

(1) Does the script looks ok?

(1)剧本看起来还好吗?

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

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

(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) 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?

(4)为什么它(仍然)有效?

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:

我怀疑脚本的编码可能是罪魁祸首,但是我得到了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

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

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

#10


0  

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:

我认为OP的问题并不是逃过了惩罚。在windows上有这样的路径:“c:\用户folderss\myscript”。sql“应该在命令行中被写成:

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

or:

或者:

c:/user/folders/myscript.sql

therefore "\u" from "c:\user" was interpreted as a command.

因此,“c:\user”中的“\u”被解释为命令。

see: http://dev.mysql.com/doc/refman/5.5/en/mysql-commands.html for more info

更多信息请参见:http://dev.mysql.com/doc/refman/5.5/en/mysql-commands.html

#11


0  

The process is simple-

这个过程很简单——

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

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

  2. Open cmd and navigate to the above location

    打开cmd并导航到上面的位置

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

    使用命令导入db -“mysql -u root -p dbpassword newDbName < dbtoimport.sql”

  4. Check for the tables for verification.

    检查表格以供核实。

#12


0  

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

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

#13


-1  

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