Unix tutorial Contact as

How to install MySQL from source on FreeBsd or Linux

MySQL is a fast, multi-threaded, multi-user and robust SQL (Structured Query Language) database server. It provides a nifty API which makes it easy to integrate into other applications, including PHP.

The most important configuration parameters include:

--without-bench Do not compile the set of benchmarking tests. Unless you will specifically be using these, using this option will speed up your build time.
--with-extra-charsets=none This builds a faster MySQL server by only using the ISO-8859-1 (Latin1) characterset. Unless you are using a language other than English, this is a good option to select.
--disable-shared Do not build a shared libmysqlclient.so library. If your build fails and complains about not being able to create this file, using this switch is a good work-around.
--enable-thread-safe-client Build the MySQL client binary with suport for threads.
CXX=gcc Use gcc as your c++ compiler instead of g++. This has the advantage of not linking in libg++ and libstdc++, which has been known to cause strange problems with MySQL. Using libg++/libstdc++ also increases the size of the mysqld binary without giving you any added benefits.

First of all, you should to add a user and group for mysqld to run as:

On Linux:
# groupadd mysql
# useradd -g mysql mysql

On FreeBsd:
# groupadd mysql
# adduser (mysql)

To build MySql follow the next steps:

# mkdir /usr/local/mysql/data
# mkdir /usr/local/mysql/tmp
# mkdir /usr/local/mysql/var
# cd /usr/src
# tar -vzxf mysql-3.23-51.tar.gz
#cd /usr/src/mysql-3.23.51
# ./configure --prefix=/usr/local/mysql --localstatedir=/usr/local/mysql/data --with-unix-socket-path=/usr/local/mysql/tmp/mysql.socket
# make
# make install

Change ownership of the MySQL binaries to root and ownership of the data directory to the user that you will run mysqld as:

# chown -R root /usr/local/mysql
# chown -R mysql /usr/local/mysql/var
# chgrp -R mysql /usr/local/mysql

# chmod 700 /usr/local/mysql/data
# chmod 700 /usr/local/mysql/var
# chmod 755 /usr/local/mysql/tmp

To start MySQL by hand, run:

# /usr/local/mysql/bin/safe_mysqld --user=mysql & (MySQL 3.x)
# /usr/local/mysql/bin/mysqld_safe --user=mysql & (MySQL 4.x)

If this is your first-time installation of MySQL, you'll need to set up the initial mysql database, which contains all database privilege information, and establish a mysqld root password.

# scripts/mysql_install_db
# mysqladmin -u root -p password 'new-password'
# mysqladmin -u root -h -p password 'new-password'

Back to main page

Copyright © 2003-2016 The UnixCities.com
All rights reserved