Step 0: Read useful links

Step 1: Update your system by typing the following commands:

sudo apt update
sudo apt upgrade

Step 2: Install mysql version 5.7 on Ubuntu 16.04

sudo apt install mysql-server mysql-client

Step 3: Run mysql_secure_installation to secure your installation

sudo mysql_secure_installation

Step 4: How do I use MySQL server?

$ mysql -u root -p

Step 5: How do I create a new MySQL server database and user account?

CREATE DATABASE mydatabase CHARACTER SET utf8 COLLATE utf8_general_ci;
CREATE USER 'newuser'@'localhost' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON * . * TO 'newuser'@'localhost';

Also you can crate file.sql then copy/paste you parameters with MySQL commands into file.sql. Then run:

mysql -u root -p < file.sql

enter root password and you will get the same. This "hack" can be use for more other things without using mysql CLI .

Grant privileges for user on database.table

GRANT [тип прав] ON [database's name].[table's name] TO [username]@'localhost;

Show user in MySQL:

mysql> select * from mysql.user;


mysql> select host, user, password from mysql.user;

Remove rights for user

REVOKE [тип прав] ON [database's name].[table's name FROM [username]@localhost;

Remove database from mysql server

DROP USER demo@localhost;

How to change password for some user in MySQL

SET PASSWORD = PASSWORD('passwordphrase')

Password for some user can be changed by this commands:

SET PASSWORD FOR username@localhost = PASSWORD('passwordphrase');
SET PASSWORD FOR username@"%" = PASSWORD('passwordphrase');

The same is can be done by these commands:

UPDATE mysql.user SET Password=PASSWORD('passwordphrase') WHERE User='логин' AND Host='localhost';


GRANT USAGE ON БД.* TO username@localhost IDENTIFIED BY 'passwordphrase';


mysqladmin -u username password passwordphrase