Installing MySQL 5.5 Part 1 – A single instance

Today I will teach you how to install a MySQL server with ease. With only a single instance in the second part of this article, I will teach installing multiple instances of MySQL and control them through the mysqld_multi.

For this tutorial I’m using:

CentOS 5.6 - 64bits
Installation without a GUI, only command line

That said, let’s get to what really matters:

  1. Let’s create a directory structure that we work with our installation of MySQL for this tutorial I will install the root partition:
    cd /
    mkdir mysql
    cd mysql
  2. We go to MySQL downlads site and download the latest version Community Server what is now 5.5.11. Use Build Linux Gener!/altmannmarceloic
    and search for the package tar.gz version of its operating system:
  3. Once downloaded the MySQL package, we will now unpack the downloaded package with the command:
    tar -vzxf mysql-5.5.11-linux2.6-x86_64.tar.gz
  4. Now we just set the folder name to something more readable:
    mv mysql-5.5.11-linux2.6-x86_64 core-5.5.11
  5. That done we will create a symbolic link, because in MySQL requires that your folder is named exactly mysql
    ln -s core-5.5.11 mysql
  6. After we create the directory structure of our instance of MySQL:
    mkdir 3306
    mkdir 3306/data
    mkdir 3306/logs
  7. The next step is to create the MySQL database But before That standard, we have to define what user will run MySQL, by default, we always create (if it does not exist) the user with the name MySQL:
    groupadd mysql
    useradd -r -g mysql mysql
    With our user created in the system, let’s change the permissions of the folders of MySQL for this user:
    chown -R mysql:mysql /mysql/
  8. We then create the databases MySQL standards given our folder/ symbolic link mysql have a several folders, one called scripts within it have a script that makes the creation of the database structure needed to start our instance of MySQL to run this script, we will enter three parameters:
    user – user owner of the folders that are created
    basedir – folder where you installed our MySQL (sources)
    datadir – folder where you want it to be created the database structure
    In our case, the command will look like this:
    cd /mysql/mysql/scripts/
    ./mysql_install_db --user=mysql --basedir=/mysql/mysql --datadir=/mysql/3306/data/
    We receive a return on the screen, we have to look to get two OK’s at the beginning of the return:Installing MySQL system tables...
    Filling help tables...
  9. Now we’ll create the settings file my.cnf, we will set up some basic parameters for our instance:
    datadir – path to the folder where is located our datadir
    socket – where we save the unix socket
    user – mysql user will use to start our instance and access the files on disk
    log-error -location and name of log file (very important because it we diagnose most problems that occur with our MySQL server)
    pid-file– file that will be the PID of MySQL
    Let’s really create our configuration file:
    vi /mysql/my.cnf
    The contents of our file should look like this:
  10. And finally, let’s start our MySQL instance:
    cd /mysql/mysql
    bin/mysqld_safe --defaults-file=/mysql/my.cnf &
  11. Okay, now our MySQL is ready for use, let’s just make another adjustment: Place the folder of MySQL in the PATH so that we can access it from anywhere in the system:
    export PATH=$PATH:/mysql/mysql/bin/
  12. To connect to the database via TCP/IP use:
    mysql -u root -h127.0.0.1
    or via UNIX socket
    mysql -u root --socket=/mysql/3306/mysql.sock

Remembering that good security practices MySQL are asking us to perform 3 tasks:

  1. Remove the database test because this database, all users have full access and can be any user create a procedure with an infinite loop to enter data until your disk is 100% full
  2. remove the anonymous user
  3. change the root password, because by default it comes in white

That’s it folks, hope you enjoyed it, post your questions and suggestions, and stay tuned, next post, I will teach climbing N instances on one server.Hugs!

2 thoughts on “Installing MySQL 5.5 Part 1 – A single instance

  1. Hello my friend,

    I am trying to configure two databases on two diferent paths, with the same instance of mysql server…
    Do you kwon how to do it?

    Thanks anyway.

Leave a Reply

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