Reputation: 77
The field 'Fparam_list' in MySQL is:
{"fsql":"select distinct(Fuid) from dp_snap.rc_order_db_t_rc_order where Frc_order_state=20 and Fbu_type = 40 and Fapproval_code like \"%D%\" and Fapproval_code <> \"[\\\"D98\\\"]\" and SUBSTR(Fmodify_time,1,10) >= date_add(now(),-7) and SUBSTR(Fmodify_time,1,10) <= date_add(now(),-0)"}
Then I want to get this field via MySQL command, my shell script is:
#!/bin/bash
sql_str="select Fparam_list from data_platform_db.t_extraction_task_info t where Ftask_id = '64842'"
param_list=$(/usr/bin/mysql -h127.0.0.1 -P10000 -uroot -p1234 --default-character-set=utf8 -N -e "$sql_str")
echo $param_list
After I execute this shell script, the result is:
~/tmp/yw_home/lab$ sh test_mysql.sh
{"fsql":"select distinct(Fuid) from dp_snap.rc_order_db_t_rc_order where Frc_order_state=20 and Fbu_type = 40 and Fapproval_code like \\"%D%\\" and Fapproval_code <> \\"[\\\\\\"D98\\\\\\"]\\" and SUBSTR(Fmodify_time,1,10) >= date_add(now(),-7) and SUBSTR(Fmodify_time,1,10) <= date_add(now(),-0)"}
It makes me confused, why the backslash is escaped after executing the MySQL command?
Upvotes: 0
Views: 105
Reputation: 21492
The mysql client escapes special characters so they can be identified easily. Use --raw
option to disable this behavior.
Upvotes: 1