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.
use the MySQL command line client: mysql -h hostname -u user database < path/to/test. sql. Install the MySQL GUI tools and open your SQL file, then execute it.
To run SQL script in MySQL, use the MySQL workbench. First, you need to open MySQL workbench. Now, File -> Open SQL Script to open the SQL script. Note − Press OK button twice to connect with MySQL.
First in terminal you have to login using your MySQL username and password Eg: mysql -uroot -p then once loged in select your data base using use <yourdatabasename then you can run this command.
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_password use db_name source <path_to_sql_file>/file.sql
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With