PYTHON Tutorial
Windows:
Linux (Ubuntu):
sudo apt-get update
sudo apt-get install mysql-server
MacOS:
brew install mysql
// For Windows
net start mysql
// For Linux/Mac
sudo service mysql start
// For Windows
C:\ProgramData\MySQL\MySQL Server 8.0\bin\my.ini
// For Linux/Mac
/etc/mysql/my.cnf
// Port
port = 3306
// Data directory
datadir = /var/lib/mysql
// For Windows
net start mysql
// For Linux/Mac
sudo service mysql start
mysql -u root -p
CREATE DATABASE my_database;
import mysql.connector
# Connect to MySQL
db = mysql.connector.connect(
host='localhost',
user='root',
password='password',
database='my_database'
)
# Create a cursor
cursor = db.cursor()
# Execute a query
cursor.execute("SELECT * FROM my_table")
# Fetch results
results = cursor.fetchall()
# Close cursor and connection
cursor.close()
db.close()