ERROR 1366 (HY000): Incorrect string value: '\xF0\x9F\x98\x9C' for column 'comment' at row 1

前端 未结 5 2069
天命终不由人
天命终不由人 2020-12-06 01:10

Here\'s my sql:

INSERT INTO comments (createdate,userid,profileid,comment,status) 
VALUES (1449503167,65704,65704,\'@Mr_S66 Wish I was There For The Xmas Par         


        
相关标签:
5条回答
  • 2020-12-06 01:28

    Change connection to mysql from "SET NAMES utf8" to "SET NAMES utf8mb4"

    In PHP, use mysqli_set_charset to add charset, https://www.w3schools.com/php/func_mysqli_set_charset.asp

    $conn = mysqli_connect("localhost","my_user","my_password","my_db");
    if (mysqli_connect_errno()) {
       echo "Failed to connect to MySQL: " . mysqli_connect_error();
    }
    
    // Change character set to utf8
    mysqli_set_charset($conn, ”utf8mb4”);
    

    Or if you are in NodeJS, (This is extra information, just in case)

    db_config = {  
        host: "localhost",
        user: "user",
        password: "password",    
        database: "mydb",  
        charset: "utf8mb4_unicode_ci"
    }
    var conn = mysql.createConnection(db_config)
    

    Also, make sure the column of the table and the Table itself is of same uf8mb4 encoding.

    ALTER TABLE my_table CONVERT TO CHARACTER SET utf8mb4;
    
    ALTER TABLE my_table
       CHANGE COLUMN my_column my_column TEXT
       CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
    
    0 讨论(0)
  • 2020-12-06 01:32

    to save emoji characters you have to set your data field to utf8m4b because mysql utf8 only uses 3 bytes to store character. Check my solution at https://stackoverflow.com/a/36274546/3792270

    0 讨论(0)
  • 2020-12-06 01:37

    If nothing works in mysql shell, try to change some settings in mysqld.cnf

    [mysqld]
    character-set-client-handshake = FALSE
    character-set-server = utf8mb4
    

    Original answer MySQL utf8mb4, Errors when saving Emojis Credits to: user3624198

    0 讨论(0)
  • 2020-12-06 01:46

    Something in your environment is not set up to correctly process Unicode text.

    The byte sequence F0 9F 98 9C, represented incorrectly as "😜" in your query, is the UTF8 encoding of the Unicode character "

    0 讨论(0)
  • 2020-12-06 01:50

    Change connection to mysql from SET NAMES utf8 to SET NAMES utf8mb4

    0 讨论(0)
提交回复
热议问题