What a MySQL database actually is, and why you create one
A database in MySQL is a container that holds organized data — think of it like a folder on your computer, except instead of files, it holds tables. Each table is like a spreadsheet with rows and columns. When you create a database, you are making an empty folder that MySQL will manage for you. You then create tables inside it to store the actual information.
You create a database because you need a place to put structured data that multiple programs or people might need to access. A website might have a database for user accounts. A small business might have a database for inventory. MySQL is free software that runs on Windows, Mac, and Linux, and it handles the job of storing and retrieving that data reliably.
The process itself takes seconds — you write one command, press Enter, and the database exists. The real work is deciding what data you want to store and how to organize it into tables. But before you can build those tables, you need the database container to exist first.
Key Takeaways
- A MySQL database is a container that holds tables, and you create one by logging into MySQL and running a single CREATE DATABASE command with a name you choose.
- The database name must start with a letter or underscore, can contain letters, numbers, and underscores, and cannot be a MySQL reserved word like SELECT or CREATE.
- After creating the database, you must tell MySQL to use it before you can add tables to it, using the USE command followed by your database name.
- You can create a database from the command line, from a graphical tool like MySQL Workbench, or through a hosting control panel if your database is on a web server.
- Once created, a database persists until you delete it — it does not disappear when you close the program or restart your computer.
Creating a database from the MySQL command line
If you have MySQL installed on your computer or you are connected to a server, you access it through the command line. On Windows, this is Command Prompt or PowerShell. On Mac or Linux, it is Terminal. You type mysql -u root -p and press Enter. MySQL will ask for your password. Once you are logged in, you see a prompt that looks like mysql>.
At that prompt, type CREATE DATABASE mydata; (replace mydata with whatever you want to call your database). The semicolon at the end tells MySQL the command is complete. Press Enter. If the command works, MySQL prints Query OK, 1 row affected. Your database now exists.
The name you choose matters only to you — MySQL does not care if you call it mydata, shop_inventory, or user_accounts. Pick something that tells you what the database holds. Avoid spaces and special characters. If you need multiple words, use underscores: customer_records instead of customer records.
Naming rules that MySQL enforces
MySQL has strict rules about what you can name a database. The name must start with a letter (A through Z, uppercase or lowercase) or an underscore. After the first character, you can use letters, numbers, and underscores. You cannot use spaces, hyphens, or most punctuation marks.
You also cannot use MySQL reserved words — words that MySQL already uses for its own commands. Common reserved words include SELECT, CREATE, DROP, INSERT, UPDATE, and DELETE. If you try to name a database SELECT, MySQL will reject it. If you absolutely need to use a reserved word, you can wrap the name in backticks: CREATE DATABASE `select`; But it is simpler to just pick a different name.
Database names are case-insensitive on Windows and Mac, but case-sensitive on Linux. This means on Windows, mydata and MyData refer to the same database. On Linux, they are different. To avoid confusion, use lowercase for all database names.
Telling MySQL which database to use
After you create a database, you need to tell MySQL you want to work inside it. You do this with the USE command. Type USE mydata; (using your actual database name). MySQL responds with Database changed. Now any tables you create will go inside that database.
If you close MySQL and log back in later, you need to run USE again. MySQL does not remember which database you were using. This is important: if you forget to run USE and you try to create a table, MySQL will tell you that you have not selected a database yet.
You can also specify the database when you log in, which skips the USE step. Type mysql -u root -p mydata (with your database name at the end). MySQL will ask for your password, and when you log in, you are already inside that database.
Creating a database through MySQL Workbench
If you prefer not to type commands, MySQL Workbench is a free graphical program that does the same thing with buttons and menus. read it from the official MySQL website. When you open it, you see a list of MySQL servers you can connect to. Click on the one you want to use, enter your password, and you are connected.
In the left panel, right-click on the server name and select Create Schema (a schema is MySQL's term for a database). A dialog box opens. Type your database name in the Name field. Leave the other settings as they are unless you have a specific reason to change them. Click explore, then Finish. Your database is created.
Workbench also shows you a list of all your databases in the left panel, and you can right-click any of them to delete, rename, or explore what is inside. This visual approach is often easier for people who are new to MySQL.
Creating a database on a web hosting account
If your database lives on a web server (because you are building a website), you usually do not access MySQL directly. Instead, your hosting company provides a control panel — often cPanel or Plesk — with a tool for managing databases. Look for a section called MySQL Databases or Database Manager.
Click the button to create a new database. You will see a form asking for a database name. Your hosting company may prefix the name automatically with your account username — for example, if your username is john and you type mydata, the actual database name becomes john_mydata. Type the name you want, click Create, and the database is ready. You can then use that database name when you configure your website or process.
The process varies slightly between hosting companies, but the concept is always the same: you fill in a name, click a button, and the database is created. You do not need to know MySQL commands at all.
What happens after you create the database
Once a database exists, it is empty. It contains no tables, no data, nothing. The next step is to create tables inside it — and that requires a separate command. You would type something like CREATE TABLE users (id INT, name VARCHAR(100)); to create a table called users with two columns. But you cannot do that until the database exists and you have told MySQL to use it.
A database persists on disk until you delete it. If you close MySQL, restart your computer, or log out, the database is still there the next time you log in. It does not disappear. You can create a database once and use it for years. The only way to remove it is to run DROP DATABASE mydata; — and MySQL will ask you to confirm because this action cannot be undone.
Frequently Asked Questions
Can I rename a database after I create it?
MySQL does not have a RENAME DATABASE command. The standard approach is to create a new database with the name you want, copy all the tables from the old database into the new one, and then delete the old database. Some hosting control panels offer a rename button that does this automatically behind the scenes.
What if I get an error saying the database already exists?
MySQL is telling you that you already created a database with that name. Either use a different name, or use the command CREATE DATABASE IF NOT EXISTS mydata; which creates the database only if it does not already exist. If it does exist, MySQL ignores the command instead of throwing an error.
Do I need to back up my database after I create it?
Not when ready — an empty database has nothing to lose. But once you add tables and data, backing up becomes important. Most hosting companies back up databases automatically, but you can also export your database to a file as a manual backup using the command mysqldump -u root -p mydata > mydata_backup.sql.
Can I create a database with a name that has spaces in it?
Not directly — MySQL does not allow spaces in database names. Use underscores or hyphens instead. If you absolutely must use spaces, wrap the name in backticks: CREATE DATABASE `my data`; But this creates confusion and is not recommended.
What is the difference between a database and a table?
A database is a container. A table is what goes inside the container. A single database can hold many tables. For example, a shop database might contain a products table, a customers table, and an orders table. You create the database first, then create tables inside it.