Execute MySQL Commands from Shell Script
Introduction:
Executing MySQL commands from a shell script offers automation capabilities for database operations. To achieve this, the MySQL client can be invoked from the script, enabling database connections and command execution.
Question:
How do you execute an SQL command through a shell script to restore data from a SQL file?
Answer:
To execute a MySQL command from a shell script, use the following syntax:
mysql -h "server-name" -u "username" "-pPASSWORD" "database-name" < "filename.sql"
Key Points:
Example:
[client] user = root password = XXXXXXXX mysql -h "server-name" "database-name" < "filename.sql"
Tips:
Conclusion:
Following these guidelines ensures seamless execution of MySQL commands from within shell scripts, automating data restoration and other database operations.
The above is the detailed content of How to Restore MySQL Data from a SQL File Using a Shell Script?. For more information, please follow other related articles on the PHP Chinese website!