Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Prodentim Probiotics Specially Designed For The Health Of Your Teeth And Gums

Instant Grammar Checker - Correct all grammar errors and enhance your writing

Teach Your Child To Read

Powerful WordPress hosting for WordPress professionals

Disclosure: My content contains affiliate links.

31,104 questions

40,777 answers

573 users

How to insert a record into MySQL database table with Python

1 Answer

0 votes
# c:\Users\user_nm\AppData\Local\Programs\Python\Python35-32\Scripts\pip install mysql-connector
  
import mysql.connector
  
db = mysql.connector.connect(
    host="localhost",
    user="root",
    passwd="",
    database="python_database"
)
 
db_cursor = db.cursor()
 
sql = "INSERT INTO workers (name, profession) VALUES (%s, %s)"
val = ("Fox", "Python Programmer")

db_cursor.execute(sql, val)

db.commit()

print("A total of:", db_cursor.rowcount, "record inserted")

 
'''
run:

A total of: 1 record inserted

'''

 





answered Nov 29, 2018 by avibootz
...