Use PyCharm to operate MySQL database

Install PyMySql template

  pip install pymysql

Configure MySQL connection parameters

  pymysql.Connect()

    host , Post, user, passwd, db, charset

Get cursor() object

  cursor()

Execute MySql statement

   cursor ().execute()

  cursor().commit()

Specific code:

# - coding: utf-8 --

import pymysql

def load_all_from_mysql():
connect
= pymysql.Connect(
host
= 'localhost',
port
= 3306,
user
= 'root',
password
= '******< span style="color: #800000;">',
db
= 'Database name',
charset
= 'utf8'
)
cursor
= connect.cursor()
sql
= "SELECT * from table name"
cursor.execute(sql)
# print(cursor.fetchall())
for row in cursor.fetchall():
print(row)

load_all_from_mysql()

# - coding: utf-8 --

import pymysql

def load_all_from_mysql():
connect
= pymysql.Connect(
host
= 'localhost',
port
= 3306,
user
= 'root',
password
= '******< span style="color: #800000;">',
db
= 'Database name',
charset
= 'utf8'
)
cursor
= connect.cursor()
sql
= "SELECT * from table name"
cursor.execute(sql)
# print(cursor.fetchall())
for row in cursor.fetchall():
print(row)

load_all_from_mysql()

WordPress database error: [Table 'yf99682.wp_s6mz6tyggq_comments' doesn't exist]
SELECT SQL_CALC_FOUND_ROWS wp_s6mz6tyggq_comments.comment_ID FROM wp_s6mz6tyggq_comments WHERE ( comment_approved = '1' ) AND comment_post_ID = 2993 ORDER BY wp_s6mz6tyggq_comments.comment_date_gmt ASC, wp_s6mz6tyggq_comments.comment_ID ASC

Leave a Comment

Your email address will not be published.