Report this

What is the reason for this report?

How to import sql file into MySQL?

Posted on 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!



This textbox defaults to using Markdown to format your 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.

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

mysql db_name < script.sql

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

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.