Wednesday, March 18, 2020

Install Mysql server on ubuntu 18.04.4 LTS

MySQL is one of the most popular open-source relational database management systems. It’s widely used in web applications, enterprise software, and data-driven projects.

This will show you how to install MySQL Server on Ubuntu 18.04.4 LTS, set the root password, and verify the installation.

Step 1: Update Package Index

Open a terminal and update your system’s package index:

sudo apt update

Step 2: Install MySQL Server

Install MySQL Server package:

sudo apt install mysql-server


The installation will automatically start the MySQL service.

No password is required during installation as the default authentication plugin is auth_socket.

Step 3: Verify MySQL Installation

Exit the current terminal and open a new terminal, then try logging in:

mysql


You may get the error:

ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)


This happens because MySQL on Ubuntu 18.04 uses auth_socket by default, which requires the root user to log in via the system user account.

Step 4: Log in as Root

Use sudo to access MySQL as root:

sudo mysql

Step 5: Set Root Password

Once inside the MySQL shell, run the following command to set a root password and switch to the mysql_native_password plugin:

ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'your_password';


Replace 'your_password' with a strong password of your choice.

Step 6: Apply Changes

Flush privileges so the changes take effect:

FLUSH PRIVILEGES;

Step 7: Verify MySQL Access

Now, you can log out of MySQL and log in again using the root password:

mysql -u root -p


Enter your password when prompted. Then verify your databases:

SHOW DATABASES;


You should see the default MySQL databases like mysql, information_schema, performance_schema, etc.