gangly/datafaker

生成中文数据导入MYSQL数据库失败

Closed this issue · 2 comments

运行系统:WIN10,python3.6.6,mysqlclient

meta.txt
id||int||[:inc(id,1)]
name||varchar(20)||[:name]
age||int||[:age]

cmd命令:
datafaker mysql mysql+mysqldb://root:root@localhost:3306/sqoop student 10 --meta D:\meta.txt

错误:
Exception in thread Thread-2:
Traceback (most recent call last):
File "D:\python\lib\threading.py", line 916, in _bootstrap_inner
self.run()
File "D:\python\lib\threading.py", line 864, in run
self._target(*self._args, **self._kwargs)
File "D:\python\lib\site-packages\datafaker\dbs\basedb.py", line 122, in save
self.save_data(lines)
File "D:\python\lib\site-packages\datafaker\dbs\rdbdb.py", line 26, in save_data
self.save_other_rdb(lines, names_format, column_names)
File "D:\python\lib\site-packages\datafaker\dbs\rdbdb.py", line 42, in save_other_rdb
self.session.execute(sql)
File "D:\python\lib\site-packages\sqlalchemy\orm\session.py", line 1269, in execute
clause, params or {}
File "D:\python\lib\site-packages\sqlalchemy\engine\base.py", line 988, in execute
return meth(self, multiparams, params)
File "D:\python\lib\site-packages\sqlalchemy\sql\elements.py", line 287, in _execute_on_connection
return connection._execute_clauseelement(self, multiparams, params)
File "D:\python\lib\site-packages\sqlalchemy\engine\base.py", line 1107, in _execute_clauseelement
distilled_params,
File "D:\python\lib\site-packages\sqlalchemy\engine\base.py", line 1253, in _execute_context
e, statement, parameters, cursor, context
File "D:\python\lib\site-packages\sqlalchemy\engine\base.py", line 1475, in _handle_dbapi_exception
util.reraise(*exc_info)
File "D:\python\lib\site-packages\sqlalchemy\util\compat.py", line 153, in reraise
raise value
File "D:\python\lib\site-packages\sqlalchemy\engine\base.py", line 1249, in _execute_context
cursor, statement, parameters, context
File "D:\python\lib\site-packages\sqlalchemy\engine\default.py", line 552, in do_execute
cursor.execute(statement, parameters)
File "D:\python\lib\site-packages\MySQLdb\cursors.py", line 191, in execute
query = query.encode(db.encoding)
File "D:\python\lib\encodings\cp1252.py", line 12, in encode
return codecs.charmap_encode(input,errors,encoding_table)
UnicodeEncodeError: 'charmap' codec can't encode characters in position 45-47: character maps to

解决了,在mysql url后面加上编码即可
datafaker mysql mysql+mysqldb://root:root@localhost:3306/sqoop?charset=utf8 student 10 --meta D:\meta.txt
感谢开源!!!

解决了,在mysql url后面加上编码即可
datafaker mysql mysql+mysqldb://root:root@localhost:3306/sqoop?charset=utf8 student 10 --meta D:\meta.txt
感谢开源!!!

好的,请多支持