MySQL

How to install MySQL on Ubuntu

In this tutorial, we are going to see how to install MySQL on Ubuntu. MySQL is the most popular open-source DBMS. It’s fast, easy to use, and scalable.
 

Step 1: Update the repository index

To install the latest available version of a software from the Internet repositories, your local repository must be up to date. Run the following command as sudo to update your local repository index:

$ sudo apt-get update


 

 

Step 2: Install MySQL Server with APT

Run the following command as sudo in order to install MySQL from the APT repositories.

$ sudo apt-get install mysql-server


 
Enter Y then press Enter; MySQL will then be installed on your system. However, the process can take some time.
 

Step 3: Check the installation

You can check your MySQL installation and also check the version number by running the following command in your terminal:

$ mysql --version


 

 

Step 4: Security Configuration

Run the following command to adjust the security on MySQL server:

$ sudo mysql_secure_installation


 
It will provide you some security options that you should choose in order to secure the MySQL server:

The first thing to do is to configure the “Validate Password” plugin. This allows you to set a secure password for the root user depending on the strength of the password you want to choose. Enter Y to run the “Validate Password” plugin and you will get the following prompt:
 

 
Enter your choice number for the password strength and press Enter. The system will then prompt you for the new root password. Enter and retype the password.
 

 
The system will display the strength of the password you provided and will also ask you if you want to continue with the password. Enter Y for Yes and press Enter.

The system will now ask you a series of questions, and you can set the security of your system based on your answers to these questions.

The first question will ask you if you want to delete anonymous users. (Press y and press Enter.)
 

 

 
The second question: Disallow root login remotely? (Press y and press Enter.)
 

 
The third question: Remove test database and access to it? (Press y and press Enter.)
 

 
The fourth question: Reload privilege tables now? (Press y and press Enter.)
 

 

Step 5: Manage MySQL server via Systemd

MySQL service is automatically started once it is configured. To check if the MySQL server is running or not, use this command:

$ sudo systemctl status mysql


 
If you find that MySQL server does not start automatically, you can use the following command to start it:

$ sudo systemctl start mysql

And start it automatically when the system starts:

$ sudo systemctl enable mysql

 

 

Step 6: Connect to MySQL server

To connect to MySQL server, use this command:

$ sudo mysql -u root -p


 
It will ask you for the password of the root account. You enter the password and press Enter.

Use SHOW DATABASES command to display all the databases on the current server:

$ mysql> show databases;


mcqMCQPractice competitive and technical Multiple Choice Questions and Answers (MCQs) with simple and logical explanations to prepare for tests and interviews.Read More

Leave a Reply

Your email address will not be published. Required fields are marked *