Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
pymysql question
#1
Hello, I am totally new to python.
I am learning to use pymysql to retrive daa from mysql, I have this code:
#!/usr/bin/python3

import pymysql

#make a connection to mysql
conn = pymysql.connect(
    host='localhost',
    user='xyz',
    passwd='abcde',
    db='my_db',
    autocommit=True
)
cur=conn.cursor()
sql="SELECT col_2 FROM my_tb WHERE row_id=1"
print(cur.execute(sql))
How do I print out the data in col_2? Thanks.
Reply
#2
change:
cur=conn.cursor()
sql="SELECT col_2 FROM my_tb WHERE row_id=1"
print(cur.execute(sql))
to
cur=conn.cursor()
sql="SELECT col_2 FROM my_tb WHERE row_id=1"
cur.execute(sql)
rows = cur.fetchall()
for row in rows:
    print(row)
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Mysql Syntax error in pymysql ilknurg 4 2,291 May-18-2022, 06:50 AM
Last Post: ibreeden
  pymysql can't do SELECT * Pedroski55 3 2,902 Sep-11-2021, 10:18 PM
Last Post: Pedroski55
  pymysql won't handle some diacritic characters awarren2001AD 0 1,237 Apr-16-2020, 08:58 AM
Last Post: awarren2001AD
  pyMySQL - ROW_NUMBER in SQL statement JayCee 1 2,339 Apr-12-2020, 08:40 PM
Last Post: JayCee
  pyMySQL How do I get the row id JayCee 3 2,667 Apr-12-2020, 08:38 PM
Last Post: JayCee
  PyMySQL return a single dictionary Valon1981 2 1,734 Feb-20-2020, 04:07 PM
Last Post: Valon1981
  pymysql: formating ouput of query wardancer84 18 8,181 Oct-04-2018, 01:54 PM
Last Post: wardancer84
  pymysql ifnull aland 4 3,939 Sep-06-2018, 05:58 AM
Last Post: buran
  get last row id in pymysql tony1812 1 11,072 Sep-26-2017, 11:25 PM
Last Post: Larz60+
  pymysql on macos seirra tony1812 5 4,496 Sep-17-2017, 03:24 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020