How to insert data into the database
This article mainly introduces the relevant knowledge of "how to insert data in the database". The editor shows you the operation process through an actual case, and the operation method is simple, fast and practical. I hope this article "how to insert data in the database" can help you solve the problem.
Insert data
Insert data using the "INSERT INTO" statement:
Demo_mysql_test.py:
Insert a record into the sites table.
Import mysql.connector
Mydb = mysql.connector.connect (
Host= "localhost"
User= "root"
Passwd= "123456"
Database= "runoob_db"
)
Mycursor = mydb.cursor () sql = "INSERT INTO sites (name, url) VALUES (% s,% s)"
Val = ("RUNOOB", "https://www.runoob.com")"
Mycursor.execute (sql, val)
Mydb.commit () # the contents of the data table are updated and this statement must be used
Print (mycursor.rowcount, "record inserted successfully.")
Execute the code and the output is as follows:
1 record inserted successfully on "how to insert data in the database" content is introduced here, thank you for reading. If you want to know more about the industry, you can follow the industry information channel. The editor will update different knowledge points for you every day.