How to Install MySQL on Linux (Ubuntu)

How to Install MySQL on Linux (Ubuntu)

Installing MySQL on Linux (Ubuntu)

Step 1: Update Package Lists

Open a terminal and run the following commands to make sure that the package lists are up-to-date:

Bash
sudo apt update

Step 2: Install MySQL Server

Next, use the following command to install the MySQL server:

Bash
sudo apt install mysql-server

During the installation process, you will be prompted to set a root password for MySQL.

Step 3: Start and Enable MySQL

After the installation is complete, start the MySQL service and enable it to start on boot with:

Bash
sudo systemctl start mysql
sudo systemctl enable mysql

Step 4: Configure MySQL Security

Run the MySQL security script to improve the security of your MySQL installation:

Bash
sudo mysql_secure_installation

This script will prompt you to perform several actions like setting a new root password, removing anonymous users, and disallowing remote root login.

Step 5: Access MySQL Shell

To access the MySQL shell, use the following command and enter the root password you set during the installation:

Bash
sudo mysql -u root -p

Step 6: Create Additional Users (Optional)

You can create additional MySQL users if needed. This is recommended for better security.

Bash
CREATE USER 'username'@'localhost' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON *.* TO 'username'@'localhost' WITH GRANT OPTION;

Replace 'username' with the desired username and 'password' with a strong password.

Step 7: Install MySQL Client (Optional)

If you need to connect to MySQL from a remote machine, you can install the MySQL client:

Bash
sudo apt install mysql-client

Step 8: Verify Installation

You can verify the installation by accessing MySQL from the command line or by using a MySQL client.

That’s it! You now have MySQL installed on your Ubuntu Linux system. You can start creating databases and tables, and using MySQL for your applications.

Total
1
Shares

Leave a Reply

Previous Post
How to Install MySQL on Windows

How to Install MySQL on Windows

Next Post
How to Create a MySQL Database

How to Create a MySQL Database

Related Posts