MySQL is an open-source, fast reliable, and flexible relational database management system, typically used with PHP. In this article, we are going to learn how to install MySQL 8 on Ubuntu 22.04. So, let’s get started.
A system with Ubuntu 23.10 installed and running.
rootor sudo user access to the system.
Once you're all set, we'll proceed with MySQL 8 installation and configuration.
Let's install MySQL 8 using the below commands.
apt update apt -y install mysql-server
Finally, you will want to secure your MySQL installation by issuing the following command.
root@ubuntu23:~# 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: y 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: 2 Skipping password set for root as authentication with auth_socket is used by default. If you would like to use password authentication instead, this can be done with the "ALTER_USER" command. See https://dev.mysql.com/doc/refman/8.0/en/alter-user.html#alter-user-password-management for more information. 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 Success. 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) : y Success. 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 - Dropping test database... Success. - Removing privileges on test database... Success. 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!
To check the database server status.
systemctl status mysql
root@ubuntu23:~# systemctl status mysql ● mysql.service - MySQL Community Server Loaded: loaded (/lib/systemd/system/mysql.service; enabled; preset: enabled) Active: active (running) since Fri 2023-10-20 13:41:23 UTC; 1min 17s ago Process: 2650 ExecStartPre=/usr/share/mysql/mysql-systemd-start pre (code=exited, status=0/SUCCESS) Main PID: 2658 (mysqld) Status: "Server is operational" Tasks: 39 (limit: 2226) Memory: 363.3M CPU: 3.758s CGroup: /system.slice/mysql.service └─2658 /usr/sbin/mysqld Oct 20 13:41:20 ubuntu23 systemd: Starting mysql.service - MySQL Community Server... Oct 20 13:41:23 ubuntu23 systemd: Started mysql.service - MySQL Community Server.
Let us begin with creating a Database and a user. We will then grant the required privileges to the user so it can interact with the Database:
mysql CREATE USER 'test_user_crowncloud'@'localhost' IDENTIFIED BY "Password_crowncloud"; CREATE DATABASE test_db_crowncloud; GRANT ALL PRIVILEGES ON test_db_crowncloud.* TO 'test_user_crowncloud'@'localhost'; FLUSH PRIVILEGES; EXIT
The above commands will give complete access to the
test_db_crowncloudDatabase to the user
test_user_crowncloud.We would suggest using a strong and long password.
Check the version and newly created database using the below command,
root@ubuntu23:~# mysql -V mysql Ver 8.0.34-1ubuntu1 for Linux on x86_64 ((Ubuntu))
You can now connect to MySQL and review the existing databases on your database server by using the following command.
mysql -e "SHOW DATABASES;" -p
root@ubuntu23:~# mysql -e "SHOW DATABASES;" -p Enter password: +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | | sys | | test_db_crowncloud | +--------------------+
Now you have successfully installed MySQL 8 on Ubuntu 23.10.