Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

mysql import on windows

I have a MySQL file, db.sql. I have tried to import it using:

mysql -uroot -p[password] db < db.sql 

All I get is a listing of mysql commands, or I get a syntax error. The weird thing is I used this file last week and, as far as I know, I'm doing it the same way.

I create the database, then in command line enter the above but it's not working. I've tried being inside mysql and just at command line and nothing seems to be working.

Is there something I should be doing differently in windows or MySQL5? I don't know how the heck I got it to work the first time...

TIA

like image 258
user80151 Avatar asked Nov 21 '09 01:11

user80151


People also ask

How do I import data into MySQL?

Importing a database from a file To import a file, open Workbench and click on + next to the MySQL connections option. Fill in the fields with the connection information. Once connected to the database go to Data Import/Restore. Choose the option Import from Self-Contained File and select the file.

How do I run a MySQL dump file in Windows?

To dump/export a MySQL database, execute the following command in the Windows command prompt: mysqldump -u username -p dbname > filename. sql . After entering that command you will be prompted for your password.

How do I run a MySQL dump file?

You'll see this output confirming the database creation. Then exit the MySQL shell by pressing CTRL+D . From the normal command line, you can import the dump file with the following command: mysql -u username -p new_database < data-dump.


2 Answers

Try this instead:

mysql -u root -p (prompts for password) use db; source db.sql 
like image 85
wallyk Avatar answered Oct 11 '22 18:10

wallyk


I found out it is different to run this command from Windows Command Line (cmd.exe) and Windows PowerShell.

Using CMD.exe the command works okay, but in PowerShell I get this error:

mysql -uroot exampledb < exampledb.sql 

The '<' operator is reserved for future use.

like image 27
Chayapan Khannabha Avatar answered Oct 11 '22 17:10

Chayapan Khannabha