Home >Database >Mysql Tutorial >How to Correctly Execute MySQL Commands from Shell Scripts?
Executing MySQL Commands from Shell Scripts
Automating SQL command execution through shell scripts simplifies data management tasks. One common use case is restoring data from an SQL file, requiring a connection to a remote server.
Issue:
Attempting to execute an SQL command via a shell script using the command:
mysql -h "server-name" -u root "password" "database-name" < "filename.sql"
results in an error.
Resolution:
The error likely arises from an incorrect way of specifying the password. To fix it, use the -p flag without any space between it and the password:
mysql -h "server-name" -u "root" "-pXXXXXXXX" "database-name" < "filename.sql"
Additional Tips:
Revised Shell Script Example:
perl fb_apps_frm_fb.pl perl fb_new_spider.pl ds_fbids.txt ds_fbids.sql mysql -h dbservername -u username "-pXXXXXXXX" dbname < ds_fbids.sql
The above is the detailed content of How to Correctly Execute MySQL Commands from Shell Scripts?. For more information, please follow other related articles on the PHP Chinese website!