How to create a database in MySQL CLI

#StandWithUkraine
Today, 25th June 2022, Ukraine is still bravely fighting for democratic values, human rights and peace in whole world. Russians ruthlessly kill all civilians in Ukraine including childs and destroy their cities. We are uniting against Putin’s invasion and violence, in support of the people in Ukraine. You can help by donating to Ukrainian's army.

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