Running multiple MySQL servers on the same machine

Source: Internet
Author: User
Tags command line mysql version socket port number

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 your existing production system settings are not disturbed, or you may want to provide a separate MySQL installation for different customers with an Internet service provider.

If you want to run multiple servers, the easiest way to do this is to recompile the server with different TCP/IP ports and socket files, so they are not listening on the same TCP/IP port or socket.

If an existing server is configured as the default port number and socket file, set up a new server with one such configure command line:

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 an installation directory that is different from the existing MySQL installation.

You can use this command to check the sockets and ports used by any currently executing 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 a list of some of the most important configurable variables for MySQL, including socket names, and so on.

You should also edit your machine's initialization script (possibly "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 ports and sockets by specifying the options that you use at runtime Safe_mysqld:
shell>/path/to/safe_mysqld--socket=file_name--port=port_number

If you are running a new server under the same database directory as another server that opens the log, you should also use the Safe_mysqld--log and--log-update options to specify the name of the log file, otherwise two servers may be trying to write to the same log file.

Warning: Typically you should never have 2 servers that update data in the same database! If your OS does not support a fail-safe (Fault-free) system lock, this can cause amazing things to happen!

If you want to use another database directory for a second server, you can use the Safe_mysqld

--datadir=path option.
When you want to connect a running, using a MySQL server that is different from the one that is compiled into your client program, you can use either 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 give the 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, pointing to the UNIX sockets and TCP/IP ports. If you typically use a specific socket or port, you should put commands for setting these environment variables into your ". Login" file.

Specify the default socket and TCP/IP port in the ". My.cnf" file in your home directory.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.