Linux MintUbuntu Based

How To Install MySQL on Linux Mint 22

Install MySQL on Linux Mint 22

In this tutorial, we will show you how to install MySQL on Linux Mint 22. MySQL is a powerful open-source relational database management system widely used for web applications and data warehousing. Its reliability, performance, and ease of use have made it a popular choice among developers and system administrators.

This article assumes you have at least basic knowledge of Linux, know how to use the shell, and most importantly, you host your site on your own VPS. The installation is quite simple and assumes you are running in the root account, if not you may need to add ‘sudo‘ to the commands to get root privileges. I will show you the step-by-step installation of the MySQL database on Linux Mint 22.

Prerequisites

  • A server running one of the following operating systems: Linux Mint 22.
  • It’s recommended that you use a fresh OS install to prevent any potential issues.
  • While we’ll guide you through the process, a basic understanding of the command line will be beneficial. If you’re new to the CLI, you might want to acquaint yourself with some fundamental commands.
  • An active internet connection.
  • Administrative privileges are essential for installing and configuring software on your system. Ensure that you have superuser or sudo access.

Install MySQL on Linux Mint 22

Step 1. Update Your Linux Mint System.

To begin, update your system packages to ensure you have the latest versions available. Open a terminal and run the following command:

sudo apt update
sudo apt upgrade

This command retrieves the latest package information from the repositories, allowing you to install the most recent versions of MySQL and its dependencies.

Step 2. Installing MySQL.

With the package list updated, you can now install the MySQL server. Execute the following command in the terminal:

sudo apt install mysql-server

The package manager will resolve any dependencies and prompt you to confirm the installation. Press ‘Y’ and hit Enter to proceed.

During the installation process, you may be asked to set a root password for MySQL. Choose a strong, secure password and remember it for future use.

Step 3. Start and Enable MySQL Service.

Once the installation is complete, start the MySQL service and enable it to automatically start on system boot. Run the following commands:

sudo systemctl start mysql
sudo systemctl enable mysql

These commands ensure that the MySQL service is running and will start automatically whenever your Linux Mint system boots up.

To verify that MySQL is installed correctly, check the service status by running:

sudo systemctl status mysql

If the installation was successful, you should see an output indicating that the MySQL service is active and running.

Additionally, you can check the MySQL version installed by executing:

mysql --version

Step 4. Secure MySQL Installation

MySQL comes with a security script that helps you enhance the security of your installation. Run the following command:

sudo mysql_secure_installation

This script will guide you through several security-related options:

  • Setting a root password (if not set during installation)
  • Removing anonymous users
  • Disallowing remote root login
  • Removing test databases
  • Reloading privilege tables

Follow the prompts and answer ‘Y’ to the questions to secure your MySQL installation.

Step 5. Configure MySQL.

To configure MySQL according to your requirements, you can modify the MySQL configuration file. The default configuration file is located at /etc/mysql/mysql.conf.d/mysqld.cnf.

Use a text editor with sudo privileges to open the file:

sudo nano /etc/mysql/mysql.conf.d/mysqld.cnf

In this file, you can adjust various settings such as port number, data directory, logging, and performance-related options. Make sure to uncomment (remove the ‘#’ at the beginning of the line) and modify the values as needed.

For the configuration changes to take effect, restart the MySQL service using the following command:

sudo systemctl restart mysql

Step 6. Create a MySQL User and Database.

To create a new MySQL user and database, follow these steps:

sudo mysql -u root -p

Create a new database:

CREATE DATABASE mydatabase;

Create a new user and grant privileges:

CREATE USER 'myuser'@'localhost' IDENTIFIED BY 'mypassword';
GRANT ALL PRIVILEGES ON mydatabase.* TO 'myuser'@'localhost';
FLUSH PRIVILEGES;

Exit the MySQL shell:

EXIT;

You have now created a new MySQL user and database that you can use for your applications.

Step 7. Test MySQL Connection.

To test the MySQL connection and ensure that everything is working correctly, log in to the MySQL shell using the newly created user:

mysql -u myuser -p

Enter the password for the user when prompted. If the login is successful, you will be presented with the MySQL shell prompt.

Try executing a simple SQL query to verify that you can interact with the database:

USE mydatabase;
CREATE TABLE test (id INT, name VARCHAR(255));
INSERT INTO test VALUES (1, 'John Doe');
SELECT * FROM test;

If the query executes successfully and you see the inserted data, your MySQL installation and configuration are working correctly.

Step 8. Troubleshooting Common Issues.

If you encounter any issues during the installation or configuration process, here are a few common problems and their solutions:

    1. Access denied for user ‘root’@’localhost’: This error occurs when the root password is incorrect or not set properly. Reset the root password by following the official MySQL documentation.
    2. MySQL service fails to start: Check the MySQL error log located at /var/log/mysql/error.log for any specific error messages. Ensure that the configuration file is properly formatted and contains no syntax errors.
    3. Insufficient privileges: If you receive errors related to insufficient privileges when creating users or databases, make sure you are logged in as the root user or a user with the necessary privileges.

Congratulations! You have successfully installed MySQL. Thanks for using this tutorial to install the latest version of the MySQL database on the Linux Mint system. For additional help or useful information, we recommend you check the official MySQL website.

VPS Manage Service Offer
If you don’t have time to do all of this stuff, or if this is not your area of expertise, we offer a service to do “VPS Manage Service Offer”, starting from $10 (Paypal payment). Please contact us to get the best deal!

r00t

r00t is a seasoned Linux system administrator with a wealth of experience in the field. Known for his contributions to idroot.us, r00t has authored numerous tutorials and guides, helping users navigate the complexities of Linux systems. His expertise spans across various Linux distributions, including Ubuntu, CentOS, and Debian. r00t's work is characterized by his ability to simplify complex concepts, making Linux more accessible to users of all skill levels. His dedication to the Linux community and his commitment to sharing knowledge makes him a respected figure in the field.
Back to top button