Install MySQL and Python MySQL Connector

  • Set up MySQL and configure Python MySQL connector for database connectivity.

  • Topic 1: Installing MySQL Server

    What is MySQL Server?

    MySQL Server is the software that:

    • Stores data

    • Manages databases

    • Executes SQL commands

    It runs in the background and handles all database operations.

    Steps to Install MySQL Server

    1. Download MySQL Installer

    2. Choose MySQL Server

    3. Set:

      • Username: root

      • Password: (remember it)

    4. Complete installation

    After installation, MySQL Server will run as a service.

    Verify MySQL Installation (Command Line)

Check MySQL Version

This command checks whether MySQL is installed correctly.

mysql --version
  • Topic 2: MySQL Workbench

    What is MySQL Workbench?

    MySQL Workbench is a GUI (Graphical User Interface) tool used to:

    • Write SQL queries

    • Create databases & tables

    • View and manage data

    • Manage MySQL users

    It is easier than using command line.

    Uses of MySQL Workbench

    • Create database visually

    • Run SQL queries

    • View table data

    • Database administration

Create Database in MySQL

This SQL command creates a new database.

CREATE DATABASE college_db;
  • Topic 3: Installing mysql.connector using pip

    What is mysql.connector?

    mysql.connector is a Python library that allows:

    • Python to connect with MySQL

    • Execute SQL queries from Python

    Install mysql.connector

Install MySQL Connector for Python

This command installs the MySQL connector library using pip.

pip install mysql-connector-python

Check MySQL Connector Installation

This Python code checks whether mysql.connector is installed correctly.

import mysql.connector
print("MySQL Connector Installed Successfully")

Test MySQL Connection Using Python

This code tests whether Python can successfully connect to MySQL Server.

import mysql.connector

conn = mysql.connector.connect(
    host="localhost",
    user="root",
    password="root"
)

if conn.is_connected():
    print("Connected to MySQL Server Successfully")

conn.close()