MySQLdb查询有中文关键字查不到数据
发布时间:2022-07-05 11:37 所属栏目:115 来源:互联网
导读:#/usr/bin/env python #__*__coding:utf8__*__ zbx_host = 10.1.12.100 zbx_port = 3306 zbx_username = zabbix zbx_password = 123456 zbx_dbname = zabbix groupname = 其他部门 conn = MySQLdb.connect(host = zbx_host,port = zbx_port,user = zbx_usern
#/usr/bin/env python #__*__coding:utf8__*__ zbx_host = '10.1.12.100' zbx_port = 3306 zbx_username = 'zabbix' zbx_password = '123456' zbx_dbname = 'zabbix' groupname = '其他部门' conn = MySQLdb.connect(host = zbx_host,port = zbx_port,user = zbx_username, passwd = zbx_password,db = zbx_dbname) cursor = conn.cursor() sql = '''select groupid from groups where name='%s' ''' % groupname cursor.execute(sql) print cursor.fetchall() 当groupname = '其他部门'的时候,一直没有查到数据,一直为空,但是将groupname = 'templates'时就有数据了,我感觉是不支持中文,数据库本身编码是utf8的MySQLdb查询有中文关键字查不到数据 剽窃了一下下人家大神写的帖子MySQLdb查询有中文关键字查不到数据发现MySQLdb插件还要在连接时声明一下,不长使用中文写脚本,一直没发现。 conn = MySQLdb.connect(host = zbx_host,port = zbx_port,user = zbx_username, passwd = zbx_password,db = zbx_dbname,charset = "utf8") 加个参数就好了,折腾了好长时间MySQLdb查询有中文关键字查不到数据. (编辑:ASP站长网) |
相关内容
网友评论
推荐文章
热点阅读