Get the App
SLTechnology News&Howtos  ›  Development  › 

How to insert data into the database

Shulou Source: shulou.com Published: 2022-06-01 01:33:19 12月01日 Update

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.

Tags: Data database knowledge success content industry statement update different practical code practical practical datasheet article method more case knowledge point article Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Technology vpn Docker Huawei Apple