How to import sql file into MySQL?

March 8, 2014 35.4k views
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!
4 Answers
Let's say you want to import a mysql dump into a new database with a new user.
Where your mysqldump is source.sql

# Enter into MySQL using "root" user identified by password
mysql -u root -p

#Create the database

#Create the user
mysql> CREATE USER 'newuser'@'localhsot' IDENTIFIED BY 'newpass';

#Grant ALL privileges onthe new database to the new User
mysql> GRANT ALL PRIVILEGES ON NEWDB.* TO 'newuser'@'localhost' IDENTIFIED BY 'newpass';

#Switch to the New Database
mysql> USE NEWDB;

#Insert data from source.sql
mysql> SOURCE source.sql
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'.
Make sure -ppassword has your password after it with no spaces.
Thanks for all of those ways to import into mysql. I got that working. Yay.
Have another answer? Share your knowledge.