Run multiple servers on the same machine. In some cases, you may want to run multiple servers on the same machine. For example, you may want to test a new MySQL version so that the settings of your existing production system are not disturbed, or you may want to install an Internet service provider for an independent MySQL instance for different customers.
Run multiple servers on the same machine. In some cases, you may want to run multiple servers on the same machine. For example, you may want to test a new MySQL version so that the settings of your existing production system are not disturbed, or you may want to install an Internet service provider for an independent MySQL instance for different customers.
If you want to run multiple servers, the easiest way is to recompile the server with different TCP/IP ports and socket files, so they do not listen on the same TCP/IP Port or socket.
Assume that an existing server is configured as the default port number and socket file, use the configure command line to set the new server:
Shell>./configure -- with-tcp-port = port_number
-- With-unix-socket = file_name
-- Prefix =/usr/local/mysql-3.22.9
Port_number and file_name should be different from the default port number and socket file path, and
-- Prefix value should specify an installation directory different from the existing MySQL installation.
You can use this command to check the socket and port used by any currently executed MySQL:
Shell> mysqladmin-h hostname -- port = port_number variables
If you have a MySQL server running on the port you are using, you will get some of the most important
A table with configurable variables, including socket names.
You should also edit the initialization script (probably "mysql. server") of your machine to start and kill multiple mysqld servers.
You don't have to recompile a new MySQL server. You just need to start it with a different port and socket. You can change the port and socket by specifying the options used by safe_mysqld at runtime:
Shell>/path/to/safe_mysqld -- socket = file_name -- port = port_number
If you run a new server in the same database directory as the server on which logs are enabled, you should also use the -- log and -- log-update options of safe_mysqld to specify the name of the log file, otherwise, the two servers may be attempting to write the same log file.
Warning: You should never have two servers that update data in the same database! If your OS does not support fault-free system locking, this can lead to surprising things!
If you want to use another database directory for the second server, you can use
-- Datadir = path option.
When you want to connect to a running MySQL server that is different from the port compiled into your client program, you can use one of the following methods:
-- Host 'hostname' -- port = port_numer or [-- host localhost] -- socket = file_name
Start the customer.
In your C or Perl program, you can provide port and socket parameters when connecting to the MySQL server.
Before you start the client program, set the MYSQL_UNIX_PORT and MYSQL_TCP_PORT environment variables to point to the port of the Unix socket and TCP/IP. If you usually use a specific socket or port, you should put the command to set these environment variables into your ". login" file.
Specify the default socket and TCP/IP Port in the ". my. cnf" file in your home directory.