Escaping MYSQL command lines via Bash Scripting

后端 未结 8 972
走了就别回头了
走了就别回头了 2020-12-06 01:09

PHP has mysql_real_escape_string() to correctly escape any characters that might cause problems. What is the best way to mimic this functionality for BASH?

8条回答
  •  情歌与酒
    2020-12-06 01:33

    This seems like a classic case of using the wrong tool for the job.

    You've got a lot of work ahead of you to implement the escaping done by mysql_real_escape_string() in bash. Note that mysql_real_escape_string() actually delegates the escaping to the MySQL library which takes into account the connection and database character sets. It's called "real" because its predecessor mysql_escape_string() did not take the character set into consideration, and could be tricked into injecting SQL.

    I'd suggest using a scripting language that has a MySQL library, such as Ruby, Python, or PHP.

    If you insist on bash, then use the MySQL Prepared Statements syntax.

提交回复
热议问题