🔰 MySQL Create Database Tutorial

📘 What is a Database?

A database is a structured collection of data stored electronically. MySQL allows you to create and manage databases to store information such as user data, product details, or customer records.


🛠 Prerequisites

Before creating a database in MySQL, make sure you:

  • Have MySQL installed (via XAMPP, WAMP, LAMP, or MySQL Workbench)
  • Have access to the MySQL command-line client or phpMyAdmin

✅ Basic Syntax to Create a Database

CREATE DATABASE database_name;
  • database_name: Replace this with the name you want to give your database.

📥 Example: Creating a Simple Database

CREATE DATABASE student_records;

This command creates a new database named student_records.


🔒 Creating a Database with Character Set and Collation (Optional)

CREATE DATABASE ecommerce
CHARACTER SET utf8mb4
COLLATE utf8mb4_unicode_ci;
  • CHARACTER SET utf8mb4: Supports emojis and most international characters.
  • COLLATE utf8mb4_unicode_ci: Specifies sorting and comparison rules.

💡 View Existing Databases

To list all available databases:

SHOW DATABASES;

📂 Select a Database to Use

USE student_records;

This tells MySQL that all subsequent commands will be executed on the student_records database.


🚫 Drop/Delete a Database (Be Careful!)

DROP DATABASE student_records;

⚠️ Warning: This will permanently delete the database and all its data.


💻 Creating a Database using MySQL Workbench

  1. Open MySQL Workbench
  2. Connect to your server
  3. Right-click on the Schemas area
  4. Click Create Schema
  5. Enter the database name and click Apply

🌐 Creating a Database using phpMyAdmin

  1. Open phpMyAdmin in your browser
  2. Click on the Databases tab
  3. Enter a database name
  4. Click Create

📝 Best Practices

  • Use lowercase names with underscores (e.g., user_data)
  • Avoid using MySQL reserved keywords as database names
  • Always back up data before deleting databases

🎯 Summary

TaskCommand
Create DBCREATE DATABASE dbname;
View DBsSHOW DATABASES;
Select DBUSE dbname;
Delete DBDROP DATABASE dbname;

🔰 MySQL Create Database Tutorial

📘 What is a Database?

A database is a structured collection of data stored electronically. MySQL allows you to create and manage databases to store information such as user data, product details, or customer records.


🛠 Prerequisites

Before creating a database in MySQL, make sure you:

  • Have MySQL installed (via XAMPP, WAMP, LAMP, or MySQL Workbench)
  • Have access to the MySQL command-line client or phpMyAdmin

✅ Basic Syntax to Create a Database

CREATE DATABASE database_name;
  • database_name: Replace this with the name you want to give your database.

📥 Example: Creating a Simple Database

CREATE DATABASE student_records;

This command creates a new database named student_records.


🔒 Creating a Database with Character Set and Collation (Optional)

CREATE DATABASE ecommerce
CHARACTER SET utf8mb4
COLLATE utf8mb4_unicode_ci;
  • CHARACTER SET utf8mb4: Supports emojis and most international characters.
  • COLLATE utf8mb4_unicode_ci: Specifies sorting and comparison rules.

💡 View Existing Databases

To list all available databases:

SHOW DATABASES;

📂 Select a Database to Use

USE student_records;

This tells MySQL that all subsequent commands will be executed on the student_records database.


🚫 Drop/Delete a Database (Be Careful!)

DROP DATABASE student_records;

⚠️ Warning: This will permanently delete the database and all its data.


💻 Creating a Database using MySQL Workbench

  1. Open MySQL Workbench
  2. Connect to your server
  3. Right-click on the Schemas area
  4. Click Create Schema
  5. Enter the database name and click Apply

🌐 Creating a Database using phpMyAdmin

  1. Open phpMyAdmin in your browser
  2. Click on the Databases tab
  3. Enter a database name
  4. Click Create

📝 Best Practices

  • Use lowercase names with underscores (e.g., user_data)
  • Avoid using MySQL reserved keywords as database names
  • Always back up data before deleting databases

🎯 Summary

TaskCommand
Create DBCREATE DATABASE dbname;
View DBsSHOW DATABASES;
Select DBUSE dbname;
Delete DBDROP DATABASE dbname;