![]() |
| |||||||
|
Monday's tip showed you how to grab and install MySQL. Today we'll create the MySQL database directory and test the installation. The database directory, by default, is created under the actual installation in /usr/local/mysql/data. It's better to create it elsewhere, perhaps under /var where most server generated data, such as incoming mail and log files, is stored. To become the root user (give your admin password) type: $ sudo -sPassword: # Create the database directory /var/mysql-data (you can place it at another location if you wish). Type: # mkdir /var/mysql-data# chown mysql:mysql /var/mysql-data # chmod 770 /var/mysql-data Create the MySQL configuration file, /etc/my.cnf, which tells mysql where the database it held. This is what it should contain: # cat /etc/my.cnf[mysqld] datadir=/var/mysql-data Next, create the necessary administrative databases by typing: # /usr/local/mysql/scripts/mysql_install_db --user=mysql --datadir=/var/mysql-dataThis should create all the necessary files with owners mysql:mysql. Test the installation - start the server by typing: # mysqld_safe --user=mysql &[1] 19718 # Starting mysqld daemon with databases from /var/mysql-data (If mysqld_safe cannot be found, see Monday's tip to add the MySQL executable directory to your PATH. Once you have done so, start a new terminal session. Alternatively, type the full path name to this and other MySQL commands - eg /usr/local/mysql/bin/mysqld_safe.) Check that the three default databases are there # mysqlshow +--------------------+ | Databases | +--------------------+ | information_schema | | mysql | | test | +--------------------+ MOST IMPORTANT: enable the root password by typing: # mysqladmin -u root password my-password# mysqladmin -u root -h hostname.domain.com password my-password Replace 'hostname.domain.com' with your host's name (eg 'mymac.local'). You might get away with typing just the first line. Obviously, replace my-password with your chosen MySQL root password. (Don't confuse the Unix root user with the MySQL root user - they are entirely separate.) NOTE: From this point on, it's necessary to give the option -p to most MySQL commands and type root's password at the prompt. As a further test of successful installation, stop the server by typing: # mysqladmin -u root -p shutdown Enter password: STOPPING server from pid file /var/mysql-data/... 060111 00:51:57 mysqld ended Next, we must create a Mac OS X startup item so MySQL will be launched when your Mac starts. Create a directory by typing: # mkdir /Library/StartupItems/MySQLCreate two files in the directory, called MySQL and StartupParameters.plist. They are included in the Mac-style Package installer, but not in the Unix style Tar package. Change to the appropriate directory: # cd /Library/StartupItems/MySQLCreate the files with the following contents:
-- MySQL --
#!/bin/sh
#
# Startup Item for MySQL
# ######################
. /etc/rc.common
mysqlctl="/usr/local/mysql/support-files/mysql.server"
StartService ()
{
if [ "${MYSQLCOM:=-NO-}" = "-YES-" ] ; then
echo "Starting MySQL server"
$mysqlctl start
fi
}
StopService ()
{
echo "Stopping MySQL server"
$mysqlctl stop
}
RestartService ()
{
echo "Restarting MySQL server"
$mysqlctl restart
}
if [ -x $mysqlctl ]; then
RunService "$1"
else
echo "Cannot execute $mysqlctl"
fi
-- StartupParameters.plist --
{
Description = "MySQL Startup";
Provides = ("MySQL");
Requires = ("DirectoryServices", "NetworkExtensions");
OrderPreference = "Last";
}
Make sure the script is executable: # chmod +x MySQLWhen you reboot, MySQL should automatically start up. NOTE: If you copy and paste this code from the OSXFAQ forums, you might have problems because PHP-BB adds odd invisible characters to the code sections. Wednesday's tip will show how to add a new database, and how to add a user to the database. Visit the Site of the Book of the Unix Tips: Discuss this trick in the OSXFAQ Learning Center forum E-mail your comments or suggestions to webmaster@osxfaq.com
|
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||