I have a .sql
file with an export from phpMyAdmin
. I want to import it into a different server using the command line.
I have a Windows Server 2008 R2 installation. I placed the .sql
file on the C drive, and I tried this command
database_name < file.sql
It is not working I get syntax errors.
- How can I import this file without a problem?
- Do I need to create a database first?
A common use of mysqldump is for making a backup of an entire database:
You can load the dump file back into the server like this:
UNIX
The same in Windows command prompt:
PowerShell
MySQL command line
If you already have the database use the following to import the
dump
or thesql
fileif you don't you need to create the relevant database(empty) in MySQL, for that first log on to the
MySQL
console by running the following command in terminal or in cmdand when prompted provide the password.
Next create a database and use it
Then import the
sql
or thedump
file to the database fromNote: if your terminal is not in the location where the
dump
orsql
file exists, use the relative path in above.I thought it could be useful for those who are using Mac OS X:
Replace
xampp
withmamp
or other web servers.Easiest way to import into your schema:
Login to mysql and issue below mention commands.
I'm using Windows 10 with Powershell 5 and I found almost all "unix-like" solutions not working for me.
I ends up using this command.
and it works perfectly, hopefully it helps.
Thanks to @Francesco Casula's answer btw.
Try:
Check MySQL Options.
Note-1: It is better to use the full path of the SQL file
file.sql
.Note-2: Use
-R
and--triggers
to keep the routines and triggers of original database. They are not copied by default.Note-3 You may have to create the (empty) database from mysql if it doesn't exist already and the exported SQL don't contain
CREATE DATABASE
(exported with--no-create-db
or-n
option), before you can import it.