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

aptCopy Code
, 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-serverCopy Code
  2. Confirm the MySQL server is running using the
    systemctlCopy Code
    command.

It should display a status of

activeCopy Code
.
 
sudo systemctl status Copy Code
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 agoCopy Code

Configure the MySQL Server on Linux

The

mysql_secure_installationCopy Code
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_installationCopy Code
    utility to set the root password and configure other default options.
sudo mysql_secure_installationCopy Code
  • The application asks whether to turn on the
    VALIDATE PASSWORD COMPONENTCopy Code
    component.

If you answer

yCopy Code
, it then asks whether to set the password strength to
LOWCopy Code
,
MEDIUMCopy Code
, or
HIGHCopy Code
.
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?Copy Code
  • 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:Copy Code
  • The following questions ask whether to remove anonymous users, to allow the
    rootCopy Code
    account to connect remotely, and to remove the
    testCopy Code
    database.

Enter

yCopy Code
or
nCopy Code
at each prompt according to your preferences.

The

testCopy Code
database is useful during initial validation, but for security reasons, it is best to disallow the
rootCopy Code
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 NoCopy Code
  • When prompted, reload the
    privilegeCopy Code
    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!Copy Code
  • Finally, to access MySQL remotely, ensure MySQL traffic is allowed through the
    ufwCopy Code
    firewall.
  • Add the following rule to open port
    3306Copy Code
    on the firewall. This rule should not be added if remote access is not required.
     
ufw allow mysql
Copy Code

Log in to MySQL as the Root User

Although the

rootCopy Code
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

rootCopy Code
user and create a new user account, follow these steps:

  • Firstly, use the
    sudo mysqlCopy Code
    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 -pCopy Code
, along with the
rootCopy Code
password.
sudo mysqlCopy Code
  • 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>Copy Code
  • Then, to confirm MySQL is operating correctly, use the
    SHOW DATABASESCopy Code
    command to display all the databases.
SHOW DATABASES; Copy Code
+--------------------+
| Database | +--------------------+ | information_schema | | mysql | |
performance_schema | | sys | +--------------------+ 4 rows in set (0.01
sec)Copy Code
  • Create a new user using the
    CREATE USERCopy Code
    command.

Enter the user name in the format

'username'@'IP_Address'Copy Code
, where
IP_AddressCopy Code
is the IP address of the user.

If the user is accessing MySQL from the local Linode, substitute

localhostCopy Code
in place of the IP Address.

In the command below, replace

mysqluserCopy Code
and
passwordCopy Code
with the actual user name and password.NoteMySQL offers several different authentication mechanisms.

The

caching_sha2_passwordCopy Code
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_passwordCopy Code
should be used instead.

MySQL source-replica replication might require the

sha256_passwordCopy Code
method.
CREATE USER 'mysqluser'@'localhost' IDENTIFIED WITH caching_sha2_password BY 'password';Copy Code
  • Grant access to the new user using the
    GRANT PRIVILEGECopy Code
    command, using the format
    GRANT list of privileges ON table TO 'username'@'IP_Address';Copy Code
    .

Some of the more common privileges include

CREATECopy Code
,
ALTERCopy Code
,
DROPCopy Code
,
INSERTCopy Code
,
UPDATECopy Code
,
DELETECopy Code
, and
SELECTCopy Code
.

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

*.*Copy Code
.

The following command grants common non-administrative privileges on all databases to

mysqluserCopy Code
.
GRANT
CREATE, ALTER, DROP, INSERT, UPDATE, DELETE, SELECT, REFERENCES, RELOAD
ON *.* TO 'mysqluser'@'localhost' WITH GRANT OPTION;Copy Code

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 updateCopy Code
  • 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
    yCopy Code
    .
    sudo yum install mysql-server sudo systemctl start mysqldCopy Code

MySQL will bind to localhost (127.0.0.1) by default.

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

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

yesCopy Code
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 *

Speed issues driving customers away?
We’ve got your back!