It's common to run a single MySQL server on a given machine, but it's possible to run multiple servers. This is a common scenario when you want to test a new release of MySQL on the same machine where you run your production server. Use of multiple servers also might be desirable for administrative purposes. If clients can be partitioned into groups that use distinct databases, you can run multiple servers, each one serving a single group of clients. Each group can have its own designated root user, and that root user won't be able to see databases that belong to other groups, as would be possible if all clients were to share the same server. Managing multiple servers is a more complex undertaking than running a single server because you must make sure that the servers do not interfere with each other. None of the servers can share resources that must be used exclusively by a single server. These resources include the following:
To make sure that each server manages a different data directory, start each one with a unique value for the --datadir option. Normally, having distinct data directories is sufficient to ensure distinct sets of log files and InnoDB files as well, because those files are created by default in the data directory if you specify their names using relative pathnames. On Unix, you can ensure that each server uses its own network interfaces by starting each with a unique value for the --port and --socket options to set up the TCP/IP and Unix socket file interfaces. On Windows, the --port option applies for TCP/IP; for servers that allow named-pipe or shared-memory connections, the options are as follows:
To set up Windows servers with distinct service names, follow the --install option of the service installation command with a service name. For example: shell> mysqld --install mysql1 shell> mysqld --install mysql2 Installed that way, when the servers start, they will read options from the [mysql1] and [mysql2] groups, respectively, in the standard option files. They'll also read options in the [mysqld] group as usual, which you can use for any options that are common to both services. Another way to install MySQL as a service is to follow the service name with an option naming the file from which the server should read options when it starts: shell> mysqld --install mysql1 --defaults-file=C:\mysql1.cnf shell> mysqld --install mysql2 --defaults-file=C:\mysql2.cnf In this case, each server ignores the standard option files when it starts and instead reads options only from the [mysqld] group of the option file named by the --defaults-file option. Each server installed as a Windows service can read the appropriate options for the data directory location and network interfaces from whichever option file and group is unique to it. On Windows, management of multiple servers is easiest if they all run as Windows services. Then you can use the native Windows tools such as the Services program that provides a graphical interface for service management. MySQL Administrator also can control MySQL services. If the MySQL servers do not run as services, you must start them manually and stop them using mysqladmin. On Unix, some administrative assistance is available for controlling multiple servers. mysqld_multi is a Perl script intended to make it easier to manage multiple servers on a single host. It can start or stop servers, or report on whether servers are running. mysqld_multi can either start servers directly, or indirectly by invoking mysqld_safe. (An advantage of using mysqld_safe is that it sets up the error log and monitors the server.) mysqld_multi requires installation of the Perl DBI module. 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. For example, mysqld_multi can stop local or remote servers, but can start only local servers. With MySQL Instance Manager, it will be possible to start remote servers as well. MySQL Instance Manager is planned for cross-platform deployment, so it will also be able to control servers on Windows. |