MySQL无法存储emoji表情解决方案分析
作者:站在两个世界的边缘 时间:2024-01-14 18:57:00
本文实例讲述了MySQL无法存储emoji表情解决方案。分享给大家供大家参考,具体如下:
今天学习爬虫爬伯乐在线的文章,由于在文章中有emoji表情,导致有emoji表情的文章都爬取不下来
经过一番搜索之后终于解决了问题。
相关文章可参考:
①. MySQL无法存储Emoji表情问题
②. mysql存emoji表情报错处理
1. 在navicat中
如果在新建表之前就改变数据库的编码,建表的时候好像可以自己转变过来吧
查看字符集编码:
show variables like '%char%';
更改数据库编码:
ALTER DATABASE 数据库名 CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;
更改表编码:
ALTER TABLE 表名 CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;
下面这些,好像没用到,要是不行也可以用用
set @@character_set_client='utf8mb4';
set @@character_set_connection='utf8mb4';
set @@character_set_results='utf8mb4';
set @@character_set_server='utf8mb4';
2. 在爬虫代码中
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,%s,%s,%s)
'''
self.cursor.execute(insert_sql, (item['title'], item['url'], item['bookmark_nums'],item['url_object_id'], item['content']))
self.conn.commit()
希望本文所述对大家MySQL数据库计有所帮助。
来源:https://www.cnblogs.com/wongbingming/p/6858644.html
标签:MySQL,emoji表情
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
sqlserver 游标的简单示例
2024-01-12 13:29:01
python 图像判断,清晰度(明暗),彩色与黑白实例
2023-09-04 12:58:00
![](https://img.aspxhome.com/file/2023/9/100269_0s.jpg)
详解Python核心编程中的浅拷贝与深拷贝
2021-05-04 15:44:09
![](https://img.aspxhome.com/file/2023/2/104942_0s.png)
跟老齐学Python之用while来循环
2021-01-13 23:38:18
![](https://img.aspxhome.com/file/2023/8/81498_0s.png)
Python 创建空的list,以及append用法讲解
2021-02-23 17:05:58
sql server不存在 sql server拒绝访问第1/3页
2024-01-22 02:18:41
JS实现利用两个队列表示一个栈的方法
2024-02-26 12:41:03
![](https://img.aspxhome.com/file/2023/4/56534_0s.jpg)
python实现发送带附件的邮件代码分享
2021-11-24 12:28:30
Python利用selenium建立代理ip池访问网站的全过程
2021-12-03 11:41:26
![](https://img.aspxhome.com/file/2023/2/131602_0s.png)
Python3自动安装第三方库,跟pip说再见
2022-03-12 04:34:15
![](https://img.aspxhome.com/file/2023/6/76896_0s.png)
python mysql中in参数化说明
2024-01-13 08:38:02
浅析Python 简单工厂模式和工厂方法模式的优缺点
2023-08-04 00:15:00
![](https://img.aspxhome.com/file/2023/5/62015_0s.png)
Python Pyecharts绘制桑基图分析用户行为路径
2022-06-07 02:47:57
![](https://img.aspxhome.com/file/2023/7/79527_0s.jpg)
详解vue 模版组件的三种用法
2024-05-10 14:18:22
Python实现 PS 图像调整中的亮度调整
2021-04-02 20:08:54
python批量解压zip文件的方法
2022-08-26 16:20:00
Mootools 1.2教程(8)——输入过滤第一部分(数字)
2008-11-27 13:01:00
Pytest allure 命令行参数的使用
2022-04-12 17:06:19
![](https://img.aspxhome.com/file/2023/6/97696_0s.png)
SQLServer2019安装教程图文详解
2024-01-24 10:09:13
![](https://img.aspxhome.com/file/2023/2/94432_0s.jpg)
ktl工具实现mysql向mysql同步数据方法
2024-01-15 18:09:21
![](https://img.aspxhome.com/file/2023/7/116787_0s.png)