How to create a database in MySQL CLI

If you just need to create a database you can install some RDBMS like Mysql-Workbench and use UI which will help you create database with humanized way. Actually RDBMS will generate very simple SQL in this case, so you can save time if you type it diractly in simple lightwaight CLI utility called mysql.

If you have no mysql server – install it

For Ubuntu:

sudo apt install mysql-server
sudo mysql_secure_installation

Now run mysql CLI

mysql -u root -p

Lets createe database db and user user with password password

Type lines one by one:

CREATE DATABASE db CHARACTER SET utf8mb4 COLLATE utf8mb4_bin;
CREATE USER 'usr'@'*' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON * . * TO 'usr'@'*';

Done.

#mysql
0
Ivan Borshchov profile picture
Nov 20, 2020
by Ivan Borshchov
Did it help you?
Yes !
No

Best related