MySQL Introduction
MySQL Introduction
Another very popular relational database system is MySQL.
MySQL has been widely used for websites, business software, and backend systems for many years.
If you understand SQL and databases, learning MySQL becomes much easier.
What Is MySQL?
MySQL is an open-source relational database management system (RDBMS).
It stores data in tables and uses SQL to manage data.
Like PostgreSQL, MySQL usually runs as a database server that applications connect to.
Why Learn MySQL?
MySQL is important because it is:
- widely used
- beginner-friendly
- fast for many workloads
- common in web development
- supported by many hosting providers
- used in real businesses
Where MySQL Is Used
MySQL is used in:
- websites
- e-commerce platforms
- content systems
- dashboards
- internal business tools
- backend APIs
MySQL vs SQLite
SQLite
- file-based
- no server
- great for local apps
MySQL
- server-based
- supports many users
- production deployments
- strong ecosystem
MySQL vs PostgreSQL
MySQL
- very common in web hosting
- popular beginner choice
- strong performance for common apps
PostgreSQL
- known for advanced features
- powerful complex queries
- strong standards support
Both are excellent choices.
Basic SQL in MySQL
Create table:
CREATE TABLE users (
id INT AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(100),
active BOOLEAN
);
What Is AUTO_INCREMENT?
Automatically increases the id value for each new row.
Example ids:
1
2
3
Insert Data
INSERT INTO users (name, active)
VALUES ('Tom', TRUE);
Read Data
SELECT * FROM users;
Update Data
UPDATE users
SET active = FALSE
WHERE id = 1;
Delete Data
DELETE FROM users
WHERE id = 1;
Connecting from Python
A common library is:
mysql-connector-python
Install:
pip install mysql-connector-python
Example:
import mysql.connector
conn = mysql.connector.connect(
host="localhost",
user="root",
password="secret",
database="mydb"
)
Parameterized Query Example
cursor.execute(
"SELECT * FROM users WHERE id = %s",
(1,)
)
Use parameters instead of building SQL strings manually.
Important Concepts
Host
The server address.
Example:
localhost
User
Database account name.
Password
Account password.
Database
The selected database to use.
Common Beginner Errors
Server Not Running
MySQL service must be running.
Wrong Password
Check credentials carefully.
Wrong Database Name
Use an existing database.
Missing Driver
Install the connector package.
Code Along
Design two tables for an online store in MySQL.
Example:
- products
- orders
Mini Challenge
Design a movie app.
Tasks:
- Create table name
- Choose 4 columns
- Pick a primary key
- Write one
INSERTquery - Write one
SELECTquery
Real World Use Case
MySQL powers websites, e-commerce stores, CMS systems, dashboards, and backend business apps.
Quiz
- What is MySQL?
- How is MySQL different from SQLite?
- What does
AUTO_INCREMENTdo? - What Python package connects to MySQL?
- Why is MySQL popular?
Assignment
Write a schema for a library system with books, members, and loans tables.
Summary
You learned what MySQL is, how it compares with SQLite and PostgreSQL, and how Python connects to it.