Below I have the high level steps I took to perform a simple install of MySQL 5.1.22 on Mac OS 10.4. These instructions can be followed for any MySQL 5.1.xx install. These are not detailed instructions. The objective is to overview a simple installation of MySQL using MOCA. The Mac OS installation will be similar to a Unix or Linux installation. Go to the MySQL documentation to review instructions if you are using a different operating system.
This is not a recommended install for a new MySQL DBA (perform a default installation to get comfortable with MySQL first). If you are an experienced DBA from another platform and understand Unix directory layouts this installation may be okay if you review the MySQL documentation first. Review the blog "The MySQL Optimial Configuration Architecture" for the reason for this layout.
Be careful
Make sure you understand exactly what commands you are running and where you are running these commands from. If you are new to Unix/Linux be extremely careful before executing the following steps. If you are not sure of a command do not run it without reviewing the documentation. Use the man pages or look at other documentation to verify what you are doing. These steps are an overview to show the main steps for a simple installation. Spend sufficient time reviewing each of these steps and make appropriate changes for your environment.
Installation Summary
The following list outlines the steps performed to install MySQL on Mac OS. I recommend reading the blog "Top Ten Things to do before installing MySQL" further down on this site before beginning this installation.
- Set up the operating system and directory structures (physical storage) for running MySQL.
- Setup the mysql operating system user id.
- Install the MySQL software in the MYSQL_HOME directory.
- Create a startup file (my.cfg).
- Run the mysql_install_db script to set up the MySQL data directory.
- Start the MySQL server instance by running mysqld_safe.
- Test the MySQL Server instance by running the perl script mysql-test-run.pl.
- Secure the mysql password environment with the mysql_secure_installation script.
- Login in using the mysql client and verify the installation. Review the data files, log files, binary log, error logs, etc.
- Define a server startup method. The script mysql.server is a likely option.
- Define a backup and recovery strategy. Test your back and recovery processes.
- Have fun with MySQL. :)
Installation Environment
Hardware: MacBook Pro laptop , 2GB of memory, dual core
Operating System: Mac OS 10.4
Disk: 160 GB
MySQL: RC 5.1.22 for Mac OS X (TAR packages)
Create the directory /opt/mysql for placing the 5.1.22 software.
Go to http://dev.mysql.com and choose the 5.1.22 download (mysql-5.1.22-rc-osx10.4-i686.tar.gz). Place this zip file in the /opt/mysql/5.1.22 directory.
Defined the following directory structure for the MySQL environment:
Bring up a terminal window as the root or administrator userid.
Use the mkdir command to create the directories listed below.
/opt/mysql/
/opt/mysql/software
/db01/mysql/mysql01/data - data directory
/db02/mysql/mysql01/mysql-bin - location of binary log files
/db03/mysql/mysql01/ - administration directory
/db03/mysql/mysql01/ - location of the PID file
/db03/mysql/mysql01/startup - location of my.cfg file
/db03/mysql/mysql01/run - location of socket file
/db03/mysql/mysql01/errors - location of error file
/db03/mysql/mysql01/logs - location for general and slow logs
/db03/mysql/mysql01/scripts - administration scripts
/db03/mysql/mysql01/sql - generic sql code
/db04/mysql/mysql01/backups - backup files, exports, miscellaneous
Preinstallation steps:
Checked to see if there was a previous MySQL installation. Seen the MySQL 4.1 installation came with the MacOS system. Verified an older version of MySQL was not currently running. Used the RPMs to deinstalled the MySQL 4.1 installation.
Verified the setup the mysql operating system user account. A mysql user already existed in the /etc/passwd file. Using the Finder window in Mac. These commands only work with Mac OS 10.4. Use the 10.5 method for the new Leopard OS.
- Go to the Applications location for Mac OS.
- Go to Utilities subdirectory.
- Click on the NetInfo Manager.
- When the window pops up, select users. Then click on mysql user.
- Click the lock at bottom of page to make changes. Set a password, home directory (/Users/mysql) and shell (/bin/ksh).
- Save the changes.
- Open a terminal window. Type exec login mysql. Type the new password and verify the mysql userid defaults to the correct home directory (/Users/mysql).
- Use vi or another text editor to create a .profile file in the /Users/mysql directory with the following values:
export MYSQL_BASE=/opt/mysql
export MYSQL_HOME=$MYSQL_BASE/5.1.22
PATH=$PATH:$MYSQL_HOME/bin
Go to each of these parent directories and change the owner and group to mysql. The operating system userid root password will be your main Mac OS password for your administrator. Make sure you are in the right directory before running any recursive command. If you are in the wrong directory you could mess up your operating system. Execute the pwd command to make sure you are in the right directory.
Login as your administrator userid or root userid to run the following commands. Be extremely careful you do this correctly!
$ cd /db01
$ sudo chown -R mysql:mysql .
$ cd /db02
$ chown -R mysql:mysql .
$ cd /db03
$ chown -R mysql:mysql .
$ cd /db04
$ chown -R mysql:mysql .
$ cd /opt/mysql
$ chown -R mysql: mysql .
Setup up the MySQL software.
Login in as the mysql operating system user id and verify.
$ who am i
mysql ttyp1 Oct 10:19
Go to the /opt/mysql directory then run the following commands to set up the MySQL HOME directory (MYSQL_HOME). The symbolic link will set /opt/mysql/5.1.22 as the software location for MySQL.
$ cd /opt/mysql
$ gunzip -c mysql-5.1.22-rc-osx10.4-i686.tar.gz tar xvf -
$ ln -s mysql-5.1.22-rc-osx10.4-i686 5.1.22
$ mv mysql-5.1.22-rc-osx10.4-i686.tar.gz file /opt/mysql/software/5.1.22
Set up the startup file (my.cnf) for MySQL Make sure to review each of these startup parameters.
$ cat /dbadmin/mysql/mysql01/startup/my.cnf
[mysqld]
log-error=/db03/mysql/mysql01/errors/mysql5.1.22.err
pid-file=/db03/mysql/mysql01/localhost.pid
datadir=/db01/mysql/mysql01/data
basedir=/opt/mysql/5.1.22
log-bin=/db02/mysql/mysql01/mysql01-bin
[client]
# global options for every client:
socket=/db03/mysql/mysql01/run/mysql01.sock
Setup the MySQL environment# Setup the mysql data directory. Make sure you are logged in as the mysql OS userid. When done go to the /db01/mysql/mysql01 directory and make sure it is setup correctly. You should see the files ib_logfile0, ib_logfile1, ibdata1 and the subdirectory mysql from the output of the ls command.
$ cd /opt/mysql/5.1.22
$ scripts/mysql_install_db --defaults-file=/db03/mysql/mysql01/startup/my.cnf
$ cd /db01/mysql/mysql01
$ ls -la
Start the MySQL daemon using the new startup my.cfg file.$ cd /opt/mysql/5.1.22
$ bin/mysqld_safe --defaults-file=/db03/mysql/mysql01/startup/my.cnf &
$ ln -s /db03/mysql/mysql01/startup/my.cnf my.cnf
# Test the MySQL daemon with mysql-test-run.pl and review the output.
$ cd /opt/mysql/5.1.22/mysql-test
$ perl mysql-test-run.pl > mysql-test-run.output
Login to the mysql server and secure the password environment.# Login to mysql and see that no passwords have been setup yet.
$ mysql -h localhost -uroot
mysql> select host, user, password from user;
mysql> quit
# Run the following script and set the values listed below. When prompted enter new password for the mysql database userid. Do NOT set this to the same value as the operating system userid mysql.
$ mysql_secure_installation
Set root password? [Y/n] y
Remove anonymous users? [Y/n] y
Disallow root login remotely? [Y/n] y
Remove test database and access to it? [Y/n] y
Reload privilege tables now? [Y/n] y
#Login to your new mysql server environment. Never type a database password on an operating system prompt. Verify a password now exists for the mysql userid on the localhost.
$ mysql -h localhost -uroot -p
mysql> select host, user, password from mysql.user;
Post Installation StepsLogin in using the mysql client and verify the installation. Review the data files, log files, binary log, error logs, etc. Make sure you are comfortable with the new environment.
Define a server startup method. The script mysql.server is a likely option. Test the startup and shutdown processes.
Define a backup and recovery strategy. Test your back and recovery processes.
Remember there are the following userids in this environment:
- root - Linux/Unix operating system user id.
- root - MySQL database user id.
- mysql - Linux/Unix operating system user id.
Installing the MySQL GUI Tools BundleInstalling the MySQL GUI tools should be installed with the .DMG file on Mac. The nice thing is it is a three click install: 1) Click to download the GUI Tools .DMG file from the dev/mysql.com site 2) Click to open the file on the Mac OS. 3) Click to move it into the Applications directory for Mac.
This is the MySQL GUI Tools Bundle for 5.0. which includes the following:
- MySQL Administrator 1.2
- MySQL Query Browser 1.2
- MySQL Migration Toolkit 1.1 (currently not available for Mac OS in bundle)
ConclusionThese instructions walk through the basic steps for setting up a MySQL server on a Mac OS. Remember this article discusses a basic install. It does not include setting up memory, InnoDB server parameters, etc. This will allow you to have fun in the documentation. :)
Have fun with MySQL. :)