How to Import and Export database in MYSQL using Terminal in UBUNTU?

Open terminal (CTRL + ALT + T) and then depending on action use this following code.

To import database from local *.sql file by using terminal:-

mysql -u user_name -p database_name < demo_db.sql

OR

if you have a database username(as admin) and password(as admin137).

Use this following code:-

mysql -u user_name -ppass_word database_name < demo_db.sql

Example:-

Here:-
Username = admin
Password = admin137
New database = new_db
Database want to import = demo_db.sql

mysql -u root(USERNAME) -padmin137(PASSWORD) new_db(NEWDATABASE) < demo_db.sql(TO BE IMPORT DATABASE)

Try this code:-

mysql -u admin  -padmin137 new_db < demo_db.sql

Enjoy the database import.

To export a database to local *.sql file using the terminal in UBUNTU:-

mysqldump -u user_name -p database_name > demo.sql

or if u have a database username(as admin) and password(as admin34).
Use this code:-

mysqldump -u user_name -ppass_word database_newname < demo_db.sql

Example:-

Username = admin
Password = admin34
New database = demoexport_db.sql
Database want to export = Open terminal (CTRL + ALT + T) and then depending on action use this code.

mysqldump -u root  -padmin34 demo_db > demoexport_db.sql


Total Page Visits: 5538 - Today Page Visits: 1

Leave a Reply