123456789101112131415161718192021222324252627282930313233343536373839404142 |
- import mysql.connector
- mydb = mysql.connector.connect(
- host="localhost",
- user="root",
- passwd="yourpassword"
- )
- c = mydb.cursor()
- c.execute("SHOW DATABASES")
- for x in c:
- print(x)
- c = mydb.cursor()
- c.execute("USE wordpress")
- c.execute("SELECT * FROM wp_posts LIMIT 5")
- result = c.fetchall()
- for x in result:
- print(x)
- c.execute("SELECT ID, post_title, guid, post_type FROM wp_posts LIMIT 5")
- result = c.fetchall()
- for x in result: print(x)
- c.execute("SELECT ID, post_title, guid, post_type FROM wp_posts LIMIT 5")
- result = c.fetchone()
- print(result)
- result = c.fetchone(); print(result)
- sql = "UPDATE wp_posts SET post_content = replace(post_content,'nginx','nginx-php')"
- c.execute(sql)
- mydb.commit()
- print(c.rowcount, "record(s) affected")
|