mysqldatabaseshellterminal

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.


Solution

  • 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"