MySQL connection through the bat file or operation involving a password, if there is a% number in the password to special processing

Source: Internet
Author: User
Tags goto

For example, I want to make a connection to a database in the bat file or to import or export data in a database (mysqldump) This will use the database password.

If the password in this database is also a special escape to run the bat file, otherwise the password is actually wrong, that is, unable to manipulate the database, because the Windows command line interpreter in the interpretation of% will see a special character, that is, the escaped character, That is, if there is a special meaning, so if there is a% of the password in accordance with 2% escaped into a%, 4% escaped to 2% such a sub-rule to re-modify the password, or the last password will be escaped to the wrong password so that there is no way to connect the database or operation database.

Such as:

@echo off

If "%1" = = "(goto input_data) ELSE (goto Input_var)

: Input_data

set/p var=input DATE (FMT:YYYYMMDDHHMM):

Goto Start

: Input_var

set/a var=%1

Goto Start

: Start

CD%cd%

Md.. \.. \to-save\tkcard\%var%

Mysql-p3302-uroot-pdst72j$mq) c%%8 -h61.160.245.119-n-s-e "SET SESSION group_concat_max_len = 99999999; SELECT CONCAT (' Mysqldump-h61.160.245.119-p3302-uroot

-Pdst72j$mq) c%%%%8 --opt-n tkcard_cn_cn_db210060000 ', Group_concat (T.table_name SEPARATOR "), ' > ') from In Formation_schema. TABLES t WHERE t.table_schema =

' tkcard_cn_cn_db210060000 ' and (T.table_name like ' dict_%% ') and T.table_name not in (' Dict_keyvalue ', ' dict_server ', ' Dict_operator_config '); "> Tkcard_dict.bat

For/f "delims=] Tokens=1"%%a in (Tkcard_dict.bat) do echo%%a. \.. \to-save\tkcard\%var%\tkcard_dict.sql >tkcard_dict.bat

Call Tkcard_dict.bat

The above 2 password original password is dst72j$mq) c%8, that is, the original password contains a%, but I am writing through the bat file must do so, that is, the first writing must be 1% before the%, the second in the% before the 3%, this way BAT file is escaped at execution time to escape the password at 2 to the correct original password: only one% of dst72j$mq) c%8

MySQL connection through the bat file or operation involving a password, if there is a% number in the password to special processing

Related Article

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.