How to install MySQL server on Ubuntu?

From LHYcloud Docs
Jump to navigation Jump to search

System Requirements

CPU: 1 Cores minimum, 2 Cores recommended

RAM: 1GB minimum, 2GB recommended

Storage: 10GB available minimum

User: root (Use sudo in front of every command if you are not the root user)

Prerequisites

  • Deploy a new Ubuntu server of any version

Installing MySQL

  • Update and install updates: apt update && sudo apt upgrade -y (OPTIONAL)
  • Install the MySQL-server package: apt install mysql-server -y
  • After installation, use the following command to secure your installation: mysql_secure_installation
Securing the MySQL server deployment.

Connecting to MySQL using a blank password.

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?

Press y|Y for Yes, any other key for No:
  • If you want to use the "VALIDATE PASSWORD COMPONENT" type Y otherwise N, then press enter.

Configure "VALIDATE PASSWORD COMPONENT" (Optional)

There are three levels of password validation policy:

LOW    Length >= 8
MEDIUM Length >= 8, numeric, mixed case, and special characters
STRONG Length >= 8, numeric, mixed case, special characters and dictionary  file

Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG:

We will use LOW so we type 0 and press enter.

Set the password for the root user

Please set the password for root here.

New password: unthinkablePassword

Re-enter new password: unthinkablePassword

Enter your password, press enter and re-enter your password, then again press enter.

If you have set up the "VALIDATE PASSWORD COMPONENT" press y now.

Remove anonymous user

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) : Y

Type Y, then press enter

Configure root remote root login

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) :

You have to choose this by yourself! If you want to access remotely type n and press enter if not type y and press enter.

Remove the test database

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) : Y

Type Y, then press enter

 - Dropping test database...
Success.

 - Removing privileges on test database...
Success.

Reload privilege tables

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

Type Y, then press enter

Success.

All done!

Remote Access setup (OPTIONAL)

You should need this if you want to access remotely to your database. For example if u run a gameserver on server A and your database runs on server B you need to enable.

Open the config file with an editor of your choice: nano /etc/mysql/mysql.conf.d/mysqld.cnf

Find the following line:

bind-address           = 127.0.0.1

and change it to:

bind-address = 0.0.0.0

to bind to all available IP addresses connected to the server.

Restart MySQL service now using: service mysql restart

References

https://dev.mysql.com/doc/mysql-apt-repo-quick-guide/en/