[MySQL] support emoji (character set problem)!

Source: Internet
Author: User

The root of the problem

The main problem is that in the character set, the general solution to this problem is by experimentation. I experimented with a conclusion to share with you (in case of errors):

    1. The character set of the database
    2. The character set of the database connection
Configuration method
  1. Set the database's character set to utf8mb4 : When you create the database ( Note : is the database), specify the character set (charset) and the contrast algorithm (collate), and then CREATE DATABASE mydatabase CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; collate what to do.

  2. The character set for setting up the database connection is utf8mb4 : Specify the character set (charset) when establishing a MySQL database connection, and the following example connects the database posture with Pyton Pymsql:

    Import Pymysqlparams= { ' host ':  ' 127.0.0.1 ',  ' Port ': 3306, < Span class= "hljs-string" > ' db ':  ' Xueweihan ',  ' user ':  ' root ',  ' password ':  ' CharSet ':  ' utf8mb4 '} # Set charsetconnection = pymysql. Connect (**params)            

Different character sets, the contrast mode (collate) is not the same, so you need to specify the rules of comparison, utf8mb4_unicode_ci is utf8mb4 the character set corresponding to the comparison rules. For example, if the character set is a utf8mb4 database, execute the SQL statement: select * from boy where name=‘xueweihan‘ you need to filter the records in the database with the specified collate rules.

Use Posture

To create a database:CREATE DATABASE mydatabase CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

To connect to a database:

Import Pymysqlparams= {' host ': ' 127.0.0.1 ', ' Port ': 3306, ' db ': ' Xueweihan ', ' user ': ' root ', ' Password ': ', ' charset ': ' utf8mb4 '} # set Charsetconnection = Pymysql.  Connect (**params)               

[MySQL] supports emoji (character set issues)!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.