Installing MySQL and connecting to Joomla

Posted by superuser Thu, 11 Mar 2010 12:26:00 GMT

This is a guide on how to install and configure MySQL for the Joomla environment. For the demonstrations of this article i use a FreeBSD-8 OS. The paths for the executables files and the paths where mysql holds the databases it may be different in your case. For example FreeBSD uses most executables scripts on /usr/local/bin/ , while Linux on /usr/bin or /usr/sbin. The rest remains the same.

Installing mysql

Nearly all operating systems have their own package manager. The installation is a straightforward process. You should have root privileges to make a complete installation in binary or to build from sources.

For example:

  • # sudo apt-get install mysql-server [DEBIAN/UBUNTU]
  • # pacman -S mysql [ARCHLINUX]
  • # yum install mysql mysql-server [REDHAT/FEDORA]
  • # make WITH_CHARSET=utf8 install clean [FreeBSD]
  • You should note that in the case of FreeBSD, i compile using

    WITH_CHARSET=utf8
    because mysql by default sets a latin1 character encoding. If you install mysql using the default latin1 encoding but you intend to use utf8 characters in your app, you'll be in trouble. Check what default character encodings use your distribution for mysql server. As far as i know, Archlinux ships with default utf8 encodings, while Fedora with latin1, as FreeBSD does.

    Configuration of mysql

    Immediately after the completion of your installation you must create the directory where your databases will be stored . Again with root privileges:

    # /usr/local/bin/mysql_install_db

    Check that the directory /var/db/mysql has been created with a lot of stuff inside. In some distributions this directory (/var/db/mysql) has not the appropriate permissions for the group and it's owned by root. We should change that, otherwise mysql server will deny to start.

    # chgrp -R mysql /var/db/mysql # chown -R mysql /var/db/mysql

    Starting mysql & Setting the mysql-Root password

    Let's start now the mysql server

    # /usr/local/bin/mysqld_safe -user=mysql &
    [1] 2783
    localhost# Starting mysqld daemon with databases from /var/db/mysql


    If you don't get an error at this step, you can be sure that mysqld daemon is up and running.. When you need to stop the server (don't do this now)

    $ mysqladmin -u root -p shutdown

    From now on, we have no need for system-root privileges, so use your ordinary user account. In our last step before starting to work with MySQL, is to set the password for the mysql-root account (mysql-root account is not related in anyway with the system-root account of your OS. Are completely different concepts. The first is a mysql user, the later a system user. The only conceptual thing in common is that both have full privileges for their environment). Replace new password with your secret mysql-root password.

    $ /usr/local/bin/mysqladmin -u root password newpassword

    Creating the database

    It's time to create my mysql database now, i call it "joodb" :

    $ mysqladmin -u root -p create joodb
    Enter password: [enter your mysql root password here]

    Check now that your database has been created. Enter at your mysql client and ask to SHOW DATABASES;:

    $ mysql -u root -p
    Enter password:

    Welcome to the MySQL monitor. Commands end with ; or \g.
    Your MySQL connection id is xxx
    Server version: 5.0.51a FreeBSD port: mysql-server-5.0.51a

    Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
    mysql>show databases;


    Your database list should include joodb. Fine! joodb database is ready to use, but for security issues mysql permits the usage of a db only by privileged mysql-users. Except the root mysql-user, we do not have created any other. Now i'll set the privileges to use "joodb" for a mysql-user named "joom" with password "ladin". This user will be automatically created during the setting of the privilege. The sensible data are "joodb"(database name), "joom"(mysql-username), "ladin"(mysql-password) and the domain "localhost".

    mysql> grant all privileges on joodb.* to 'joom'@'localhost' identified by 'ladin';
    Query OK, 0 rows affected (0.09 sec)

    mysql> flush privileges;
    Query OK, 0 rows affected (0.05 sec)

    mysql> \q
    Bye

    flush privileges enables the privilege and pressing \q you exit the client.

    Our database now is ready to use by a mysql-user named joom. Connecting my Joomla application with this database it means simply that i have to provide these informations to the configuration file of Joomla. In the section Database Settingsof the configuration.php i simply set:

    #--- configuration.php ---
    /* Database Settings */
    var $dbtype = 'mysql';
    var $host = 'localhost';
    var $user = 'joom';
    var $password = 'ladin';
    var $db = 'joodb';
    var $dbprefix = 'jos_';

    That's all! We have succesfully created and configured our mysql database, created our mysql-user, set up the privileges and connected at our joomla application. Fire up now with your extra-galactica application.

    Posted in  | Tags , ,  | no comments