Execute with cmd command (under Windows)
"MySQL Bin directory" \mysql–u user name –p password –d database < "SQL script file path full name" Example:
D:\mysql\bin\mysql–uroot–p123456-dtest<d:\test\ss.sql
Attention:
A, if the use database is used in a SQL script file, the-d database option can be ignored
B, if "MySQL Bin directory" contains spaces, you need to use "" "include, such as:" C:\Program files\mysql\bin\mysql "–u username –p password –d database <" SQL script file path full name "
Successful code:
Set errorlevel=0set path_bin_mysql="C:\Program files\mysql\mysql Server 5.7\bin\ MySQL"set User_mysql=rootset Password_mysql=root%path_bin_mysql%-u%user _mysql%-p%password_mysql% <mysql.sql
The pits encountered:
- The quotation mark must take the MySQL installation path to the \bin\mysql all to wrap in, otherwise the error cannot find the meaning "the database named Bin\mysql";
- MySQL executes the SQL file in this way, you and-P are followed by the user name and password, cannot have spaces;
Write the bat script to execute the MSYQL database sql