[mysql] Import mysql DB with XAMPP in command LINE

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'

This question is related to mysql import xampp

The answer is


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


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


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

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

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


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.


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.


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


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

/opt/lampp/bin/./mysql -u dbusername -p dbname < sqlfilepath.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"


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"

Go to the xampp shell command line and run

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

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.


It works:

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

C:\ is for example


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

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


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.


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


Examples related to mysql

Implement specialization in ER diagram How to post query parameters with Axios? PHP with MySQL 8.0+ error: The server requested authentication method unknown to the client Loading class `com.mysql.jdbc.Driver'. This is deprecated. The new driver class is `com.mysql.cj.jdbc.Driver' phpMyAdmin - Error > Incorrect format parameter? Authentication plugin 'caching_sha2_password' is not supported How to resolve Unable to load authentication plugin 'caching_sha2_password' issue Connection Java-MySql : Public Key Retrieval is not allowed How to grant all privileges to root user in MySQL 8.0 MySQL 8.0 - Client does not support authentication protocol requested by server; consider upgrading MySQL client

Examples related to import

Import functions from another js file. Javascript The difference between "require(x)" and "import x" pytest cannot import module while python can How to import an Excel file into SQL Server? When should I use curly braces for ES6 import? How to import a JSON file in ECMAScript 6? Python: Importing urllib.quote importing external ".txt" file in python beyond top level package error in relative import Reading tab-delimited file with Pandas - works on Windows, but not on Mac

Examples related to xampp

Xampp localhost/dashboard phpMyAdmin ERROR: mysqli_real_connect(): (HY000/1045): Access denied for user 'pma'@'localhost' (using password: NO) Is there way to use two PHP versions in XAMPP? Where to find htdocs in XAMPP Mac phpMyAdmin access denied for user 'root'@'localhost' (using password: NO) How to downgrade php from 7.1.1 to 5.6 in xampp 7.1.1? How to turn on/off MySQL strict mode in localhost (xampp)? mysqli_connect(): (HY000/2002): No connection could be made because the target machine actively refused it How to install mcrypt extension in xampp Fatal error: Uncaught Error: Call to undefined function mysql_connect()