Grafana is a very useful open-source data visualization and monitoring platform that can use data from a variety of sources and display it based of custom filters and alerts.

In this article, we will go through the setup of Grafana on a CentOS 7 system, using a MySQL database as a data source.

Install MySQL

Before installing any packages, run yum update in order to make sure that your system is up to date.

CentOS 7 uses MariaDB as the preferred database application, so MySQL can’t be installed from the default repositories.

The first step is to download the latest release package for CentOS, you might have to install the wget utility first:

yum –y install wget

Install the downloaded package:

yum localinstall mysql80-community-release-el7-1.noarch.rpm

You can now install MySQL 8, which is the latest version. However, it is a better idea at the moment to choose version 5.7, because it offers better compatibility with many applications, so let’s configure the repository to install that version:

yum –y install yum-utils
yum-config-manager --disable mysql80-community
yum-config-manager --enable mysql57-community

You can now proceed with the actual installation:

yum -y install mysql-community-server

Start and enable the mysql service:

systemctl start mysqld
systemctl enable mysqld

Unlike older versions, MySQL 5.7 generates a random root password during the installation process; you will need to get it from the logs in order to use the database:

grep temporary /var/log/mysqld.log

Copy the temporary password and run the following command in order to secure your database by tweaking some common settings:


All of the options here are pretty straightforward: choose a strong root password to replace the temporary one and press y to accept all of the other questions, which will remove anonymous users and the test database, as well as disable remote root login.

Connect to the database to make sure that everything is in order:

mysql –u root –p

Install Grafana

There are several ways to install Grafana in CentOS, the most convenient is to setup a yum repository because it will allow you to easily upgrade your packages in the future.

Create a new file at /etc/yum.repos.d/grafana.repo using your favorite text editor and add these lines to it:


You can now install the latest version from the new repository:

yum install grafana

Start the server and enable it automatically at boot:

systemctl daemon-reload
systemctl start grafana-server
systemctl enable grafana-server
systemctl status grafana-server

The last command just checks if the service has started properly, the output should look like this:

A few extra packages might also be required for proper font display, so just install them to be sure:

yum install fontconfig freetype* urw-fonts

Getting started with Grafana

Your Grafana server is now up and running, so you can connect to it using your web browser.

By default, the server uses the port 3000, so open your browser and go to http://<Domain or IP address>:3000

Enter admin/admin as the initial username and password, you’ll be immediately prompted to enter a new password.

You will then reach the home menu, from where you can add a data source, configure plugins, create dashboards and share them with other users.

Configure a MySQL data source

From the dashboard, click on Add data source to configure the connection with the MySQL server.

Enter a name for this data source, as well as the database name, user and password. In this example, we have created a dummy database and user, both named grafana_test.

Click on the Save & Test button, if the credentials are correct you should see the message Database Connection OK.

Of course, in a real scenario you will have an actual database populated with real data that you can use as a source.

Play with the dashboard

Grafana is a very powerful application, after adding the first data source it is time to start exploring its features.

The next step is to customize the dashboard to visualize your data, so click on the Create your first dashboard button.

Select one of the options available, you will be able to add many other types later using applications and plugins.

Follow the initial walkthrough to the end, the Add Users menu allows you to invite other members of your team. However, a local SMTP server must be configured first, which we will not cover in the limited scope of this article.

The last step is to install apps and plugins, clicking on it will open a list of both free and premium options that can greatly enhance your Grafana server.


By following this tutorial, you now have a fully functional installation of Grafana, configured to use data from a local MySQL server.

It is a very powerful platform that can be customized according to your needs; you can for example add a Prometheus dashboard in order to create a monitoring stack. Check the official documentation for more ideas and specific use cases.