MySQLdb query with Chinese keyword cannot find data

Source: Internet
Author: User

#/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 department ' 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 '% gro Upnamecursor.execute (SQL) print Cursor.fetchall ()


When groupname = ' other department ', has not found the data, has been empty, but will groupname = ' templates ' when there is data, I feel is not support Chinese, the database itself code is UTF8 650) this.width=650; " Src= "Http://img.baidu.com/hi/jx2/j_0004.gif" alt= "J_0004.gif"/>

Stole a bit of the great God wrote the post 650) this.width=650; "src=" Http://img.baidu.com/hi/bobo/B_0018.gif "alt=" B_0018.gif "/> found that the MYSQLDB plug-in also to the connection when the Declaration, not long use Chinese script, has not been found.

conn = MySQLdb.connect (host = Zbx_host,port = Zbx_port,user = zbx_username, passwd = zbx_password,db = Zbx_dbname, Char set = "UTF8")

Add a parameter just fine, toss a good long time 650) this.width=650; "src=" Http://img.baidu.com/hi/bobo/B_0062.gif "alt=" B_0062.gif "/>


Reference:

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





This article is from the "LINUX" blog, so be sure to keep this source http://wangpengtai.blog.51cto.com/3882831/1946275

MySQLdb query with Chinese keyword cannot find data

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.