Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

MySQLdb query has Chinese keywords but cannot find data.

2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

# / usr/bin/env python#__*__coding:utf8__*__zbx_host = '10.1.12.100'zbx_port = 3306zbx_username =' zabbix'zbx_password = '123456'zbx_dbname =' zabbix'groupname = 'other departments' 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'% groupnamecursor.execute (sql) print cursor.fetchall ()

When groupname = 'other departments', the data has not been found and has been empty all the time, but there is data when groupname = 'templates'. I think it does not support Chinese, and the database itself is encoded in utf8.

Plagiarized the post written by the great god for a while.

Found that the MySQLdb plug-in should also declare when connecting, not long to use Chinese to write scripts, has not been found.

Conn = MySQLdb.connect (host = zbx_host,port = zbx_port,user = zbx_username, passwd = zbx_password,db = zbx_dbname,charset = "utf8")

Just add a parameter. It's been going on for a long time.

Reference:

Http://blog.csdn.net/dszgf5717/article/details/50985816

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report