斜杠在 mysql 客户端的控制台输出中被转义;不在数据库中;)
尝试以交互方式运行客户端:
mysql -uuser -Ddatabase -p'password'
mysql> select * from my_table;
+------------------------------------+
| x |
+------------------------------------+
| stackoverflow\.com\/questions\/ask |
+------------------------------------+
并且是非交互的:
mysql -uuser -Ddatabase -p'password' <<< "select * from my_table"
stackoverflow\\.com\\/questions\\/ask
用于--raw
禁用此转义:
mysql -uuser -Ddatabase -p'password' --raw <<< "select * from my_table"
stackoverflow\.com\/questions\/ask
从手册:
--原始,-r
For tabular output, the “boxing” around columns enables one column value to be distinguished from another. For nontabular output (such as is produced in batch mode or when the --batch or --silent option is given), special characters are escaped in the output so they can be identified easily. Newline, tab, NUL, and backslash are written as \n, \t, \0, and \. The --raw option disables this character escaping.
BTW mysql_real_escape_string was the right escape function to use.