Write the bat script to execute the MSYQL database sql

Source: Internet
Author: User

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:

    1. 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";
    2. 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.