Bobcares

Install MySQL on Linode

by | Mar 22, 2022

Wondering how to Install MySQL on Linode? We can help you.

At Bobcares, we offer solutions for every query, big and small, as a part of our Server Management Service.

Let’s take a look at how our Support Team assist with this query.

How to Install MySQL on Linode?

MySQL is available as part of the default Ubuntu packages, so it is not necessary to edit the source list.

It can easily install using apt, but it is important to secure the application and edit the firewall afterwards.

These instructions are geared towards Ubuntu users, but are generally applicable for those who want to install MySQL on another Linux distribution.

Download MySQL

To install the MySQL server on Ubuntu, follow the steps below:

  1. Firstly, install the MySQL server application. sudo apt install mysql-server
  2. Confirm the MySQL server is running using the systemctl command.

It should display a status of active.

sudo systemctl status mysql
mysql.service - MySQL Community Server Loaded: loaded
(/lib/systemd/system/mysql.service; enabled; vendor preset:> Active:
active (running) since Thu 2021-09-09 12:24:29 UTC; 1h 44min ago

Configure the MySQL Server on Linux

The mysql_secure_installation utility is the easiest way to configure the application.

To use the set-up script, Support Techs follow these steps:

  • Firstly, launch the mysql_secure_installation utility to set the root password and configure other default options.

sudo mysql_secure_installation

  • The application asks whether to turn on the VALIDATE PASSWORD COMPONENT component.

If you answer y, it then asks whether to set the password strength to LOW, MEDIUM, or HIGH.

VALIDATE
PASSWORD COMPONENT can be used to test passwords and improve security.
It checks the strength of password and allows the users to set only
those passwords which are secure enough. Would you like to setup
VALIDATE PASSWORD component?

  • At the next prompt, the utility asks for a password for the root account. Set the password and then re-enter it.

Please set the password for root here. New password: Re-enter new password:

  • The following questions ask whether to remove anonymous users, to allow the root account to connect remotely, and to remove the test database.

Enter y or n at each prompt according to your preferences.

The test database is useful during initial validation, but for security reasons, it is best to disallow the root account from logging in remotely.

By
default, a MySQL installation has an anonymous user, allowing anyone to
log into MySQL without having to have a user account created for them.
This is intended only for testing, and to make the installation go a bit
smoother. You should remove them before moving into a production
environment. Remove anonymous users? (Press y|Y for Yes, any other key
for No) : Normally, root should only be allowed to connect from
'localhost'. This ensures that someone cannot guess at the root password
from the network. Disallow root login remotely? (Press y|Y for Yes, any
other key for No) : By default, MySQL comes with a database named
'test' that anyone can access. This is also intended only for testing,
and should be removed before moving into a production environment.
Remove test database and access to it? (Press y|Y for Yes, any other key
for No

  • When prompted, reload the privilege tables to update the database.

Reloading
the privilege tables will ensure that all changes made so far will take
effect immediately. Reload privilege tables now? (Press y|Y for Yes,
any other key for No) y Success. All done!

  • Finally, to access MySQL remotely, ensure MySQL traffic is allowed through the ufw firewall.
  • Add the following rule to open port 3306 on the firewall. This rule should not be added if remote access is not required.
ufw allow mysql

Log in to MySQL as the Root User

Although the root user has full access to the MySQL database, its use should be reserved for administrative purposes.

This reduces the chance of accidentally overwriting critical sections of the database.

Even in a single-user setup, a separate user account should be created for most MySQL activities.

To access the MySQL server as the root user and create a new user account, follow these steps:

  • Firstly, use the sudo mysql command to access the database. MySQL authenticates the root user based on their root credentials when logging in locally, so no password is require.

Alternatively, access the root account using sudo mysql -u root -p, along with the root password.sudo mysql

  • MySQL displays the release number and some information about the installation and then presents the MySQL prompt.

Welcome
to the MySQL monitor. Commands end with ; or \g. Your MySQL connection
id is 15 Server version: 8.0.26-0ubuntu0.20.04.2 (Ubuntu) ... mysql>

  • Then, to confirm MySQL is operating correctly, use the SHOW DATABASES command to display all the databases.

SHOW DATABASES; +--------------------+
| Database | +--------------------+ | information_schema | | mysql | |
performance_schema | | sys | +--------------------+ 4 rows in set (0.01
sec)

  • Create a new user using the CREATE USER command.

Enter the user name in the format 'username'@'IP_Address', where IP_Address is the IP address of the user.

If the user is accessing MySQL from the local Linode, substitute localhost in place of the IP Address.

In the command below, replace mysqluser and password with the actual user name and password.NoteMySQL offers several different authentication mechanisms.

The caching_sha2_password method is recommended for users who want to log in using a password and is used here.

However, certain older applications might not be able to authenticate properly this way. In that case, mysql_native_password should be used instead.

MySQL source-replica replication might require the sha256_password method.CREATE USER 'mysqluser'@'localhost' IDENTIFIED WITH caching_sha2_password BY 'password';

  • Grant access to the new user using the GRANT PRIVILEGE command, using the format GRANT list of privileges ON table TO 'username'@'IP_Address';.

Some of the more common privileges include CREATE, ALTER, DROP, INSERT, UPDATE, DELETE, and SELECT.

To apply these privileges to all databases, use the wildcard variable *.*.

The following command grants common non-administrative privileges on all databases to mysqluser.GRANT
CREATE, ALTER, DROP, INSERT, UPDATE, DELETE, SELECT, REFERENCES, RELOAD
ON *.* TO 'mysqluser'@'localhost' WITH GRANT OPTION;

  • Finally, to exit the MySQL prompt, type exit.exit

Installing MySQL on CentOS

MySQL is a popular database management system used for web and server applications.

However, MySQL is no longer in CentOS’s repositories and MariaDB has become the default database system offered.

Install MySQL

MySQL must installed from the community repository.

  • Download and add the repository, then update.

wget
http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm sudo rpm
-ivh mysql-community-release-el7-5.noarch.rpm yum update

  • Install MySQL as usual and start the service. During installation, you will be asked if you want to accept the results from the .rpm file’s GPG verification.
  • If no error or mismatch occurs, enter y.sudo yum install mysql-server sudo systemctl start mysqld

MySQL will bind to localhost (127.0.0.1) by default.

 
Harden MySQL Server
  1. Run the mysql_secure_installation script to address several security concerns in a default MySQL installation.

sudo mysql_secure_installation

You will given the choice to change the MySQL root password, remove anonymous user accounts, disable root logins outside of localhost, and remove test databases. It is recommend that you answer yes to these options

[Looking for a solution to another query? We are just a click away.]

 

Conclusion

To sum up, our skilled Support Engineers at Bobcares demonstrate how to Install MySQL on Linode

PREVENT YOUR SERVER FROM CRASHING!

Never again lose customers to poor server speed! Let us help you.

Our server experts will monitor & maintain your server 24/7 so that it remains lightning fast and secure.

GET STARTED

0 Comments

Submit a Comment

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

Never again lose customers to poor
server speed! Let us help you.