JavaScript Editor Js editor     Website development 



Main Page

Previous Page
Next Page

Running MySQL on Mac OS X

On Mac OS X, there are a handful of ways to get MySQL running. For starters, there is an optional System Preferences panel (Figure 2.15) that handles the task nicely. There is also the choice of having MySQL automatically start when you turn on your computer. You can enable this feature by checking the box in the System Preferences panel or by installing the MySQL Startup Item when you installed MySQL (see the instructions in Chapter 1). With the Startup Item, you can use the information presented in the sidebar to also control MySQL.

Figure 2.15. MySQL on Mac OS X comes with a System Preferences panel that can be used to stop and start the database server.


Using the Startup Item

The Startup Item is a simple shell script that provides a shortcut for starting and stopping MySQL. In fact, the hardest thing about using the Startup Item is finding where it was installed in the first place. Depending upon your versions of OS X and MySQL, the full path and script name will most likely be one of the following:

  • /System/Library/MySQL/MySQL

  • /System/Library/MySQLCOM/MySQLCOM

  • /Library/MySQL/MySQL

  • /Library/MySQLCOM/MySQLCOM

Once you confirm its location (just use the Finder to hunt around), you can start and stop MySQL using the proper commands within a Terminal window. These would be simply

sudo/path/to/script start

and

sudo/path/to/script stop

(You have to run them using sudo; you will then be prompted for your Mac OS X administrative password.)

For example, in two test environments I have MySQL 4.1.13 on Mac OS X 10.4 Server and MySQL 5.0.18 on Mac OS X 10.3 ServerI use

sudo/System/Library/StartupItems/MySQL/MySQL start

If there's a problem, an error message will be displayed, and the Terminal will seem to sit there. In that case, press Enter to get a prompt again. Voilà! That's all there is to it!


Still, knowing how to manually start and stop MySQL is useful, so I'll run through that process. It involves using the Terminal application, with which you may not already be familiar.

To run MySQL on Mac OS X:

1.
Open the Terminal application.

The Terminal is found within your Utilities folder, which itself is inside the Applications folder. Just double-click the icon to open the Terminal.

2.
Move to the MySQL directory (Figure 2.16).

Figure 2.16. To begin controlling MySQL, get yourself into the installation directory, within a Terminal window.


cd/usr/local/mysql

To start, you'll want to move yourself into the directory where MySQL was installed. This should be /usr/local/mysql but could be different if you did something special during the installation process. If so, change the path here accordingly.

3.
Start MySQL (Figure 2.17).

Figure 2.17. Call the mysqld_safe script to start MySQL.


Type the following at the prompt and press Return:

sudo./bin/mysqld_safe &

The mysqld_safe script is used to start the server. It's located in the bin directory and must be run by prepending the command with the period and a slash (it's a Unix requirement). The ampersand at the end of this line tells the script to run in the background.

Because you must run the script as a superuser (in terms of your operating system), the whole line begins with sudo. You'll then be prompted for your Mac OS X administrative password.

Press Return to get back to the prompt.

If MySQL fails to start, make note of the error message displayed and refer to Appendix A, "Troubleshooting," or the MySQL manual for assistance.

4.
Confirm that MySQL is running (Figure 2.18).

Figure 2.18. The mysqlshow utility will show a list of available databases. It is also an easy way to confirm that MySQL is running.


At the prompt, type the following and press Enter:

./bin/mysqlshow -u root

This quick test should connect to MySQL and reveal the list of databases. If you have already established a MySQL root userpassword, you'll need to add -p at the end of the command to be prompted for that password.

5.
Stop MySQL (Figure 2.19).

Figure 2.19. Use mysqladmin to shut down MySQL. If the MySQL root userhas already been assigned a password, add -p after root.


Type the following at the prompt and press Return:

./bin/mysqladmin -u root shutdown

The mysqladmin utility can be used for many things, including stopping a running server. The -u root argument says that mysqladmin should perform the commandshutdownas the MySQL root user.

If you have already created a root userpassword, you'll need to add the -p flag, so that it prompts you for that password. In such a case, the full command would be:

./bin/mysqladmin -u root -p shutdown

Keep in mind that the MySQL root user is an entirely separate entity than your operating system users.

6.
Start MySQL up again and begin administering your database.

See the remainder of this chapter for information on related MySQL utilities, creating users, and so forth.

Tips

  • If you are running Mac OS X Server and it came with MySQL preinstalled, make sure you know what version it is. Versions of MySQL prior to 4.0 were started using the safe_mysqld script instead of mysqld_safe. If this is the case, change the preceding commands accordingly.

  • The mysqld server (and, therefore, the mysqld_safe script) can take a number of arguments to adjust how it runs. The average user will not need to tinker with these, but the complete listing can be found in the MySQL manual.



Previous Page
Next Page


JavaScript Editor Js editor     Website development


©

R7