How to Create Databases & Tables in phpMyAdmin
# CHAPTER 4
Creating Databases and Tables
1. Introduction
Every great software application begins with an empty database. In traditional SQL, creating a database and defining the tables requires typing out long, perfectly formattedCREATE DATABASE and CREATE TABLE commands. One missing comma, and the terminal throws an error. phpMyAdmin eliminates this frustration. In this chapter, we will use the visual GUI to instantly create our first database, configure its character set, and architect our very first tables without writing a single line of SQL code.
2. Learning Objectives
By the end of this chapter, you will be able to:- Create a new Database via the GUI.
- Understand and select the correct Collation (Character Set).
- Create a new Table within a database.
- Define columns and data types visually.
- Understand database naming conventions.
3. Creating Your First Database
Creating a database in phpMyAdmin takes exactly two clicks.-
1.
Open phpMyAdmin (
http://localhost/phpmyadmin).
- 2. In the left sidebar, click the New button (at the very top of the database tree).
- 3. The main screen will display "Create database".
-
4.
Enter a name in the "Database name" text box (e.g.,
company_db).
-
5.
Leave the "Collation" dropdown as its default value, or select
utf8mb4_unicode_ci(more on this below).
- 6. Click the Create button.
4. Naming Conventions
Before you type a name, you must understand the industry rules for naming databases and tables.-
Lowercase Only: Always use lowercase letters. (
Company_DBis bad;company_dbis good).
-
No Spaces: Never use spaces. Use underscores (
_) to separate words. (my storeis bad;my_storeis good).
-
Plural Tables: A database name is singular (
company_db), but table names should almost always be plural nouns because they hold multiple records (users,products,orders).
5. What is Collation (Character Sets)?
When you create a database, you see a dropdown box next to the name filled with strange terms likelatin1_swedish_ci or utf8mb4_general_ci. This is the Collation.
It tells the database how to store and sort text characters.
The Golden Rule: Always select utf8mb4_unicode_ci (or utf8mb4_general_ci).
Why? Because utf8mb4 supports every language on Earth (Chinese, Arabic, Russian) AND it supports Emojis! If you use older collations like latin1, and a user types a 🚀 emoji into a comment, your database will crash or corrupt the data.
6. Creating Your First Table
Now thatcompany_db exists, click on it in the left sidebar. The main screen will say: "No tables found in database. Create table".
-
1.
Name: Type
users.
-
2.
Number of columns: Type
3.
- 3. Click the Create button.
7. Defining the Table Structure
You will now see a grid where you define the architecture of your newusers table. Fill out the first row (the primary key):
-
Name: type
id
-
Type: select
INT(Integer/Number)
-
A_I: Check the box that says
A_I(Auto Increment). This tells MySQL to automatically count 1, 2, 3 as new users are added. Checking this box automatically makes it the Primary Key!
Fill out the second row:
-
Name: type
username
-
Type: select
VARCHAR(Variable Character text)
-
Length/Values: type
50(Maximum 50 characters)
Fill out the third row:
-
Name: type
email
-
Type: select
VARCHAR
-
Length/Values: type
150
Scroll down and click Save. You have successfully architected a database table without writing any SQL!
8. Mini Project: Student Management Database
Let's practice the workflow.-
1.
Click New and create a database named
school_systemusingutf8mb4_unicode_ci.
-
2.
Inside
school_system, create a table namedstudentswith 4 columns.
- 3. Configure the columns:
-
student_id(INT, check the A_I box)
-
first_name(VARCHAR, Length 100)
-
last_name(VARCHAR, Length 100)
-
enrollment_date(Type: DATE)
- 4. Click Save.
9. Common Mistakes
-
Forgetting the Length for VARCHAR: If you set a column type to
VARCHAR, MySQL *requires* you to define a maximum length (e.g., 255). If you leave the Length/Values box empty and click Save, phpMyAdmin will throw a bright red SQL error.INTandDATEdo not strictly require manual lengths, butVARCHARalways does.
10. Best Practices
-
The "id" Column Rule: Every single table you ever create in your life should have its very first column named exactly
id(ortablename_id), set toINT, and with theA_I(Auto Increment) box checked. This ensures every row has a unique mathematical fingerprint (Primary Key).
11. Exercises
-
1.
According to industry naming conventions, should a table containing customer data be named
Customer,CustomersData, orcustomers?
-
2.
What happens if you check the
A_I(Auto Increment) box for anINTcolumn in phpMyAdmin?
12. Database Challenges
You are creating a database that will be used by a global audience spanning Europe, Asia, and the Middle East. Furthermore, users will be allowed to use Emojis in their profile bios. What specific Collation must you select when creating this database in phpMyAdmin to prevent data corruption? *(Answer:utf8mb4_unicode_ci or utf8mb4_general_ci)*
13. MCQ Quiz with Answers
When creating a new database in phpMyAdmin, why is it strongly recommended to select utf8mb4 as the Collation rather than the older latin1 default?
When defining a table structure via the phpMyAdmin GUI, what is the mandatory requirement if you select VARCHAR as the data type for a column?
14. Interview Questions
-
Q: Explain the purpose of checking the
A_I(Auto Increment) checkbox in the phpMyAdmin table creation GUI. What structural database constraint does phpMyAdmin automatically apply when this box is checked?
- Q: Discuss database naming conventions. Why do experienced database administrators vehemently avoid using uppercase letters and spaces when naming databases and tables?
15. FAQs
Q: I created a table, but I misspelled the name. Do I have to delete it and start over? A: No! You can easily rename it. Click on the table in the left sidebar, click the "Operations" tab at the top of the screen, and look for the "Table options" section where you can rename it instantly.16. Summary
You have built your foundation. You understand that clicking the "New" button, selectingutf8mb4, and utilizing the visual table builder allows you to rapidly deploy professional-grade database architectures while avoiding the syntax errors of raw SQL programming.
17. Next Chapter Recommendation
We created our tables perfectly the first time. But in the real world, business requirements change. What if the boss asks you to add a "Phone Number" column to theusers table after it is already built? In Chapter 5: Managing Table Structures and Columns, we will learn how to modify existing tables using the Structure tab.