How to install MySQL on Ubuntu

Install MySQL ubuntu phpMyAdmin

There are several database management systems, but many opt for Microsoft Access, as always, because it is from Microsoft and is part of its office suite. Many others, since managing databases is a task done by knowledgeable people, are aware of the open source option which, from what I have seen, is the choice of many companies. Here we are going to teach you install mysql in Ubuntu.

If we are on Windows, installing MySQL is a simple task if you know what to install, since there are packages that include everything. In Linux it is not the same, and it is a little more complicated because a lot is done with command lines. Today we are going to try to explain how to install MySQL in Ubuntu, although it can also be said that what we will install will be LAMPie Linux, Apache, MySQL and PHP.

Before starting

MySQL is a tool without a graphical interface that works from the terminal by command line (CLI). Its installation is rather simple, but only with MySQL would we have to carry out all the queries from the terminal. To improve the user experience, you must also install and configure phpMyAdmin. This is what complicates things a bit. Depending on how it is configured, we can enter phpMyAdmin or we will find one of the many errors that it can show us.

It also seems important to me to mention that what is described here works at the time of writing this article, and has been tested on Ubuntu 22.10. Seeing as there are no packages or anything special, it should work in past and future versions, but it's not guaranteed. So, if you run into any bugs, I would recommend going back to what you did to find this article (if you didn't find it on social media): search for the specific bug on Google Duckucko

How to install MySQL on Ubuntu

With the above explained, let's go with the steps to follow to install LAMP together with phpMyAdmin and make everything work in Ubuntu.

  1. To make sure everything is up to date, we update all packages, either from Software Update or with the command sudo apt update && sudo apt upgrade.
  2. As an optional step, we go to the browser and put "localhost", making sure to remove the S from HTTPS if it does. We will see an error because there is no server doing its job.

localhost not working

  1. We go to the terminal and install the A of LAMP: Apache.
sudo apt install apache2
  1. As another optional step, which are not important but indicate that we are doing well, we return to the browser, put "localhost" and verify that now something like the following appears:

localhost working

  1. Next we install MySQL, the M of LAMP:
sudo apt install mysql-server
  1. In the next step, if we do not have it, we install the P of LAMP (PHP):
sudo apt install php

And with this we would have everything necessary to use MySQL in Ubuntu. To improve the user experience, we continue.

Install phpMyAdmin on Ubuntu

  1. In the terminal, we write:
sudo apt install phpmyadmin
  1. There will come a time when it will ask us for the server to use. We choose apache2 with the space bar, then tab and OK.

phpmyadmin server

  1. It will notify us that it is necessary to have an active database, and if we want to manage it with dbconfig-common. We accept the first window, which does not offer more options, and we go to the second, we say yes and we put a password to phpMyAdmin (twice):

dbconfig-common

Set phpMyAdmin password

  1. We go back to the browser and add “phpmyadmin” to “localhost”, which would be localhost/phpmyadmin.

phpMyAdmin login

  1. We do another check: we put the default user, which is phpmyadmin, and the password that we have configured in step 10. We will see that it enters, but we do not have privileges.

phpMyAdmin without privileges

  1. We close the session in phpMyAdmin.

Sign off

  1. We return to the terminal, write sudo -i (or sudo su) and put our password.
  2. Now we write mysql -u root -py we put the password of phpMyAdmin (the one from step 10).

enter mysql

  1. There's nothing left. In the next step we are going to create a user (1), changing 1234 for another password (which must go between the single quotes) and ubunlog for your user, we give it privileges (2) and restart them (it will be confirmed that it went well with the "Query OK" message after each intro):
create user 'ubunlog'@'%' identified by '1234'; grant all privileges on *.* to 'ubunlog'@'%' with grant option; flush privileges;

And that would be all. It remains to go back to the browser, refresh the login/phpmyadmin page and verify that we can enter with the created user, and also that we can manage the databases.

Manage databases in phpMyAdmin on Ubuntu

Hiding databases and changing the theme

Now that we can manage the databases, we may want to do it our own way. On the main page we find the “Theme” option, and depending on the operating system where we have phpMyAdmin installed, 3 or 4 options may appear. Although there are not many, there are alternatives in phpmyadmin.net/themes, and, for example, the following is BooDark (Dark Bootstrap):

BooDark Theme

The themes have to be unzipped and put the folder inside the themes folder that will be inside the phpmyadmin folder (in Ubuntu it is usually /usr/share/phpmyadmin/themes).

On the other hand, if you have noticed, you will have noticed that to the left of the BooDark screenshot there are fewer databases than in the screenshot above. That's because they are hidden. The theory says that they are databases with configuration files and that it is worth not touching anything there, but we can hide them, that everything will continue to work as when they are visible.

To hide them, and thus work only with our databases, we can open Files, go to other locations, enter the root of our hard drive, hit the magnifying glass, search for phpmyadmin, enter the folder and open the config.inc file. .php. At the end you can add a line like the following:

$cfg['Servers'][$i]['hide_db'] = '^mysql|sys|phpmyadmin|performance_schema|information_schema$';

From the above, we are using the option to hide databases (hide_db) and indicating which ones we do not want to see. The string starts and ends with single quotes; within it, the first symbol must be "^" and the last "$"; and inside are the databases separated by "|". If you happen to notice something strange, although you shouldn't, you can "comment out" that line by putting two slashes (//) before it or putting it between /*…*/.

Managing databases with LibreOffice Base

As we have explained at the beginning of this article, what is really necessary to use MySQL in Ubuntu is done in about 7 steps. If we then manage with the terminal, nothing else is needed. With phpMyAdmin we will do it with a graphical interface, one that is usually available in hosting services, so it is worth getting used to it before anything else. But you can also manage databases with other software.

For example, just as we have Access in Microsoft 365, LibreOffice has Base. And yes, we can connect to MySQL databases with Base, sort of. Although it is true that we can add tables to the database, it is also true that it does not allow us to edit the tables that we have created from phpMyAdmin, so it is worthwhile that, if we are going to work with Base, we create the database with MySQL, let's connect to it and then manage the tables from Base. As for the SQL queries, only those to obtain information are allowed; if we want to make changes, we must do it through the graphical interface.

To do this, once we have installed all of LAMP (Linux is already there, Apache, MySQL and PHP), we have to follow these steps:

  1. We open LibreOffice Base. A wizard will be shown to us.
  2. In the first window, we choose “Connect to an existing database”, drop down the menu and choose “MySQL/MariaDB”.

Create Database with LibreOffice Base

  1. In the next window, we choose “Connect directly (via MariaDB C connector)” and click next:

Connect using MariaDB

  1. Next, we put the name of the database and the server. The database will be the one we want to connect to, and the server is localhost.

Database data

  1. After clicking on next, we will put the username and, with the “Required password” box checked, we will click on test the connection.

Test the connection

  1. It will ask us for the password (of the MySQL user), we put it. If everything goes well, we will see a message confirming that the connection has been successful.
  2. We click on next and we will see a last window in which it is worth leaving things by default and clicking on “Finish”.

Save database

This will allow us to access the database from LibreOffice Base, but I would only use it if something native is needed and for basic management. Also if you prefer to work with something that looks better on your desktop, such as GTK in Ubuntu or Qt in other graphical environments.

Among the other options, one of the favorites is DBeaver, which has an open source Community option, but using one or the other should already be a matter of taste. That and that probably in a job they ask you to move well in phpMyAdmin.

And this is how you can install MySQL on Ubuntu and manage the databases with a graphical interface from Ubuntu.


A comment, leave yours

Leave a Comment

Your email address will not be published. Required fields are marked with *

*

*

  1. Responsible for the data: Miguel Ángel Gatón
  2. Purpose of the data: Control SPAM, comment management.
  3. Legitimation: Your consent
  4. Communication of the data: The data will not be communicated to third parties except by legal obligation.
  5. Data storage: Database hosted by Occentus Networks (EU)
  6. Rights: At any time you can limit, recover and delete your information.

  1.   Francisco Velasco said

    Great, I had been looking for information for the installation of MySQL for days and this email arrived on time with the steps