Mac OS X Unleashed

Mac OS X Unleashed

By John Ray and William C. Ray

MySQL

The MySQL database system is a free implementation of an SQL-based (Structured Query Language) database system. MySQL has been successfully deployed for a number of high-end applications on Web sites such as NASA, Yahoo!, and Slashdot. In addition to the database package itself, MySQL has JDBC and ODBC drivers available, making it accessible from any platform supporting these standards, including Microsoft Windows.

Installing MySQL

To install MySQL, download the latest source code distribution. The server software is updated on an almost daily basis, but there is a stable release listed along with the latest developmental releases. We highly recommend that you stick with the stable release for any serious development projects.

The MySQL source tarball can be downloaded from www.mysql.com/downloads/:

[primal:~] jray% curl-o http://www.mysql.com/Downloads/MySQL-3.23/ mysql-3.23.39.tar.gz

Next, unarchive the distribution, cd into the resulting MySQL directory and run ./configure to prepare for compilation:

[primal:~] jray% cd mysql-3.23.39/
[primal:~/mysql-3.23.39] jray% ./configure
creating cache ./config.cache
checking host system type... powerpc-apple-darwin1.3.3
checking target system type... powerpc-apple-darwin1.3.3
checking build system type... powerpc-apple-darwin1.3.3
checking for a BSD compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking whether make sets ${ MAKE} ... yes
checking for working aclocal... missing
checking for working autoconf... found
checking for working automake... missing
checking for working autoheader... found
...

After a few minutes of analyzing your system, the configuration process will complete. Use make to compile the software. This will take 5 to 10 minutes, depending on your system:

[primal:~/mysql-3.23.39] jray% make
cd include; make link_sources
/bin/cp ../config.h my_config.h
echo timestamp > linked_include_sources
cd libmysql; make link_sources
set -x; ...

Finally, install the software with sudo make install:

[primal:~/mysql-3.23.39] jray% sudo make install
Making install in include
make[2]: Nothing to be done for `install-exec-am'.
/bin/sh ../mkinstalldirs /usr/local/include/mysql
mkdir /usr/local/include
mkdir /usr/local/include/mysql
 /usr/bin/install -c -m 644 dbug.h /usr/local/include/mysql/dbug.h
 /usr/bin/install -c -m 644 m_string.h /usr/local/include/mysql/m_string.h
 /usr/bin/install -c -m 644 my_sys.h /usr/local/include/mysql/my_sys.h
 /usr/bin/install -c -m 644 mysql.h /usr/local/include/mysql/mysql.h

The software is installed (/usr/local/bin), but isn't ready to run. Before you're finished, you'll need to initialize the default databases and create a startup script to initialize the server when Mac OS X boots.

Creating the Initial MySQL Database

MySQL uses an internal database to manage access permissions to databases and tables. Before the software can start for the first time, you must initialize these tables using the mysql_install_db command, located in /usr/local/bin:

[primal:/usr/local/bin] jray% sudo ./mysql_install_db
Preparing db table
Preparing host table
Preparing user table
Preparing func table
Preparing tables_priv table
Preparing columns_priv table
Installing all prepared tables
010614 14:50:09  /usr/local/libexec/mysqld: Shutdown Complete

To start mysqld at boot time you have to copy support-files/mysql.server
to the right place for your system

PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
This is done with:
/usr/local/bin/mysqladmin -u root -p password 'new-password'
/usr/local/bin/mysqladmin -u root -h primal -p password 'new-password'
See the manual for more instructions.

You can start the MySQL daemon with:
cd /usr/local ; /usr/local/bin/safe_mysqld &

You can test the MySQL daemon with the benchmarks in the 'sql-bench' directory:
cd sql-bench ; run-all-tests

Please report any problems with the /usr/local/bin/mysqlbug script!

The latest information about MySQL is available on the web at
http://www.mysql.com
Support MySQL by buying support/licenses at https://order.mysql.com

As the documentation says, you should reset the root password immediately using the command /usr/local/bin/mysqladmin -u root -p <password> <new-password> .

Creating a Startup Script

Mac OS X uses a special directory structure located in /Library/StartupItems or /System/Library/StartupItems to automatically start processes when the machine boots. Although some applications install these startup files in the /System path, the design of the operating system indicates that add-on software should use the /Library directory, rather than altering the main system folder.

There are three components to a Mac OS X startup script:

  • A folder named after the service you are installing (such as MySQL).
  • A shell script that bears the same name as the folder. This script should contain the commands needed to start the server process.
  • An XML file named StartupParameters.plist that contains a description of the process. This currently isn't used by any Mac OS X admin tool, but presumably will provide an Extension Manager–type control of services in the future.

Let's take a look at what is exactly needed for Mac OS X and MySQL.

Create the folder MySQL in /Library/StartupItems. Within this folder, add a text file named MySQL containing the following shell script:

#!/bin/sh

##
# Start MySQL
##

. /etc/rc.common

if [ "${ MYSQL:=-NO-} " = "-YES-" ]; then
    ConsoleMessage "Starting MySQL"
    cd /usr/local ; /usr/local/bin/safe_mysqld &
fi

This script will check the /etc/hostconfig file for a line that reads MYSQL=-YES- and, if it exists, add start the server. Use a text editor to add this to the hostconfig file, or just type

echo "MYSQL=-YES-" >> /etc/hostconfig

Next, add the StartupParameters.plist file to the directory. The contents of this file are arbitrary—until Apple releases official specifications.

{
  Description     = "MySQL database server";
  Provides        = ("MySQL");
  Requires        = ("Resolver");
  OrderPreference = "None";
  Messages =
  {
    start = "Starting MySQL server";
    stop  = "Stopping MySQL server";
  } ;
}

After you add these files, your Mac OS X machine will automatically start MySQL upon booting. It's time to start using your new SQL server.

Share ThisShare This

Informit Network