The Statement
Open the client as an administrator, with sudo mysql on Ubuntu, sudo mariadb on MariaDB, or mysql -u root -p with the password typed at the prompt. Then:
CREATE DATABASE app CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;The database is created at once and is empty. CREATE SCHEMA is the same statement under another name.
Character Set and Collation
- utf8mb4: full Unicode, including emoji and all scripts. Use it for every new database. The older
utf8(an alias forutf8mb3) stores at most three bytes per character and cannot hold all of Unicode. - Collation: the rules for sorting and comparing text.
utf8mb4_works on both MySQL and MariaDB. MySQL 8.0 and later useunicode_ ci utf8mb4_as the default for0900_ ai_ ci utf8mb4, which MariaDB does not have. - Name it explicitly: the server default depends on the version and on the distribution's configuration, so writing both values gives the same result everywhere.
Check what a database got:
SHOW CREATE DATABASE app;ALTER DATABASE app CHARACTER SET utf8mb4 COLLATE utf8mb4_ changes the default for tables created later; existing tables keep their own settings.
Only If It Does Not Exist
CREATE DATABASE IF NOT EXISTS app CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;Without IF NOT EXISTS, a second run fails with error 1007, database exists. With it, the statement gives a warning and changes nothing, which suits scripts. Note that it does not alter an existing database to match.
Naming Rules
- Use letters, digits, and underscores:
shop_works anywhere without quoting.db - Avoid hyphens and spaces: a name such as
my-appmust be written in backticks, as`my-app`, in every query. - Treat names as case-sensitive: on Linux, database names map to directories, and
Appandappare different databases.
Give One User Access
CREATE USER 'app_user'@'localhost' IDENTIFIED BY 'STRONG_PASSWORD';
GRANT ALL PRIVILEGES ON app.* TO 'app_user'@'localhost';The account works in app only and connects from the server itself only. Type the real password inside the SQL shell, never on a command line. Narrower grants and how to check them are in how to create a MySQL user.
From the Shell
sudo mysqladmin create app
sudo mysql -e "CREATE DATABASE app CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;"mysqladmin create uses the server's default character set, so the second form is the more predictable one. On MariaDB the tool is also called mariadb-admin. To confirm the database is there, see how to list databases in MySQL.
Load Existing Data
mysql -u app_user -p app < app.sqlThe dump is read into the new database. If the dump contains its own CREATE DATABASE and USE lines, it may load into a different name; look at the first lines of the file with head before you run it.
Dropping a Database
DROP DATABASE removes the database and every table in it immediately. There is no confirmation and no undo. Before you run it, take a dump and check that the file is complete:
sudo mysqldump --single-transaction app > app-before-drop.sql
DROP DATABASE app;The first line runs in the shell, the second inside the client. On MariaDB the dump tool is mariadb-dump. Also check whether any application still uses the database. A server snapshot is a second safety net, as described in snapshot vs backup.
Updated:
Linux VPS with Full Root Access
MUVCloud cloud servers run on KVM with Enterprise NVMe SSD storage and full root access, in Turkey, the Netherlands, and the USA.
More Guides
No Limits on Service or Support
You are not on your own as your projects grow. Our support engineers are ready 24/7, on several channels, whenever you need them.

- 100% customer satisfaction goal
- Our own hardware
- 24/7 ticket and email support
- 4 countries with locations