Get the App
SLTechnology News&Howtos  ›  Database  › 

How can MySQL solve the problem of being unable to store emoji emoticons

Shulou Source: shulou.com Published: 2022-05-31 21:23:08 10月04日 Update

This article is about how MySQL solves the problem of being unable to store emoji emoticons. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.

The details are as follows

1. In navicat

If you change the coding of the database before creating a new table, it seems that you can change it yourself when you build the table.

View character set encodings:

Show variables like'% char%'

Change the database code:

ALTER DATABASE database name CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci

Change the table encoding:

ALTER TABLE table name CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci

The following seems to be useless, but you can also use them if you can't.

Set @ @ character_set_client='utf8mb4';set @ @ character_set_connection='utf8mb4';set @ @ character_set_results='utf8mb4';set @ @ character_set_server='utf8mb4'

two。 In crawler code

Class MysqlPipeline (object): def _ init__ (self): self.conn = MySQLdb.connect ('127.0.0.1,' root', 'root',' article_spider', charset='utf8mb4', use_unicode=True) self.cursor = self.conn.cursor () def process_item (self, item, spider): insert_sql =''insert into article (title,url,bookmark_nums,url_object_id,content) VALUE (% s% s % title'% s)''self.cursor.execute (insert_sql, (item [' title'], item ['url'], item [' bookmark_nums'], item ['url_object_id'], item [' content'])) self.conn.commit () Thank you for reading! This is the end of this article on "how to solve the problem that MySQL can not store emoji emoticons". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it for more people to see!

Tags: Coding content data database emoticons problems storage more articles no good practical code characters character sets articles time come on crawlers see Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno vpn Shulou Information Linux NVidia OPPO Reno