How do I insert a special character such as ' into MySQL?

前端 未结 5 1739
南旧
南旧 2020-12-19 01:50

I am executing the insert query from a shell script which reads data from multiple files. Some of the data to be inserted contains \' in the text a

5条回答
  •  攒了一身酷
    2020-12-19 02:22

    You will have to escape the input strings before passing them to MySql.

    The list of escape characters is:

    Character   Escape Sequence
    \0  An ASCII NUL (0x00) character.
    \'  A single quote (“'”) character.
    \"  A double quote (“"”) character.
    \b  A backspace character.
    \n  A newline (linefeed) character.
    \r  A carriage return character.
    \t  A tab character.
    \Z  ASCII 26 (Control-Z). See note following the table.
    \\  A backslash (“\”) character.
    \%  A “%” character. See note following the table.
    \_  A “_” character. See note following the table.
    

提交回复
热议问题