How to Install MySQL on Ubuntu 22

how to install mysql on ubuntu

MySQL is an open-source management of database software that is typically used as part of the well-known LAMP (Linux, Apache, MySQL PHP/Python/Perl) stack. It utilizes the relational model and makes use of Structured Query Language (better known as SQL) to manage its database.

In this article, we’ll look at how to install MySQL 8.0 on Ubuntu 22.04. Keep in mind, you can also use the steps below to install MySQL 5.7 on Ubuntu 22.04. After completing the process, you’ll be able to create an operational relational database you can use to develop your next site or application. Since you Buy VPS Hosting Server with Ubuntu 22 to install MySQL 8.0.

 

Step 1: Install MySQL on Ubuntu

If you are using Ubuntu in order to run MySQL server 8.0.30, it is possible that you will need to install it through the APT repository for packages. MySQL, which is within the standard Ubuntu repository, has been upgraded to version 8.0. Be aware that this is a must when you’ve just purchased the best Linux VPS hosting service or have had your Linux server upgraded.

In order to install MySQL on Ubuntu, you must upgrade the index of packages on your server; if you’ve not done it in the past:

sudo apt update

 

Then, install then the mysql server package:

sudo apt-install mysql server

 

Check that your server is running with systemctl start. the systemctl startup command:

sudo systemctl start mysql.service

 

This command will set up and begin MySQL, but they will not ask you to enter an account password or make other changes to the configuration. Since this makes the installation process of MySQL vulnerable, in the next steps, we’ll discuss how to configure the server.

 

Step 2: Configuring MySQL

To install MySQL on Ubuntu, you’ll need to use this database management software’s security script. This script will alter certain more vulnerable default options to prevent remote root logins and disallowing sample users.

The security script should be run using sudo:

sudo mysql_secure_installation

It will walk the user through a sequence of questions that allow you to make adjustments in the MySQL installation’s security settings. The first prompt will ask if you’d like to install an application called the Validate Password Plugin, which can be used to verify the strength of the passwords of new MySQL users prior to determining whether they are legitimate.

If you choose to configure this Validate Password Plugin, any MySQL user that you create that authenticates using an account password will have to have a password that meets the requirements of the policy you have selected. No matter if you decide to install the Validate Password plugin, the next step is to create an account username and password for your MySQL username. Enter and verify a password that is secure to your preference.

It is important to note that even though you’ve entered an administrator password for your primary MySQL user, the user isn’t currently set to use the password to connect with MySQL. If you’re using the Validate Password plugin, you’ll get feedback on the quality of your new password. The script will then ask you if you would like to keep the password you’ve entered or whether you’d like to create a new password. If you’re satisfied with the security of the password that you entered, press Y to continue the process.

Then, click Y followed by Enter and accept default answers on each of the following questions. This will delete certain anonymous users as well as the test database, deactivate remotely-based root passwords and load the new rules in a way that MySQL immediately recognizes the changes you’ve made.

When the script has finished, the MySQL database will now be secure. It is now time to move on to create a dedicated database user using your MySQL client. This is required even with the most recent version of MySQL server version 8.0.30.

 

Step 3: Creating a Dedicated MySQL User and Granting Privileges

After installation, MySQL creates an initial user account that you can make use of for managing your databases. This account has complete privileges on all aspects of the MySQL server, which means that it controls each table, database user, etc. This is why it is best not to use this account for anything other than administrative functions. This guideline outlines how you can make use of the MySQL root account to set up an account as a user and then grant it access rights.

In Ubuntu systems that run MySQL 5.7 (and the subsequent version) root username is configured to authenticate with auth_socket as a plugin by default rather than to use a password. The plugin demands that the user’s name matches the user who invokes the MySQL client and is identical to the name of the MySQL user that is specified in the command. Consequently, you need to invoke mysql using sudo rights to be able to access MySQL’s user root MySQL username:

sudo mysql

 

Once you’ve got access to your MySQL interface, you are able to create a brand new user using the CREATE USER statement.

CREATE USER ‘username’@’host’ IDENTIFIED WITH authentication_plugin BY ‘password’;

After you create a user, when you click CREATE USER, you enter your username. The username is followed immediately by an @ symbol and then the hostname to which the user will connect. If you plan to only connect to this user locally on the local area of your Ubuntu server, you may use localhost. Enclosing both the username as well as the host into single quotation marks isn’t required, but it will help prevent mistakes.

There are a variety of options available in selecting the right authentication plugin for your user. The auth_socket plug-in mentioned earlier is an ideal choice since it offers strong security without having valid users create a password in order to gain access to the database. It also blocks remote connections that could make things more complicated when other programs require interaction with MySQL.

As an alternative, you can leave out the WITH authentication_plugin portion of the syntax entirely to have the user authenticate with MySQL’s default plugin, caching_sha2_password.

The following command can be used to create a user who authenticates using caching_sha2_password. You must ensure that you have changed nora with your username of choice and Password to a secure password that you can use:

CREATE USER ‘nora’@’localhost’ IDENTIFIED BY ‘password’;

Once you have created your user, you are able to assign them the appropriate rights. The standard syntax for granting users privileges is as follows:

Grant privilege on database.table to ‘username’@’host’

The PRIVILEGE value of this syntax defines the actions the user has the right to carry out on the specific table and database. You can give multiple rights to the same user with a single command by segregating each one with the use of a comma. You can also grant user rights globally by using the asterisks (*) in lieu of table and database names. In SQL, the asterisks are special characters used to signify “all” databases or tables.

For example, the following command allows a user to have global privileges to create, alter, and DROP tables, databases and users, along with the ability to insert or UPDATE records from every table that is on the server. The command also gives users the ability to search for data using SELECT, make foreign keys using the REFERENCES keyword, as well as execute FLUSH operations by using permissions to RELOAD. But, it is important to only allow users to access the privileges they require and are free to alter your privileges for users as required.

Take this GRANT statement, replacing nora using your personal MySQL username to give these privileges to your MySQL user:

GRANT CREATE, ALTER, DROP, INSERT, UPDATE, INDEX, DELETE, SELECT, REFERENCES, RELOAD on *. * TO ‘nora’@’localhost’ WITH GRANT OPTION;

This statement includes the WITH GRANT OPTION. This allows you to allow your MySQL client to assign permissions it may have to other users of the system.

 

Step 4: Testing MySQL

No matter how you installed it regardless of how you installed it, MySQL must have been running on its own. For confirmation, verify the status.

If MySQL isn’t working, then you can restart it by using sudo systemctl begin mysql.

Systemctl status mysql.service

If you want to test it further, you can connect to the database with the mysqladmin program, which is a client tool that allows you to run commands for administration. For instance, the command above will connect using the MySQL user with the name nora (-u nora) and prompt you for the password (-p) and provide the database version. Make sure that you change nora’s name to the name of your designated MySQL user, and then use the password of that user at the prompt.

 

Latest MySQL Version

what is mysql latest version
MySQL Server 8.0.30 and 5.7.39 MySQL New versions of the renowned Open Source Database Management System are now available together with the 8.0.30 Component and Connector products.

Windows packages are available through the Installer on Windows as well as .ZIP (no-install) Packages to meet more sophisticated requirements. The point-and-click wizards for setting up and configuration as well as every MySQL product are included in the Unified Installer for Windows.

 

Conclusion

Suppose you decide to buy a Linux VPS server to start an entirely new website or application. To build and publish both of them, it is necessary to have an area to keep the files. If you’re on Ubuntu to install the MySQL client, you’ll need to do this by using the apt install command. In this tutorial, we have covered the steps on how to install MySQL on Ubuntu 20.04.

Leave a Reply

Your email address will not be published.