• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
YL玥
博客园    首页    新随笔    联系   管理    订阅  订阅
Connector for python
 1     conn = mysql.connector.connect(host='10.214.168.25', port='3306', user='user', password='password',
 2                                    database='test')
 3     cursor = conn.cursor()
 4     cursor.execute('select * from test t limit 2')
 5     result = cursor.fetchall()
 6     if result:
 7         print(len(result))
 8         for r in result:
 9             print(r)
10     else:
11         print("result is %" % result)
12     config = {
13         'host': '10.214.168.25',
14         'user': 'user',
15         'password': 'password',
16         'port': 3306,
17         'database': 'test',
18         'charset': 'utf8'
19     }
20 
21     conn = mysql.connector.connect(**config)
22     cursor = conn.cursor()
23     cursor.execute("select * from test t limit 2")
24     result = cursor.fetchall()
25     if result:
26         print(len(result))
27         for r in result:
28             print(r)
29     else:
30         print("result is %" % result)
31 
32  cursor.execute('select * from test t where uuid = %s', ('00262732-d108-4a20-8af6-d1b4c3c4db6d',))
33     result = cursor.fetchall()
34     if result:
35         print("result len is %s, result type is %s" % (len(result), type(result)))
36         for r in result:
37             print(r)
38             for item in r:
39                 print("item is %s, item type is %s" % (item, type(item)))
40     else:
41         print("result is %" % result)

 

posted on 2019-04-08 10:53  YL玥  阅读(203)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3