MySQL Installation


Advice on installing and securing MySQL server and client binaries on FreeBSD UNIX and RHEL systems.

Install the MySQL Server on a FreeBSD System

  1. Install the desired MySQL port:
    % cd /usr/ports/databases/mysql[NN]-server
    % sudo make install clean
  2. Install the scripts port that goes along with your selected MySQL server port:
    % cd /usr/ports/databases/mysql[NN]-scripts
    % sudo make install clean
  3. Add these configuration lines to /etc/rc.conf:
    mysql_args="--log=/var/log/mysql/connections.log --max_connections=153"
  4. Install MySQL system databases:
    % sudo mysql_install_db
  5. Secure MySQL system databases:
    % sudo mysql_secure_installation

    Be sure to:

    1. Set the root password
    2. Remove anonymous users
    3. Disallow root login remotely
    4. Remove test database and access to it
    5. Reload the privilege tables
  6. Add a 'Local Additions' entry to /etc/newsyslog.conf to rotate the logfile:
    # Local Additions
    /var/log/mysql/connections.log  mysql:mysql     644  7     100  *     JC    /data/mysql/

Install the MySQL Server on a RHEL System

  1. Use yum to install the mysql-server package
  2. Make sure selinux is disabled
  3. start the mysql service. The first time it is started it will created the needed tables and data structures.
  4. run /usr/bin/mysql_secure_installation to harden
  5. Use /sbin/chkconfig mysqld on to turn the service on so that it restarts automatically after a reboot
  6. Enjoy using mysql

Enable the MySQL Federated Storage Engine on a FreeBSD System

As of May 10, 1012, FreeBSD's mysql-server port doesn't acknowledge the WITH_FEDERATED=yes option in /etc/make.conf. Fortunately, you can work around it.

  1. Update this FreeBSD system's ports to the latest versions.
  2. Modify the Makefile's config args to include the Federated Storage Engine.
    % ~% cd /usr/ports/databases/mysql51-server/
    mysql51-server% sudo vi Makefile
    [Add the federated-storage-engine option to CONFIGURE_ARGS]
    CONFIGURE_ARGS= --localstatedir=/var/db/mysql \
                    --without-debug \
                    --without-readline \
                    --without-libedit \
                    --with-libwrap \
                    --with-low-memory \
                    --with-comment='FreeBSD port: ${PKGNAME}' \
                    --with-federated-storage-engine \
  3. Build or upgrade mysql-server.
  4. Add 'federated' to the MySQL server startup script arguments:
    % sudo vi /etc/rc.conf
    [Add 'federated' to the existing set of args]
    mysql_args="--log=/var/log/mysql/connections.log --max_connections=200 --federated"

Install the MySQL Client on a RHEL System

  1. Download the latest MySQL Community Server tarfile.
  2. Unzip, untar, and build it:
    % ./configure --prefix=/util/mysql-5.1.57 --without-server
    % make
    % sudo make install clean
  3. Repoint the mysql symlink to make this installation the default.


  1. FreeBSD does not honor the typical MySQL variable configuration strategy of placing config variables in a my.cnf file. Instead, set them in /etc/rc.conf's mysql_args variable.
  2. Build MySQL servers with these config options: --enable-local-infile
  3. With pre-4.1 clients the OLD_PASSWORD() function is needed so use the older hashing algorithms of pre-4.1 clients.
  4. Build Perl module DBD::mysql with these Makefile modifications:

    /util/bin/perl Makefile.PL --libs="-L/util/lib/mysql -lmysqlclient -lz -lposix4 -lgen -lsocket -lnsl -lm -L/util/gnu/lib -lgcc_s" --cflags=-I/util/include/mysql --testdb=test --testuser=root --testpassword=[redacted]

  5. Obsolete advice? I can't remember why I documented this. When setting up MySQL on RHEL, install with yum. Be sure you do not have /util mounted. The client installed in /util which gets picked up in the path causes odd things to happen with the install.