< Day Day Up > |
In some cases, you might want to run multiple mysqld servers on the same machine. You might want to test a new MySQL release while leaving your existing production setup undisturbed. Or you may want to give different users access to different mysqld servers that they manage themselves . (For example, you might be an Internet Service Provider that wants to provide independent MySQL installations for different customers.) To run multiple servers on a single machine, each server must have unique values for several operating parameters. These can be set on the command line or in option files. See Section 3.3, "Specifying Program Options." At least the following options must be different for each server:
If you use the following log file options, they must be different for each server:
Log file options are described in Section 4.8.6, "Log File Maintenance." If you want more performance, you can also specify the following options differently for each server, to spread the load between several physical disks:
Having different temporary directories is also recommended, to make it easier to determine which MySQL server created any given temporary file. Generally, each server should also use a different data directory, which is specified using the --datadir= path option. Warning: Normally you should never have two servers that update data in the same databases! This may lead to unpleasant surprises if your operating system doesn't support fault-free system locking! If (despite this warning) you run multiple servers using the same data directory and they have logging enabled, you must use the appropriate options to specify log file names that are unique to each server. Otherwise, the servers will try to log to the same files. This warning against sharing a data directory among servers also applies in an NFS environment. Allowing multiple MySQL servers to access a common data directory over NFS is a bad idea !
Make it easy for yourself: Forget about sharing a data directory among servers over NFS. A better solution is to have one computer that contains several CPUs and use an operating system that handles threads efficiently . If you have multiple MySQL installations in different locations, normally you can specify the base installation directory for each server with the -- basedir = path option to cause each server to use a different data directory, log files, and PID file. (The defaults for all these values are determined relative to the base directory.) In that case, the only other options you need to specify are the --socket and --port options. For example, suppose that you install different versions of MySQL using tar file binary distributions. These will install in different locations, so you can start the server for each installation using the command bin/mysqld_safe under its corresponding base directory. mysqld_safe will determine the proper --basedir option to pass to mysqld , and you need specify only the --socket and --port options to mysqld_safe . (For versions of MySQL older than 4.0, use safe_mysqld rather than mysqld_safe .) As discussed in the following sections, it is possible to start additional servers by setting environment variables or by specifying appropriate command-line options. However, if you need to run multiple servers on a more permanent basis, it will be more convenient to use option files to specify for each server those option values that must be unique to it. 4.9.1 Running Multiple Servers on WindowsYou can run multiple servers on Windows by starting them manually from the command line, each with appropriate operating parameters. On Windows NT-based systems, you also have the option of installing several servers as Windows services and running them that way. General instructions for running MySQL servers from the command line or as services are given in Section 2.2.1, "Installing MySQL on Windows." This section describes how to make sure that you start each server with different values for those startup options that must be unique per server, such as the data directory. These options are described in Section 4.9, "Running Multiple MySQL Servers on the Same Machine." 4.9.1.1 Starting Multiple Windows Servers at the Command LineTo start multiple servers manually from the command line, you can specify the appropriate options on the command line or in an option file. It's more convenient to place the options in an option file, but it's necessary to make sure that each server gets its own set of options. To do this, create an option file for each server and tell the server the filename with a --defaults-file option when you run it. Suppose that you want to run mysqld on port 3307 with a data directory of C:\mydata1 , and mysqld-max on port 3308 with a data directory of C:\mydata2 . (To do this, make sure that before you start the servers, each data directory exists and has its own copy of the mysql database that contains the grant tables.) Then create two option files. For example, create one file named C:\my-opts1.cnf that looks like this: [mysqld] datadir = C:/mydata1 port = 3307 Create a second file named C:\my-opts2.cnf that looks like this: [mysqld] datadir = C:/mydata2 port = 3308 Then start each server with its own option file: C:\> C:\mysql\bin\mysqld --defaults-file=C:\my-opts1.cnf C:\> C:\mysql\bin\mysqld-max --defaults-file=C:\my-opts2.cnf On NT, each server will start in the foreground (no new prompt appears until the server exits later); you'll need to issue those two commands in separate console windows. To shut down the servers, you must connect to the appropriate port number: C:\> C:\mysql\bin\mysqladmin --port=3307 shutdown C:\> C:\mysql\bin\mysqladmin --port=3308 shutdown Servers configured as just described will allow clients to connect over TCP/IP. If your version of Windows supports named pipes and you also want to allow named pipe connections, use the mysqld-nt or mysqld-max-nt servers and specify options that enable the named pipe and specify its name. Each server that supports named pipe connections must use a unique pipe name. For example, the C:\my-opts1.cnf file might be written like this: [mysqld] datadir = C:/mydata1 port = 3307 enable-named-pipe socket = mypipe1 Then start the server this way: C:\> C:\mysql\bin\mysqld-nt --defaults-file=C:\my-opts1.cnf Modify C:\my-opts2.cnf similarly for use by the second server. 4.9.1.2 Starting Multiple Windows Servers as ServicesOn NT-based systems, a MySQL server can be run as a Windows service. The procedures for installing, controlling, and removing a single MySQL service are described in Section 2.2.1.7, "Starting MySQL as a Windows Service." As of MySQL 4.0.2, you can install multiple servers as services. In this case, you must make sure that each server uses a different service name in addition to all the other parameters that must be unique per server. For the following instructions, assume that you want to run the mysqld-nt server from two different versions of MySQL that are installed at C:\mysql-4.0.8 and C:\mysql-4.0.17 , respectively. (This might be the case if you're running 4.0.8 as your production server, but want to test 4.0.17 before upgrading to it.) The following principles apply when installing a MySQL service with the --install or --install-manual option:
Note: Before MySQL 4.0.17, only a server installed using the default service name ( MySQL ) or one installed explicitly with a service name of mysqld will read the [mysqld] group in the standard option files. As of 4.0.17, all servers read the [mysqld] group if they read the standard option files, even if they are installed using another service name. This allows you to use the [mysqld] group for options that should be used by all MySQL services, and an option group named after each service for use by the server installed with that service name. Based on the preceding information, you have several ways to set up multiple services. The following instructions describe some examples. Before trying any of them, be sure that you shut down and remove any existing MySQL services first.
To remove multiple services, use mysqld --remove for each one, specifying a service name following the --remove option. If the service name is the default ( MySQL ), you can omit it. 4.9.2 Running Multiple Servers on UnixThe easiest way to run multiple servers on Unix is to compile them with different TCP/IP ports and Unix socket files so that each one is listening on different network interfaces. Also, by compiling in different base directories for each installation, that automatically results in different compiled-in data directory, log file, and PID file locations for each of your servers. Assume that an existing server is configured for the default TCP/IP port number (3306) and Unix socket file ( /tmp/mysql.sock ). To configure a new server to have different operating parameters, use a configure command something like this: shell> ./configure --with-tcp-port= port_number \ --with-unix-socket-path= file_name \ --prefix=/usr/local/mysql-4.0.17 Here, port_number and file_name must be different from the default TCP/IP port number and Unix socket file pathname, and the --prefix value should specify an installation directory different than the one under which the existing MySQL installation is located. If you have a MySQL server listening on a given port number, you can use the following command to find out what operating parameters it is using for several important configurable variables, including the base directory and Unix socket filename: shell> mysqladmin --host= host_name --port= port_number variables With the information displayed by that command, you can tell what option values not to use when configuring an additional server. Note that if you specify localhost as a hostname, mysqladmin will default to using a Unix socket file connection rather than TCP/IP. In MySQL 4.1, you can explicitly specify the connection protocol to use by using the --protocol={TCP SOCKET PIPE MEMORY} option. You don't have to compile a new MySQL server just to start with a different Unix socket file and TCP/IP port number. It is also possible to specify those values at runtime. One way to do so is by using command-line options: shell> mysqld_safe --socket= file_name --port= port_number To start a second server, provide different --socket and --port option values, and pass a --datadir= path option to mysqld_safe so that the server uses a different data directory. Another way to achieve a similar effect is to use environment variables to set the Unix socket filename and TCP/IP port number: shell> MYSQL_UNIX_PORT=/tmp/mysqld-new.sock shell> MYSQL_TCP_PORT=3307 shell> export MYSQL_UNIX_PORT MYSQL_TCP_PORT shell> mysql_install_db --user=mysql shell> mysqld_safe --datadir= /path/to/datadir & This is a quick way of starting a second server to use for testing. The nice thing about this method is that the environment variable settings will apply to any client programs that you invoke from the same shell. Thus, connections for those clients automatically will be directed to the second server! Appendix B, "Environment Variables," includes a list of other environment variables you can use to affect mysqld . For automatic server execution, your startup script that is executed at boot time should execute the following command once for each server with an appropriate option file path for each command: mysqld_safe --defaults-file= path Each option file should contain option values specific to a given server. On Unix, the mysqld_multi script is another way to start multiple servers. See Section 4.1.5, "The mysqld_multi Program for Managing Multiple MySQL Servers." 4.9.3 Using Client Programs in a Multiple-Server EnvironmentWhen you want to connect with a client program to a MySQL server that is listening to different network interfaces than those compiled into your client, you can use one of the following methods :
|
< Day Day Up > |