Junior — Middle
Have you used MySQL databases in your projects?
sobes.tech AI
Answer from AI
Yes, MySQL is often used as a relational database in Python projects. To work with MySQL in Python, libraries such as mysql-connector-python or PyMySQL are commonly used. They allow connecting to the database, executing queries, and retrieving and processing results.
Example of connecting and executing a simple query using mysql-connector-python:
import mysql.connector
# Connecting to the database
conn = mysql.connector.connect(
host='localhost',
user='user',
password='password',
database='test_db'
)
cursor = conn.cursor()
# Executing a query
cursor.execute('SELECT * FROM users')
# Fetching results
for row in cursor.fetchall():
print(row)
cursor.close()
conn.close()
MySQL is suitable for storing structured data with clear relationships and supports transactions, which are important for many applications.