Setup MySQL on Ubuntu 18

Install with APT repository

  1. First determine version you like and go to https://dev.mysql.com/downloads/repo/apt/
  2. At this time, there is only one option: mysql-apt-config_0.8.22-1_all.deb – which seems to be MySql 8.0, note the file name.
  3. Now, get the deb file like so:
    wget -c https://dev.mysql.com/get/mysql-apt-config_0.8.22-1_all.deb
  4. Next launch config tool like so:
    dpkg -i mysql-apt-config_0.8.22-1_all.deb
  5. It should launch a UI interface, choose appropriate versions and select OK in the last screen that shows your selections and then click bottom OK button.
  6. Now apt has stored your selections, next pull down those selections by running
    apt-get update
  7. Install Mysql Server with:
    apt-get install mysql-server
    You will see a number of lines like below:
    Preparing to unpack …/00-mysql-common_8.0.28-1ubuntu18.04_amd64.deb …
    Unpacking mysql-common (8.0.28-1ubuntu18.04) …
  8. Answer Screen prompt by entering and confirming passwords, choose Strong Password Encryption and click ok. It should do the below:
    update-alternatives: using /etc/mysql/mysql.cnf to provide /etc/mysql/my.cnf (my.cnf) in auto mode
    Created symlink /etc/systemd/system/multi-user.target.wants/mysql.service → /lib/systemd/system/mysql.service.
    Setting up mysql-server (8.0.28-1ubuntu18.04) …
    Processing triggers for man-db (2.8.3-2ubuntu0.1) …
    Processing triggers for libc-bin (2.27-3ubuntu1.5) …
  9. Run security utility and follow the prompts
    mysql_secure_installation
  10. Our source and credit to : https://phoenixnap.com/kb/how-to-install-mysql-on-ubuntu-18-04

Install with TAR file

Installing MySQL 8 (reference: https://dev.mysql.com/doc/refman/8.0/en/binary-installation.html)
wget https://downloads.mysql.com/archives/get/p/23/file/mysql-8.0.26-linux-glibc2.12-x86_64.tar.xz
tar xvf mysql-8.0.26-linux-glibc2.12-x86_64.tar.xz
mv mysql-8.0.26-linux-glibc2.12-x86_64 /opt/mysql8
groupadd mysql
useradd -r -g mysql -s /bin/false mysql
[Because the user is required only for ownership purposes, not login purposes, the useradd command uses the -r and -s /bin/false options to create a user that does not have login permissions to your server host.]
chown -R mysql:mysql /opt/mysql8
chmod 750 /opt/mysql8
[add mysql bin in PATH variable by editing /etc/environment]

Initialize with : mysqld –initialize –user=mysql

If you see lib errors, run below:
apt-get install libaio1 libaio-dev
apt-get install libnuma-dev

If succeeds copy the temporary password, generated during start up.
Start mysql with:
mysqld_safe –user=mysql &
login with root and the temporary password generated.

Change the password like so:
ALTER USER ‘root’@’localhost’ IDENTIFIED BY ‘root-password’;