Method to run multiple MySQL servers simultaneously

  • 2020-05-06 11:48:25
  • OfStack

If you want to run multiple servers, the easiest way is to recompile the servers with different TCP/IP ports and socket files, so they are not listening for the same TCP/IP port or socket.
Suppose an existing server is configured with a default port number and socket file,   then set up the new server with a command line like configure:

shell >   ./configure   --with-tcp-port=port_number  
--with-unix-socket=file_name  
--prefix=/usr/local/mysql-3.22.9

Here port_number and file_name should be different from the default port number and socket file pathname, and
The prefix value should specify a different installation directory from the existing MySQL installation.

You can use this command to check the socket and port used by any currently executing MySQL:
shell >   mysqladmin   -h   hostname   --port=port_number   variables
If you have an MySQL server running on the port you are using, you will get some of the most important
of MySQL A list of configurable variables, including socket names, and so on.
You should also edit your machine's initialization script (probably "mysql.server") to start and kill multiple mysqld servers.
You don't have to recompile a new MySQL server, just start with a different port and socket.   you can change the port and socket by specifying the option to be used at run time by safe_mysqld:
shell >   /path/to/safe_mysqld   --socket=file_name   --port=port_number
If you are running the new server in the same database directory as the other server where the log is started, you should also specify the name of the log file using the --log and -- log-update options of safe_mysqld. Otherwise, both servers may be trying to write to the same log file.

Warning: you should never have two servers updating data in the same database!   if your OS does not support fail-free (fault-free) system locking, this can lead to something surprising!
If you want to use another database directory for the second server, you can use safe_mysqld with
- datadir = path options.
When you want to connect to a running   server that USES a different port than the MySQL server compiled into your client, you can use one of the following methods:
The & # 65533; --host   'hostname'   --port=port_numer or [--host   localhost]   --socket=file_name
Start the customer.
In your C or Perl programs, you can give port and socket parameters when connecting to the MySQL server.
Before you start the client, set the MYSQL_UNIX_PORT and MYSQL_TCP_PORT environment variables,   pointing to the Unix socket and TCP/IP ports. If you normally use a particular socket or port, you should put the command to set these environment variables in your ".login "file.
Specify the default socket and TCP/IP port in the file ".my.cnf "in your home directory.

Related articles: