
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

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.
Step-by-Step MySQL Installation on Ubuntu 22
Installing MySQL on Ubuntu 22 is a straightforward process. Follow these steps to ensure a successful setup:
- Update Your System: Ensure your system is up-to-date with
sudo apt update && sudo apt upgrade. - Install MySQL Server: Use
sudo apt install mysql-serverto install the MySQL package. - Secure MySQL Installation: Run
sudo mysql_secure_installationto set up security options. - Verify MySQL Service: Check MySQL status with
sudo systemctl status mysql.
MySQL vs. Other Databases
Choosing the right database is crucial for your application’s performance. Here’s a quick comparison:
| Feature | MySQL | PostgreSQL | SQLite |
|---|---|---|---|
| Performance | High for read-heavy | High for complex queries | Lightweight |
| Scalability | Excellent | Excellent | Limited |
| ACID Compliance | Yes | Yes | Yes |
FAQ
What are the prerequisites for installing MySQL on Ubuntu?
Ensure your system is updated and you have administrative privileges. Also, a stable internet connection is required for package downloads.
How do I start the MySQL service on Ubuntu?
Use the command sudo systemctl start mysql to start the MySQL service. Verify it’s running with sudo systemctl status mysql.
Can I install MySQL on a Rackset VPS?
Yes, Rackset’s VPS solutions provide the necessary environment to install and run MySQL efficiently. Explore our VPS hosting options to get started.
Optimizing MySQL Configuration on Ubuntu
Once MySQL is installed on your Ubuntu system, optimizing its configuration is crucial for ensuring optimal performance and resource utilization. The default settings may not be suitable for all use cases, especially in production environments. Here are some key parameters to consider adjusting in the my.cnf file, typically located in /etc/mysql/.
- max_connections: This parameter determines the maximum number of simultaneous connections that MySQL can handle. For high-traffic applications, increasing this value can prevent connection errors.
- query_cache_size: Setting an appropriate query cache size can significantly enhance performance by storing the results of frequently executed queries. However, excessive cache size can lead to inefficiencies, so balance is key.
- innodb_buffer_pool_size: For InnoDB storage engines, this parameter should be set to about 70-80% of available RAM to maximize data throughput and minimize disk I/O.
After making changes, restart the MySQL service with sudo systemctl restart mysql to apply the new settings.
Securing MySQL Installation
Security is a paramount consideration when deploying MySQL on Ubuntu. Following best practices can help safeguard your databases from unauthorized access and potential breaches.
- Run the MySQL Secure Installation Script: This script assists in configuring basic security settings such as removing anonymous users, disallowing remote root login, and setting a strong root password. Execute it with
sudo mysql_secure_installation. - Regularly Update MySQL: Keeping your MySQL installation up to date with the latest security patches is crucial. Use
sudo apt updateandsudo apt upgraderegularly to ensure your system is protected. - Firewall Configuration: Use
ufwto restrict access to MySQL ports. Allow only trusted IP addresses to connect by configuring rules such assudo ufw allow from 192.168.1.0/24 to any port 3306.
Troubleshooting Common MySQL Installation Issues
While installing MySQL on Ubuntu is generally straightforward, you may encounter some common issues. Understanding these and knowing how to resolve them can save time and frustration.
- MySQL Service Fails to Start: This could be due to incorrect configuration settings or port conflicts. Check the error log at
/var/log/mysql/error.logfor specific messages. Correct any configuration errors inmy.cnfand ensure no other services are using port 3306. - Access Denied for User ‘root’@’localhost’: This can occur if the root password is not set correctly. Reset it by stopping the MySQL server and starting it with the
--skip-grant-tablesoption, then update the root password using the MySQL shell. - Unable to Connect Remotely: Ensure that MySQL is configured to listen on the appropriate network interfaces by checking the
bind-addresssetting inmy.cnf. Also, verify that firewall rules allow remote connections.
Comparing MySQL with Alternative Databases on Ubuntu
MySQL is a popular choice for many developers, but there are other databases available on Ubuntu that might better suit specific needs. Here’s a quick comparison of MySQL with PostgreSQL and MariaDB, two other widely-used databases.
| Feature | MySQL | PostgreSQL | MariaDB |
|---|---|---|---|
| Performance | Optimized for read-heavy operations | Strong in complex queries and write-heavy operations | Improved performance over MySQL, especially in newer versions |
| License | GPL with commercial options | Open Source (PostgreSQL License) | GPL |
| Community Support | Large community with extensive resources | Growing community with strong support for advanced features | Community-driven fork of MySQL |
Choosing the right database involves considering factors such as the complexity of queries, licensing requirements, and community support. Each option has its strengths and is well-supported on Ubuntu systems.
Leave a Reply