ch2
2021-05-17 12:18:18 +08:00
用 python 写个脚本,重新转一下字符集
```python
# -*- coding: utf-8 -*-
from __future__ import print_function
import pymysql
db_host="127.0.0.1"
user="root"
password='123456'
db="db"
mysql_connection=pymysql.connect(host=db_host, user=user, password=password, db=db,charset='utf8mb4')
number=100000
def convert():
cursor = pymysql.cursors.SSCursor(mysql_connection)
cursor.execute("select * from table")
count = 0
total = []
while True:
row = cursor.fetchone()
if not row:
break
item = {
"content": row[0].decode("gbk").encode("utf-8")
}
total.append(item)
if len(total) >= number:
hotcomment_collection.insert_many(total)
total = []
count += number
print(count)
if len(total) > 0:
#插入新的表
def main():
convert()
if __name__ == '__main__':
main()
```