MySQL runs on many Unix and Unix-like systems, including those based on BSD Unix, System V Unix, and Linux. This section describes general procedures for running MySQL on them. The topics include the prerequisites to check prior to running the server, and arranging for server startup and shutdown. On Unix, it's best to use a dedicated login user and group for administering and running MySQL Server so that it can be run with permissions other than those of the root login. In this study guide, it's assumed that the user and group names both are mysql. 24.3.1. Server Startup Prerequisites on UnixBefore attempting to run MySQL Server on Unix, you should make sure that everything has been installed and that there is a login account to use for administering and running the server. You should also initialize the data directory if necessary. On Unix, precompiled MySQL distributions come in the form of RPM files or as compressed tar files. RPMs are used on Linux systems. tar files are available for many platforms. RPM installation for MySQL typically requires more than one RPM file because the distribution is split up into different RPMs. The most important RPM files are for the server and for the client programs, so at a minimum, you normally install both of them. If you want to run a Max version of the server, you'll also need a Max server RPM, which must be installed after the regular server RPM. The installation process for RPM files sets up a login account that has user and group names of mysql to use for administering and running the server. It also installs all the files, initializes the data directory and the mysql database that contains the initial MySQL accounts, registers a startup script named mysql in the /etc/init.d directory, and starts the server. The server is installed in /usr/sbin and the data directory is created at /var/lib/mysql. A tar file distribution is installed simply by unpacking it. For example, if you have a distribution named mysql-max-5.0.10-beta-sun-solaris2.9-sparc.tar.gz on Solaris, you can unpack it in /usr/local to create a subdirectory named mysql-max-5.0.10-beta-sun-solaris2.9-sparc. It's common to create a symbolic link named mysql in /usr/local that points to the installation directory so that it can be referred to more easily as /usr/local/mysql. This study guide assumes the latter pathname of the installation directory for MySQL as installed from a tar file on Unix. One advantage of setting up a symbolic link (besides that it's shorter than the name created by the tar file) is that when you upgrade to a newer version of MySQL, you can easily retarget the link to the new installation directory. Just delete the link and re-create it to point to the new directory. With tar file distributions, there is no automatic creation of a login account for running the server, and the data directory is not set up. You must create the login account and initialize the data directory yourself. The commands to set up a login account for administering and running the server vary for different versions of Unix. For purposes of this guide, it's assumed that you create an account that has user and group names of mysql. To initialize the data directory, change location into the installation directory and run the mysql_install_db script. For a tar file distribution, this script normally is located in the scripts directory, so you run it like this: shell> cd /usr/local/mysql shell> scripts/mysql_install_db To make sure that all directories and files that mysql_install_db creates have the proper ownership, run the script as just described while logged in as the mysql user. Alternatively, you can run it as root with the --user=mysql option: shell> cd /usr/local/mysql shell> scripts/mysql_install_db --user=mysql mysql_install_db creates the data directory and initializes the mysql and test databases. If you do not run this script, the server will complain when you run it later that it cannot find files in the mysql database. For example, the server will issue an error message such as Can't find file: ./host.frm. With a tar file distribution, you'll also need to install a startup script. That is covered in Section 24.3.2, "Choosing a Server Startup Method on Unix." Regardless of how you install MySQL on Unix (whether from RPM files or a tar file), the initial MySQL accounts have no passwords. After the server has been started, you should set up passwords as described in Section 35.5.1, "Securing the Initial MySQL Accounts." 24.3.2. Choosing a Server Startup Method on UnixThe server can be started on Unix using any of several different methods:
To have the server run automatically at system startup time, a startup script that's appropriate for your system must be installed:
If the server does not start properly, look in the error log. The default error log name on Unix is host_name.err in the data directory, where host_name is the name of your server host. To stop the server manually, use one of the following techniques:
mysqld_safe has no server shutdown capability. You can use mysqladmin shutdown instead. Note that if you forcibly terminate mysqld by using the kill -9 command to send it a signal, mysqld_safe will detect that mysqld terminated abnormally and will restart it. You can work around this by killing mysqld_safe first and then mysqld, but it's better to use mysqladmin shutdown, which initiates a normal (clean) server shutdown. The mysqld_multi script can be used to manage multiple servers. However, MySQL AB currently is developing another program called MySQL Instance Manager to be used for multiple-server management. This program will offer some significant improvements over mysqld_multi and eventually will replace it:
|