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 Ser
bin
folder of mysql server.source databasefilename.sql
and EnterI think it's worth mentioning that you can also load a gzipped (compressed) file with zcat
like shown below:
zcat database_file.sql.gz | mysql -u username -p -h localhost database_name
mysql --user=[user] --password=[password] [database] < news_ml_all.sql
The following command works for me from the command line (cmd) on Windows 7 on WAMP.
d:/wamp/bin/mysql/mysql5.6.17/bin/mysql.exe -u root -p db_name < database.sql
Providing credentials on the command line is not a good idea. The above answers are great, but neglect to mention
mysql --defaults-extra-file=etc/myhost.cnf database_name < file.sql
Where etc/myhost.cnf is a file that contains host, user, password, and you avoid exposing the password on the command line. Here is a sample,
[client]
host=hostname.domainname
user=dbusername
password=dbpassword
Go to the directory where you have the MySQL executable. -u
for username and -p
to prompt for the password:
C:\xampp\mysql\bin>mysql -u username -ppassword databasename < C:\file.sql