Creating a database in MySQL takes one command

To create a database in MySQL, open your MySQL client and run CREATE DATABASE database_name; — replace "database_name" with whatever you want to call it. That's the core action. What comes after depends on whether you're working from the command line, a graphical tool, or a hosting control panel, and whether you need to set permissions or character encoding.

The command works the same way regardless of your operating system. MySQL will create the database immediately and return a confirmation message. If a database with that name already exists, MySQL will return an error unless you add IF NOT EXISTS to the command.

Key Takeaways

  • The basic command is CREATE DATABASE database_name; — the semicolon at the end is required.
  • Use CREATE DATABASE IF NOT EXISTS database_name; to avoid an error if the database already exists.
  • You can specify character encoding with CREATE DATABASE database_name CHARACTER SET utf8mb4; to support special characters and emojis.
  • After creating a database, you must select it with USE database_name; before you can create tables or add data.
  • Different tools — command line, phpMyAdmin, hosting panels — use the same underlying command but present different interfaces.

Creating a database from the MySQL command line

Log into MySQL first by opening your terminal or command prompt and typing mysql -u root -p, then enter your password when prompted. The -u flag specifies the username (usually "root" for local installations) and -p tells MySQL to ask for a password.

Once you see the mysql> prompt, type your CREATE DATABASE command. For example: CREATE DATABASE my_store; Then press Enter. MySQL will respond with "Query OK, 1 row affected" or similar, meaning the database was created. Type SHOW DATABASES; to see a list of all databases on your server and confirm yours appears.

To start using the database immediately, type USE my_store; The prompt will change to show mysql> my_store> or similar, confirming you're now working inside that database. Any tables you create or queries you run will affect this database until you switch to a different one.

Using character encoding and collation

By default, MySQL may use latin1 character encoding, which doesn't handle accented letters, non-Latin alphabets, or emojis well. If your data includes any of these, specify utf8mb4 when you create the database: CREATE DATABASE my_store CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

The CHARACTER SET part tells MySQL how to store characters. The COLLATE part tells MySQL how to sort and compare them. utf8mb4_unicode_ci means "case-insensitive Unicode comparison" — it treats uppercase and lowercase as equivalent when sorting. If you need case-sensitive sorting, use utf8mb4_unicode_cs instead.

You can check what character set a database is using by running SHOW CREATE DATABASE my_store; This displays the exact CREATE DATABASE command that was used, so you can see the encoding and collation settings.

Creating a database through phpMyAdmin

If you're using a hosting provider or local installation with phpMyAdmin (a web-based MySQL tool), log in and look for a "Databases" tab or link, usually near the top of the page. Click it, and you'll see a form asking for a database name.

Type your database name in the text field. Below it, you'll usually see a dropdown for "Collation" — this is where you set the character encoding. Select utf8mb4_unicode_ci if your data includes special characters. Leave it at the default if you're only using standard English text. Then click "Create" and phpMyAdmin will run the command for you.

After creation, phpMyAdmin will show your new database in the left sidebar. Click on it to select it, and you can then create tables, import data, or run queries without typing any commands.

Creating a database through a hosting control panel

Most web hosting providers include a control panel like cPanel or Plesk. Log into your hosting account, find the "Databases" or "MySQL Databases" section (the exact name varies by provider), and look for a button to create a new database.

You'll typically need to enter a database name and choose a character set. Some panels prefix the database name with your account name automatically — for example, if your account is "johnsmith" and you type "my_store", the actual database name becomes "johnsmith_my_store". Check what the panel shows before confirming.

After creation, the panel usually displays connection details: the database name, the hostname (often "localhost"), and instructions for creating a user account with a password. You'll need these details to connect from your application or to log in via phpMyAdmin.

Avoiding common mistakes when creating databases

The most common error is forgetting the semicolon at the end of the command. MySQL requires ; to mark the end of a statement. If you type CREATE DATABASE my_store without it, MySQL will wait for more input and won't execute the command.

Another mistake is using spaces or special characters in the database name. Stick to letters, numbers, and underscores. Names like "my-store" or "my store" will cause errors. If you must use a name with special characters, wrap it in backticks: CREATE DATABASE `my-store`;

A third issue is creating a database but forgetting to select it before creating tables. If you run CREATE TABLE users (...); without first running USE my_store;, MySQL will return an error saying "No database selected". Always select your database before working with its contents.

Checking and deleting databases

To see all databases on your server, run SHOW DATABASES; This lists every database you have permission to access. System databases like "mysql", "information_schema", and "performance_schema" appear here too — don't delete these.

To delete a database you no longer need, run DROP DATABASE database_name; This permanently removes the database and all its tables and data. There's no undo, so be certain before running this command. To avoid an error if the database doesn't exist, use DROP DATABASE IF EXISTS database_name;

Frequently Asked Questions

Do I need special permissions to create a database?

Yes. Your MySQL user account must have the CREATE privilege. If you're using the root account on a local installation, you have this by default. If you're on a hosting provider, your account usually has permission to create databases within your own account. If you get a "permission denied" error, contact your hosting provider.

Can I rename a database after creating it?

MySQL doesn't have a direct RENAME DATABASE command. The standard approach is to create a new database, copy all tables from the old one to the new one, then delete the old database. Some hosting panels offer a rename function that handles this automatically.

What's the difference between CHARACTER SET and COLLATE?

CHARACTER SET defines which characters can be stored and how they're encoded in bytes. COLLATE defines how those characters are sorted and compared. You can have the same character set with different collations — for example, utf8mb4_unicode_ci (case-insensitive) versus utf8mb4_unicode_cs (case-sensitive).

Can I create a database with the same name as one that already exists?

No — MySQL will return an error. Use CREATE DATABASE IF NOT EXISTS database_name; to avoid the error if the database already exists. This command creates the database only if it doesn't exist, and does nothing if it does.

What happens if I create a database but never use it?

Nothing bad happens. The empty database sits on your server taking up minimal disk space. You can select it and start using it whenever you're ready, or delete it if you change your mind.