How to import sql file into MySQL?

  • Posted March 8, 2014

You answered my question about phpmyadmin but I can’t find it nor the command lines. I know how to SFTP my .sql file to the new droplet, but the mysql command to import it into the database is gone.

Seems like this entire site changed overnight and I just started!


Submit an answer
You can type!ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Let’s say you want to import a mysql dump into a new database with a new user. <br>Where your mysqldump is source.sql <br> <br># Enter into MySQL using “root” user identified by password <br>mysql -u root -p <br> <br>#Create the database <br>mysql> CREATE DATABASE NEWDB; <br> <br>#Create the user <br>mysql> CREATE USER ‘newuser’@‘localhsot’ IDENTIFIED BY ‘newpass’; <br> <br>#Grant ALL privileges onthe new database to the new User <br>mysql> GRANT ALL PRIVILEGES ON NEWDB.* TO ‘newuser’@‘localhost’ IDENTIFIED BY ‘newpass’; <br> <br>#Switch to the New Database <br>mysql> USE NEWDB; <br> <br>#Insert data from source.sql <br>mysql> SOURCE source.sql

mysql db_name < script.sql

Thanks for all of those ways to import into mysql. I got that working. Yay.

If you are using phpMyAdmin, you can simply create a database and then go to the import tab and upload there, or you can SSH to your server and run ‘mysql -u username -ppassword database_name < FILE.sql’. <br>Make sure -ppassword has your password after it with no spaces.