0 votes
493 views
in MySQL by

How to import SQL file using command line in MySQL?

2 Answers

0 votes
by (3.7k points)

To import sql file from command line in mysql type the following command:-

mysql -u root -p < /opt/projects/Test.sql

We have following options with import sql file from command line in mysql:-

  • Better to use full path of the SQL file like: Test.sql.
  • To Use -R and --triggers for keeping the routines and triggers of original database. They are not copied by default.
  • You may have to create the (empty) database from mysql. If it doesn't exist already and exported SQL don't contain CREATE DATABASE (exported with --no-create-db or -n option), before you can import it.
0 votes
by (5k points)

If you want to take backup of your sql into the server use the following different command like:-

  • MySQL command line:-
    • mysql> use database_name;
    • mysql> source backup.sql;
  • UNIX:-
    • shell> mysql database_name < backup.sql
  • Windows command prompt:-
    • mysql -p -u [user] [database] < backup.sql

Share:- Whatsapp Facebook Facebook


Welcome to Developerhelpway Q&A, where you can ask questions and receive answers from other members of the community.

Categories

...