In [ ]:
import mysql.connector
# Connecting to MySQL
conn = mysql.connector.connect(
host=''''your_host'''',
user=''''your_username'''',
password=''''your_password'''',
database=''''your_database''''
)
cursor = conn.cursor()
# Creating a table
cursor.execute(''''''''''''
CREATE TABLE users (
id INT AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(255),
age INT
)
'''''''''''')
# Inserting data
cursor.execute("INSERT INTO users (name, age) VALUES (''''Alice'''', 25)")
conn.commit()
# Querying data
cursor.execute("SELECT * FROM users")
for row in cursor:
print(row)
conn.close()