JavaScript Editor Js editor     Website development 

Main Page

Previous Page
Next Page

Running MySQL on Linux and Unix

On non-Windows systems, the mysqld daemonthe process the runs the MySQL serveris started using the mysqld_safe script, which ensures that mysqld continues to run. This is true for Mac OS X as well as Linux and other flavors of Unix. Calling this script is straightforward and should be pretty simple for those knowledgeable about Unix, so I'll run through it quickly. Stopping MySQL makes use of the mysqladmin utility, which I'll also demonstrate.

To start and stop MySQL on Linux and Unix:

Log in to your system from a command-line interface.

For most versions of Unix and Linux, this is a matter of opening the Terminal application.

Change to the MySQL directory (Figure 2.20).

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


Assuming you followed the installation instructions as detailed in Chapter 1, all of the relevant MySQL utilities will now be located within the bin subdirectory of the /usr/local/mysql directory. Red Hat Linux users may find these utilities in /usr/bin instead.

Invoke the superuser (Figure 2.21).

Figure 2.21. To avoid problems using sudo when starting MySQL, enter this simple command.

sudo echo

This is a little trick I like to do in order to avoid problems with the next step. Enter your administrative password at the prompt. Once you've done that, you can use sudo again (in Step 4) without having to reenter the password (which can otherwise cause complications).

Start MySQL (Figure 2.22).

Figure 2.22. Starting MySQL on Linux.

Type the following at the prompt and press Return or Enter:

sudo./bin/mysqld_safe --user=mysql &

This line tells the server to keep mysqld_safe running constantly. What the mysqld_safe script does is check to see if mysqld is running and, if it is not, start up the daemon. The very first time you start mysqld_safe, it will immediately realize that mysqld is not up and will therefore start it.

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

Press Enter or Return to get back to the prompt.

Confirm that MySQL is running (Figure 2.23).

Figure 2.23. The mysqlshow utility will show a list of available databases, which also serves as a confirmation that MySQL is running.

At the prompt, type the following and press Enter or Return:

./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 user password, you'll need to add -p at the end of the command to be prompted for the root user password.

Stop MySQL (Figure 2.24).

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

Type the following at the prompt and press Enter or 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 user password, 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

Again, press Enter or Return to return to the prompt.


  • MySQL includes a MySQL Instance Manager with version 5.0.4 and later. This tool, which runs on Windows and Unix, can also be used to start and stop the server. See the MySQL manual for details.

  • Some Red Hat users have experienced problems starting MySQL using the preceding directions. If you installed MySQL using an RPM, then it may be already established as a service. If so, you can start mysqld using either service mysqld start or the linuxconf control panel. A last option would be to use the line

    /etc/rc.d/init.d/mysqld start.
  • On Unix systems (particularly Red Hat Linux), you might also have luck stopping MySQL with

    /etc/rc.d/init.d/mysqld stop.
  • The mysqld daemon (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