Import SQL file using a Linux terminal

If you have bigger database backup and you want to import SQL file into your database it will be easier to use the Terminal. Simply follow these steps:

1) Go to sql file backup directory (e.x. Desktop)

2) In terminal:

metodiew@metodiew:~/Desktop$ mysql -u <database username> -p <user password> <database name>  < <your file>.sql

Note: you can skip <database name> if you have one SQL backup file.

metodiew@metodiew:~/Desktop$ mysql -u <database username> -p <user password>  < <your sql backup file>.sql

Of course you can using phpMyAdmin Import option, but you might have problems if your file is bigger and you don’t have made any changes to your server configuration. Also it will be faster and easier for person who is comfortable with working Linux terminal to type two-line command and to wait for uploading the file. If the file is larger, you can always go for a coffee 🙂

Keep in mind this post it mostly for me, because I’m a lazy person when it comes to remembering commands, so it will be easier for me to find the snipped and to use them in the future 😀

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.