Creating a database in MySQL takes three steps: connect to MySQL, run a CREATE DATABASE command with your chosen name, and verify it worked
A database in MySQL is a container that holds related tables, and you create one before you can store any data. The process is straightforward whether you are working on your own computer or a web server. You will need access to MySQL (either installed locally or through your hosting provider), a way to send commands to it, and about two minutes.
This guide covers the most common method — using the MySQL command line — plus the graphical alternative if you prefer not to type commands. Both approaches create the same result.
Key Takeaways
- You connect to MySQL first using your username and password, then create the database with a single CREATE DATABASE command.
- Database names can contain letters, numbers, and underscores, but cannot start with a number and are case-insensitive on most systems.
- After creating a database, you use a USE command to select it before creating tables inside it.
- If you make a mistake, you can delete a database with DROP DATABASE and start over without losing anything else.
Connecting to MySQL from the command line
Open your terminal or command prompt. On Windows, search for "Command Prompt" or "PowerShell". On Mac or Linux, open Terminal. Type this command and press Enter:
mysql -u root -p
Replace "root" with your MySQL username if it is different. The system will ask for your password. Type it (you will not see the characters appear) and press Enter. If the connection works, you will see a prompt that looks like mysql>. If you get an error saying "command not found" or "mysql is not recognized", MySQL is either not installed or not in your system path — check with your hosting provider or system administrator for the correct connection method.
If you are connecting to a remote server (like a web hosting account), add the host address:
mysql -u username -p -h server.example.com
Replace "username" with your MySQL user and "server.example.com" with your actual server address. Your hosting provider will give you this information.
Running the CREATE DATABASE command
Once you see the mysql> prompt, type this command:
CREATE DATABASE mydatabase;
Replace "mydatabase" with whatever you want to call your database. The semicolon at the end is required — it tells MySQL the command is complete. Press Enter. If it works, you will see a message saying "Query OK, 1 row affected". That means the database now exists.
Database names follow these rules: they can contain letters (a–z, A–Z), numbers (0–9), and underscores (_), but cannot start with a number. Most systems treat "MyDatabase" and "mydatabase" as the same name, so pick one style and stick with it. Avoid spaces and special characters like hyphens or periods.
If you get an error saying "database already exists", that name is taken. Choose a different name and run the command again. If you get a syntax error, check that you included the semicolon and spelled CREATE DATABASE correctly.
Verifying the database was created
To confirm your database exists, type this command:
SHOW DATABASES;
Press Enter. You will see a list of all databases on this MySQL server, including the one you just created. Look for your database name in the list. If you see it, the database was created successfully.
Now select that database so you can add tables to it:
USE mydatabase;
Replace "mydatabase" with your actual database name. Press Enter. The prompt will change to show mysql> mydatabase> (or similar), confirming you are now working inside that database. Any tables you create from this point will be stored in this database.
Using MySQL Workbench if you prefer a graphical interface
If typing commands feels uncomfortable, MySQL Workbench is a free graphical tool that does the same thing with buttons and menus. Download it from the official MySQL website. After installing and opening it, connect to your MySQL server using the same username and password you would use on the command line.
Once connected, right-click in the "Schemas" panel on the left side and select "Create Schema". A dialog box will appear. Type your database name in the "Name" field and click "Apply". A confirmation window will show the CREATE DATABASE command that Workbench is about to run. Click "Apply" again, and the database is created. You will see it appear in the Schemas list.
Workbench is useful if you want to see all your databases and tables visually, or if you prefer clicking over typing. The end result is identical to using the command line.
What to do if something goes wrong
If you see "Access denied for user", you typed the wrong password or your username does not have permission to create databases. Check your credentials with your system administrator or hosting provider. If you are on your own computer and forgot the root password, the recovery process depends on your operating system — search for "reset MySQL root password" plus your OS name.
If you see "Can't connect to MySQL server", the MySQL service is not running. On Windows, open Services and look for "MySQL" — if it is stopped, right-click and select Start. On Mac, MySQL may need to be started from System Preferences or the terminal. On Linux, use sudo systemctl start mysql. If you are connecting to a remote server and get a connection error, check that the server address is correct and that your hosting provider has not blocked your IP address.
If you created a database by mistake, delete it with this command:
DROP DATABASE mydatabase;
Replace "mydatabase" with the name you want to delete. MySQL will ask for confirmation. Type yes and press Enter. The database and everything in it will be permanently deleted, so only do this if you are certain.
Next steps after creating your database
Once your database exists and you have selected it with USE, you are ready to create tables. A table is where your actual data lives — it has columns (like "name" or "email") and rows (the individual records). You create a table with a CREATE TABLE command, which is the next step after this one.
You can also set permissions so other users can access this database without having full control over it. This is useful if you are building an application and want the app to connect with limited privileges. That also comes after this step.
Frequently Asked Questions
Can I create a database with a space or special character in the name?
Technically yes, but only if you wrap the name in backticks: CREATE DATABASE `my database`; Spaces and special characters cause confusion later, so avoid them. Stick to letters, numbers, and underscores.
What is the difference between a database and a table?
A database is a container that holds multiple tables. A table is where the actual data lives — it has columns and rows, like a spreadsheet. You create the database first, then create tables inside it.
Do I need to create a database for every project?
Yes, it is standard practice. Each project or application gets its own database so the data stays organized and separate. You can create as many databases as you need on a single MySQL server.
What happens if I create a database but never use it?
Nothing bad happens. It just sits there taking up a tiny amount of disk space. You can delete it later with DROP DATABASE if you change your mind. There is no expiration or automatic cleanup.
Can I rename a database after I create it?
MySQL does not have a direct RENAME DATABASE command. The standard approach is to create a new database with the name you want, copy all the tables from the old one to the new one, then delete the old database. This is more work than renaming, so choose your database name carefully the first time.