↑ ↓ select, Enter open, Esc close

Create a MySQL database with its own user

Caution: This command changes the system. Understand what it does before you run it.

Adjust the values, the command updates live
root@server
mysql -e "CREATE DATABASE wp_example CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; CREATE USER 'wp_example_user'@'localhost' IDENTIFIED BY 'SecurePassword'; GRANT ALL PRIVILEGES ON wp_example.* TO 'wp_example_user'@'localhost';"

Creates a database with full Unicode support (utf8mb4, which also covers emojis in content), creates a local user and grants it all privileges on this database only. This is the usual foundation for WordPress and other web applications.

Note: On Plesk servers, create databases through Plesk, otherwise Plesk does not know about them for backups and management. The password ends up in the shell history.

Also searched as

  • create new mysql database
  • create database and user
  • create database for wordpress

Related one-liners

All in MySQL and MariaDB

Read first, then run.

The commands on myline.de act directly on servers, files and databases. A wrong path or placeholder can delete data irreversibly or make a server unreachable.

  • All commands are provided without warranty and are not tested on every system.
  • Understand what a command does before running it, and check every placeholder.
  • Make a backup first and, if possible, try it on a test system.
  • You run commands at your own risk. Liability for damages is excluded to the extent permitted by law.