Introduction
MySQL stands as one of the most ubiquitous database management systems, powering countless applications and websites across the digital landscape. Its versatility and reliability make it a cornerstone for developers and system administrators alike. However, to harness its power, one must first traverse the path of installation and configuration, a journey often met with a few hurdles.
In this comprehensive guide, we embark on a journey through the installation process of MySQL on Ubuntu, one of the most popular Linux distributions renowned for its stability and user-friendly environment. Additionally, we delve into the crucial task of resetting the root user’s password, an essential skill for maintaining security and access control within your MySQL environment.
Whether you’re a seasoned sysadmin or a budding developer, this article aims to demystify the installation process and empower you with the knowledge to navigate MySQL’s inner workings with confidence. Let’s embark on this journey together, unlocking the gateway to MySQL on Ubuntu and ensuring that you have the tools to manage your database effectively.
Install MySQL in UBUNTU
Updating Package Lists
Before installing any new software on your Ubuntu system, it’s essential to ensure that your package lists are up-to-date. To do this, open a terminal window and enter the following command and enter your password if needed:
sudo apt update
This command, prefixed with sudo for administrative privileges, updates the package lists for repositories configured in Ubuntu. It’s a necessary step to ensure that you’re installing the latest versions of software packages available for your system.
Installing MySQL Server
Once your package lists are updated, you’re ready to install the MySQL server package. Enter the following command in the terminal:
sudo apt install mysql-server
This command will prompt you to confirm whether you want to proceed with the installation. Type ‘y’ and press Enter to continue. The installation process will then begin, and Ubuntu will automatically download and install the MySQL server package and its dependencies.
Changing MySQL root password
Accessing MySQL and Setting Root Password
After the installation is complete, you can access the MySTo begin, open a terminal window and enter the following command to access the MySQL command-line interface with administrative privileges:QL database server through the command line. Enter the following command in the terminal:
sudo mysql
Once you’re in the MySQL command-line interface, execute the following command to alter the root user’s authentication method and set a password of your choice:
alter user 'root'@'localhost' identified with mysql_native_password by 'yourpassword';
Replace 'yourpassword'
with a strong password of your choice. This command ensures that the root user is authenticated using the MySQL native password authentication method.
After setting the password, you can exit the MySQL command-line interface by typing:
exit
Securing Your MySQL Installation on Ubuntu
Running mysql_secure_installation
Next, run the mysql_secure_installation script to further enhance the security of your MySQL installation. Enter the following command in the terminal:
sudo mysql_secure_installation
This script guides you through a series of security-related questions and actions. First, you’ll be prompted to enter the password for the root user. Once authenticated, follow the prompts:
During this process, you’ll have the option to change the password for the root user. If you’ve already set a password in initially, you can choose not to change it by pressing ‘n’. Press ‘y’ to remove anonymous users, which are users with no identified credentials.
Press ‘y’ to disallow root login remotely, limiting access to the root account to local connections.
Press ‘y’ to remove the test database and access to it, eliminating potential security risks associated with the test database.
Press ‘y’ to reload the privilege tables to apply the changes.