Brennan Casey Brennan Casey - 1 year ago 126
SQL Question

Run sql file in database from terminal

I have a server and within that server I have an sql script in the /var/www/ directory. That script is to create tables and databases. I need to know how to execute this sql script from terminal or some client while keeping the file on the server.

PS- I don't know much of the terminology for this topic so I will look into other suggestions for my approach. Thanks

Answer Source

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

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

There is another way:

mysql --host=localhost --user=your_username --password=your_password  -e "filename.sql"
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download