Install Mysql 8.0 on Ubuntu 20.04

 1) Run these command

$ sudo apt update

$ sudo apt install mysql-server


2) If you facing error like this

Reading package lists... Done

Building dependency tree       

Reading state information... Done

You might want to run 'apt --fix-broken install' to correct these.

The following packages have unmet dependencies:

 mysql-client : Depends: mysql-community-client (= 5.7.33-1ubuntu18.04) but it is not going to be installed

 mysql-server : Depends: mysql-community-server (= 8.0.23-1ubuntu18.04) but it is not going to be installed

E: Unmet dependencies. Try 'apt --fix-broken install' with no packages (or specify a solution).


then again run these command

$ sudo apt --fix-broken install

$ sudo apt install mysql-server


3) maneesh@maneesh:~$ sudo systemctl status mysql

[sudo] password for maneesh: 

● mysql.service - MySQL Community Server

     Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled)

     Active: active (running) since Wed 2021-03-03 15:03:38 IST; 15min ago

       Docs: man:mysqld(8)

             http://dev.mysql.com/doc/refman/en/using-systemd.html

    Process: 660 ExecStartPre=/usr/share/mysql-8.0/mysql-systemd-start pre (code=exited, status=0/SUCCESS)

   Main PID: 722 (mysqld)

     Status: "Server is operational"

      Tasks: 37 (limit: 4654)

     Memory: 391.2M

     CGroup: /system.slice/mysql.service

             └─722 /usr/sbin/mysqld


Mar 03 15:03:06 maneesh systemd[1]: Starting MySQL Community Server...

Mar 03 15:03:38 maneesh systemd[1]: Started MySQL Community Server.


4) For setting the password

aneesh@maneesh:~$ sudo mysql_secure_installation


Securing the MySQL server deployment.


Connecting to MySQL using a blank password.


5) Now mysql is working

maneesh@maneesh:~$ sudo mysql

Welcome to the MySQL monitor.  Commands end with ; or \g.

Your MySQL connection id is 10

Server version: 8.0.23 MySQL Community Server - GPL

Oracle is a registered trademark of Oracle Corporation and/or its

affiliates. Other names may be trademarks of their respective

owners.


Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.


mysql> create database demo;

Query OK, 1 row affected (0.05 sec)


mysql> show databases;

+--------------------+

| Database           |

+--------------------+

| demo               |

| information_schema |

| mysql              |

| performance_schema |

| sys                |

+--------------------+

5 rows in set (0.04 sec)


6) Create user and delete user

mysql> create user 'database_user'@'localhost' IDENTIFIED BY 'user_password';

Query OK, 0 rows affected (0.15 sec)


mysql> select user ,host from mysql.user;

+------------------+-----------+

| user             | host      |

+------------------+-----------+

| database_user    | localhost |

| debian-sys-maint | localhost |

| mysql.infoschema | localhost |

| mysql.session    | localhost |

| mysql.sys        | localhost |

| root             | localhost |

+------------------+-----------+

6 rows in set (0.00 sec)


mysql> show databases;

+--------------------+

| Database           |

+--------------------+

| demo               |

| information_schema |

| mysql              |

| performance_schema |

| sys                |

+--------------------+

5 rows in set (0.01 sec)


mysql> drop database demo;

Query OK, 0 rows affected (0.08 sec)


mysql> show databases;

+--------------------+

| Database           |

+--------------------+

| information_schema |

| mysql              |

| performance_schema |

| sys                |

+--------------------+

4 rows in set (0.00 sec)


mysql> drop user 'database_user'@'localhost';

Query OK, 0 rows affected (0.10 sec)


mysql> select user ,host from mysql.user;

+------------------+-----------+

| user             | host      |

+------------------+-----------+

| debian-sys-maint | localhost |

| mysql.infoschema | localhost |

| mysql.session    | localhost |

| mysql.sys        | localhost |

| root             | localhost |

+------------------+-----------+

5 rows in set (0.00 sec)



Comments