Time for action – creating the database
To keep it simple let's assume that you're going to host the database on the same server as Cacti.
Execute the following command to logon to the MySQL CLI:
mysql –u root mysql
The default MySQL root account does not have a password set, so you can set one as follows:
SET PASSWORD FOR root@localhost = PASSWORD('MyN3wpassw0rd');
You can now also remove the example database, as it is not needed:
DROP DATABASE test;
Together with the example database, some example users may have been created. You can remove these with the following command:
DELETE FROM user WHERE NOT (host = "localhost" AND user = "mydbadmin");
On a CentOS distribution you can use the following command to guide you through the above steps:
/usr/bin/mysql_secure_installation
Now that MySQL is secured, let's create the Cacti database. Enter the following command:
mysqladmin -u root -p create cacti
This will ask for the MySQL root password which you provided in Setup Step 1. When finished, you will have an empty database called
cacti
.As the database is still empty, you need to create the tables and fill it with the initial data that comes with Cacti. The following command will do just that:
mysql -p cacti < /var/www/html/cacti/cacti.sql
Again it will ask for the MySQL root password. Once the command finishes you'll have a working Cacti database. Unfortunately Cacti is still unable to access it, therefore you are now going to create a database user for Cacti.
Enter the following command:
mysql -u root -p mysql
You'll see the following on the screen:
Type the next few lines in the MySQL prompt to create the user. Make sure to choose a strong password:
GRANT ALL ON cacti.* TO cactiuser@localhost IDENTIFIED BY 'MyV3ryStr0ngPassword'; flush privileges; exit
What just happened?
You used some tools to secure the MySQL server and created a database. You also filled the Cacti database with the initial data and created a MySQL user for Cacti. However, Cacti still needs to know how to access the database, so let's move on to the next step.
In case you are not using CentOS to install Cacti, you can use some MySQL internal functions to secure your installation.
Configuring Cacti
You
need to tell Cacti where to find the database and which credentials it should use to access it. This is done by editing the config.php
file in the include
directory.