Now it's time to create the MySQL database and admin user that your Piwik installation will be using. It is recommended that you create a user and database specifically for Piwik to use to keep your MySQL users and databases segregated.
Create a user and database for your installation, using the following steps:
1. Open your browser, browse to the location of your cPanel installation, and click on the MySQL Databases link in cPanel.
2. Enter a name for the database you will be using for Piwik, and click on the Create Database button. If you are on shared hosting, cPanel will add your username as a prefix. For example, if you chose
piwik
as the name of your database and your username isusername
, the actual name of the database created will beusername_piwik
. You will need to remember this database name for the web-based Piwik installation.3. Now it's time to create a user and assign the user to our new database. Jump down to the MySQL Users section. Enter your desired username and password twice, and click on Create User. You will need to remember the username and password for the Piwik installation. With cPanel on a shared host, you will get a new MySQL username with your username as a prefix, like this:
username_mysqluser
.4. Now add the user to the database, by clicking on the Add button.
5. Next, check the ALL PRIVILEGES checkbox for the user and click on the Make Changes button, so that the new user gets full control of the new database.
Some web hosts provide you with an installation of phpMyAdmin with your hosting account, and other hosts may give you a way to install phpMyAdmin with a one-click installation process. In either case, here is how we create a user and database in Piwik using phpMyAdmin:
1. Navigate to the folder where phpMyAdmin is installed. The location of this installation depends upon your hosting provider or the directory you choose in the phpMyAdmin one-click installation process.
2. Click on the Databases link.
3. There, you should see a textbox with the words Create new database. Enter the name of your database in the box and click on the Create button.
4. Now that your database exists, it is time to create a user. Click on the More link on the far right-hand side of the upper menu. This will bring up another menu. One of the items in that menu will be Privileges. Click on that link.
5. When the page loads, click on Add a new User.
6. Enter a username, a password, and the same password again, in their designated boxes. Below that, in the Database for user section, make sure Grant all privileges on database "Your_Database_Name" is checked, where Your_Database_Name is the database you just created.
7. Click on the Go button at the end of the page. Once the page loads, you are done with the creation of a database section.
For those of you who would rather use SSH to create your database for Piwik, you can use the following steps:
1. Log in to your web server via SSH, using Putty or Terminal.
2. Connect to the MySQL server, using the following command:
mysql -u root –p
In this command,
root
is a MySQL user with full permission.3. You will be prompted for this user's password. Enter it.
4. Run the following command:
CREATE DATABASE piwik;
In this command,
piwik
is the name of the database you are creating.5. Run this command:
GRANT ALL ON piwik.* TO piwik_user@'localhost' IDENTIFIED BY 'password';
In this command,
piwik_user
is the MySQL username you choose andpassword
is the password you choose for that user.
Your database will be ready, but you may have to run the last command for all the possible host names you will be using. You will also need to run the last command for localhosts such as 127.0.0.1, and the domain your Piwik installation will be running under, if any.