CentOS 7.0 how to start multiple MySQL instances tutorial (mysql-5.7.21), centosmysql-5.7.21

Source: Internet
Author: User

CentOS 7.0 how to start multiple MySQL instances tutorial (mysql-5.7.21), centosmysql-5.7.21

Configuration instructions

Linux: CentOS-7.0

MySQL version: 5.7.21

Start Multiple MySQL instances in Linux. Currently, there are two methods available: one is implemented through mysqld_multi.server officially provided, but I have not studied how this method is implemented yet; another method is to install multiple MySQL servers. I am using the second method. Two MySQL instances are successfully started. Next, let's introduce the operation process.

1. Install the first MySQL (5.7.21) Server

First of all, I installed mysql with a Binary Package: mysql-5.7.21-linux-glibc2.12-x86_64.tar.gz

1. Obtain the mysql Binary Package and decompress it using the tar command.mv mysql-5.7.21-linux-glibc2.12-x86_64 mysql_3306Command to rename the decompressed folder to a short name. Note the port number to be used for easy differentiation. You can decide where to place the extracted files. The difference is that if you do not name the extracted files as mysql and directly put them in the/usr/local directory, or use mysql reference in the/usr/local directory through ln, you need. cnf or specify in the startup command parameters (basedir = actual extract file path and datadir = actual export file path/data ). In mysql. server, you can use the vi command to open it.

2. After reading many mysql installation methods on the Internet, we will mention the addition of user groups, users: groupadd mysql and useradd-r-g mysql-s/bin/false mysql, added mysql users and mysql user groups. This depends on your actual needs, because I only use it myself. Without security issues, I will not add a new one, but directly use root. If you need to add users and user groups, you can find information online or see the https://dev.mysql.com/doc/refman/5.7/en/binary-installation.html In the MySQL official manual

3. Create my. cnf can be copied from another place. It is mainly used to specify parameters such as basedir, datadir, port number, and socket in the initialization file. It is my. cnf content. Replace the relevant parameters according to your actual path in the installation directory:

4. Follow the installation steps in the official documents and create a new mysql-files folder under the installation directory. I still know why to create this folder. Haha, the official document "the mysql-files directory provides a convenient location to use as the value for The secure_file_priv system variable, which limits import and export operations to a specific directory."

5. initialize mysql. First, add the data folder under the installation directory, then enter the bin folder under the installation directory, and execute the following command:“./mysqld --initialize --user=root --basedir=/data/program/mysql3306 --datadir=/data/program/mysql3306/data”. In linux, when a command carries a parameter, if the parameter name is the full name, two horizontal bars "--" are used. If the parameter is abbreviated, a horizontal bar "-" is used, for example ,. /mysql -- host = localhost and. /mysql-hlocalhost. In the above command to initialize mysql, replace the parameter value with your own path and user. If you only install one mysql instance in the/usr/local/mysql default directory, you do not need to specify the basedir and datadir parameters. If you want to re-initialize for some reason, you need to delete the content in the data directory first. You can choose to delete the entire data folder and then add:rm -rf data, mkdir dataAnd then you can execute the above initialization command to re-Initialize smoothly. Note that the default password will be found at the end of the prompt after the initialization is successful. Remember to use the default password when logging on to the client.

6. Create the certificate and key required for secure transmission and run the following command in the bin directory:“./mysql_ssl_rsa_setup --datadir=/data/program/mysql3306/data” In the same way, replace the parameter with your value. The default installation directory does not need to specify the datadir value. The role of this command is officially described as follows: "This program creates the SSL certificate and key files and RSA key-pair files required to support secure connections using SSL and secure password exchange using RSA over unencrypted connections, if those files are missing. this command creates an SSL Certificate and key-value pair for secure transmission using SSL and RSA over an unencrypted connection.

7. mysql Initialization is complete. You can start the mysql server. mysql 5.7 and later versions start the service by running the mysqld_safe command. You can also use mysql in the support-file directory. server, but mysql. server is also started using mysqld_safe. The command for mysqld_safe is as follows:“./mysqld_safe --defaults-file=/data/program/mysql3306/my.cnf  --user=root --port=3306 &”The key is to specify the path my. cnf, because I have not installed it in the default directory, and we want to install two mysql instances on one machine. Note that "-- defaults-file" must be the first parameter. Otherwise, an error is reported and a prompt is displayed. In addition, "&" at the end of the command is displayed. this tells the system to use the mysql instance as the background process so that the mysql server can continue running only when the command is exited.

For detailed parameters of mysql_safe command, refer to: http://www.bkjia.com/article/52259.htm

8. after starting the server, you can use the client to access the server and run the following command in the bin directory:“./mysql -uroot -P3306 -p”And then prompt to enter the password, then you enter the default password in step 5. Run the following command:set password=password('new password')Set your new password. Otherwise, the server will not allow you to perform other operations.

9. At this point, a mysql installation has been completed.

Ii. Install the nth MySQL (5.7.21) Server

With the above installation process, the installation of the nth mysql is basically the same as above. decompress the installation package, rename it to mysql_port, distinguish different mysql servers by port number, and then. in cnf and the commands executed above, replace the relevant path parameters with the corresponding path. By specifying the specific path, you can install and start multiple mysql instances on a linux machine. Which port must be specified when the client accesses the server?-P3306, P in upper case.

This is only a simple installation process of recording and learning, mysql also has a lot of configuration and functions need to pay attention to, there will be a chance to sort out later.

Summary

The above is all the content of this article. I hope the content of this article has some reference and learning value for everyone's learning or work. If you have any questions, please leave a message to us, thank you for your support.

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.