MySQL on FreeBSD 7

Prerequisites:

FreeBSD (Base + Autoconf, Automake, Bash and GCC)
OpenSSL

Overview:
 Step #1 - Download, Unzip, Untar, Configure, Compile and Install MySQL Server
 Step #2 - Add users, manually start the server and perform basic tests
 Step #3 - Copy and test the "rc" boot time startup script
 Step #4 - Tuning

Step #1

MySQL – The open source database server of choice

Home: 

 http://www.mysql.com

# Add a “mysql” user to your system: (MySQL should not need to run as root!)
pw groupadd mysql
pw useradd mysql -n mysql -G mysql -s /usr/sbin/nologin

# Download (Notes: Users behind a Proxy Server should read this and users without Internet but have a CDRom read this.)
cd /usr/src
fetch http://mysql.he.net/Downloads/MySQL-5.0/mysql-5.0.67.tar.gz

# Unzip and Untar and Change Directory
tar xvf mysql-?.?.*.tar.gz
cd mysql-?.?.*

#
 Configure
./configure --prefix=/usr/local --mandir=/usr/local/man --infodir=/usr/local/info/ --build=i386-srcbld-freebsd7.0 --localstatedir=/var/db/mysql --with-mysqld-user=mysql --with-mysqlmanager --enable-thread-safe-client --enable-assembler --with-tcp-port=3306 --without-debug --with-openssl=/usr/bin/openssl --with-openssl-includes=/usr/include --with-openssl-libs=/usr/lib --with-readline --enable-dependency-tracking --enable-local-infile --with-archive-storage-engine --with-csv-storage-engine --with-blackhole-storage-engine --with-federated-storage-engine --with-libwrap --with-mysqlfs --with-low-memory --with-berkeley-db --with-named-thread-libs=-pthread --with-embedded-server

#
 Compile
make all

#
 Install
make install

 

Step #2

Add users, manually start the server and perform basic tests

# Install the base database
/usr/local/bin/mysql_install_db


# Set permissions to correct owner

chown -R mysql:mysql /var/db/mysql


#
 Start the server
cd /usr/local ; /usr/local/bin/mysqld_safe &

# Perform basic checks
/usr/local/bin/mysqladmin version
/usr/local/bin/mysqladmin variables

# Set a Password!
/usr/local/bin/mysqladmin -u root password mysqlpassword

# Secure a production server
/usr/local/bin/mysql_secure_installation

# Add a "mysql" user with password and grant that user permission to connect
/usr/local/bin/mysql --user=root --password=mysqlpassword mysql
GRANT ALL PRIVILEGES ON *.* TO mysql@localhost IDENTIFIED BY 'mysqlpassword' WITH GRANT OPTION;
GRANT ALL PRIVILEGES ON *.* TO mysql@"%" IDENTIFIED BY 'mysqlpassword' WITH GRANT OPTION;
GRANT ALL PRIVILEGES ON *.* TO root@localhost IDENTIFIED BY 'mysqlpassword' WITH GRANT OPTION;
FLUSH PRIVILEGES;
exit

# Add a "mysqltop" user with no password and no ability to make changes and only usable via localhost for the "mtop" CLI tool
/usr/local/bin/mysql --user=root --password=mysqlpassword mysql
grant super, reload, process on *.* to mysqltop;
grant super, reload, process on *.* to mysqltop@localhost;
flush privileges;
exit

# (Optional) Add some compatibility for Linux applications by creating a symbolic links
ln -sv /usr/local/bin/mysqladmin /usr/bin/mysqladmin
ln -sv
/usr/local/bin/mysqldump /usr/bin/mysqldump

# (Optional) Run some tests before going into production (optional)
# /usr/local/mysql-test/mysql-test-run --force
# cd /usr/local/mysql-test ; perl mysql-test-run.pl
# Report any problems with the /usr/local/bin/mysqlbug script

 

Step #3

Copy and test the "rc" boot time startup script

 

# Copy the "rc" startup script
cp /usr/src/mysql-?.?.*/support-files/mysql.server /usr/local/etc/rc.d/mysql.sh
chmod +x /usr/local/etc/rc.d/mysql.sh


# Test the "rc" script
/usr/local/etc/rc.d/mysql.sh restart
/usr/local/etc/rc.d/mysql.sh stop
/usr/local/etc/rc.d/mysql.sh start
/usr/local/etc/rc.d/mysql.sh reload

# Clean up
cd /usr/src/mysql-?.?.*
make clean

# Perform basic checks using the password
/usr/local/bin/mysqladmin --user=root --password=mysqlpassword ping
/usr/local/bin/mysqladmin --user=root --password=mysqlpassword version
/usr/local/bin/mysqladmin --user=root --password=mysqlpassword variables
/usr/local/bin/mysqladmin --user=mysql --password=mysqlpassword var ext stat ver

 

# Edit your /etc/my.cnf
# See my example my.cnf

# Get the free MySQL Administrator to optimize and test your settings! UNTESTED AT THIS POINT DO NOT USE
# cd /usr/ports/devel/libglade2
# make install clean
# cd /usr/ports/x11-toolkits/gtkmm24
# make install clean
# cd /usr/ports/databases/mysql-administrator
# make install clean
# cd /usr/src
# fetch http://mysql.he.net/Downloads/MySQLGUITools/mysql-gui-tools-5.0r12.tar.gz

 

Step #4

Tune up MySQL to boost performance

# Edit /etc/my.cnf
vi /etc/my.cnf


# Restart MySQL
/usr/local/etc/rc.d/mysql.sh restart

# Check out your MySQL settings and tune /etc/my.cnf do more as desired
/usr/local/bin/mysqladmin --user=mysql --password=mysqlpassword var ext stat ver