Problems with shell scripts executing MySQL statements

Source: Internet
Author: User

Shell script to execute the MySQL statement problems, ask the group of Daniel to answer, is a single quotation mark problem, changed to double quotation marks can be

#小提示 (Nothing to do with this topic): Ubuntu is currently using dash, causing some for (() function not to perform properly,

sudo dpkg-reconfigure Dash

If you choose No, you'll bash.

One. The script reads as follows:

#/bin/bashhostname= ' 192.168.2.52 ' port=3306username= ' root ' password= ' 123456 ' #dbname = ' #-----SQL CMD---------------------------sql_cmd= ' ALTER TABLE ' mysql '. ' User ' ADD COLUMN ' Test ' VARCHAR (1) NULL COMMENT ' test ' after ' T3 '; ' Sql_cmd_02= ' Show tables; ' sql_cmd_03= ' ALTER TABLE ' mysql '. ' User ' ADD COLUMN ' test3 ' VARCHAR (1) NULL COMMENT ' operating system name test_03 '; Sql_cmd_04= ' select * from ' MySQL '. ' User '; ' sql_cmd_05= ' ALTER TABLE ' mysql '. ' User ' ADD COLUMN ' test3 ' VARCHAR (1) NULL COMMENT ' operating system name test_03 '; Mysql-h${hostname}-p${port}-u${username}-p${password}-E "${sql_cmd_03}"

Two. Error content:

T

[Email protected]:~$ sh mysql-tb.sh ERROR 1064 (42000) at line 1:you has an error in your SQL syntax; Check the manual-corresponds to your MariaDB server version for the right syntax-use-near ' operating system name test_03 ' at line 1

Three. How to resolve:

The contents of the comment in the SQL statement require double quotation marks:

ALTER TABLE ' mysql '. ' User ' ADD COLUMN ' test3 ' VARCHAR (1) NULL COMMENT ' os name test_03 '; ' Change to: ALTER TABLE ' mysql '. ' User ' ADD COLUMN ' test3 ' VARCHAR (1) NULL COMMENT "Operating system name test_03";


Problems with shell scripts executing MySQL statements

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.