shell指令碼執行mysql語句出現的問題

來源:互聯網
上載者:User

標籤:

shell指令碼執行mysql語句出現的問題,問群裡的大牛的到解答,是單引號問題,改成雙引號即可

#小提示(對本主題沒什麼關聯):ubuntu目前使用的是dash,導致一些for(()函數無法正常執行,

sudo dpkg-reconfigure  dash

選擇NO,就改會bash了

一。指令碼內容如下:

#/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 ‘作業系統名test_03‘;‘sql_cmd_04=‘select * from `mysql`.`user`;‘sql_cmd_05=‘ALTER TABLE `mysql`.`user` ADD COLUMN `test3` VARCHAR(1) NULL COMMENT ‘作業系統名test_03‘;‘mysql -h${hostname} -P${port} -u${username} -p${password}  -e "${sql_cmd_03}"

二.報錯內容:

t

[email protected]:~$ sh mysql-tb.sh ERROR 1064 (42000) at line 1: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ‘作業系統名test_03‘ at line 1

三.解決方式:

  sql語句中的COMMENT的內容需要雙引號:

ALTER TABLE `mysql`.`user` ADD COLUMN `test3` VARCHAR(1) NULL COMMENT ‘作業系統名test_03‘;‘改成:ALTER TABLE `mysql`.`user` ADD COLUMN `test3` VARCHAR(1) NULL COMMENT "作業系統名test_03";‘


shell指令碼執行mysql語句出現的問題

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.