Run sql file in database from terminal Run sql file in database from terminal database database

Run sql file in database from terminal


I presume that it is MYSQL. To run it from Unix / Linux environment you must do this:

$ mysql -h "server-name" -u "your_username" -p "your_password" "database-name" < "filename.sql"

There is another way:

mysql --host=localhost --user=your_username --password=your_password  -e "filename.sql"


Try this:

mysql -u your_username -p your_passworduse db_namesource <path_to_sql_file>/file.sql


If you want to run an SQL file for a specific database, then select the database first:

mysql -u your_username -p your_passworduse db_namesource <path_to_sql_file>/file.sql