执行MySQL命令后为什么反斜杠转义

时间:2017-09-07 03:49:44

标签: mysql shell

MySQL中的字段'Fparam_list'是:

{"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)"}

然后我想通过MySQL命令获取此字段,我的shell脚本是:

#!/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

执行此shell脚本后,结果为:

~/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)"}

让我感到困惑,为什么在执行MySQL命令后反斜杠会被转义?

1 个答案:

答案 0 :(得分:1)

mysql客户端转义特殊字符,以便轻松识别它们。使用--raw选项禁用此行为。