In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
What the editor wants to share with you this time is how to build multi-instance MySQL8 in CentOS 7. The article is rich in content. Interested friends can learn about it. I hope you can get something after reading this article.
cause
Recently, when refactoring began on the project, we may use the situation where the master is separated from adding reading and writing. I just want to build one locally to try the effect. As a result, Baidu found a lot of them, but few of them went to the pit themselves. Most of them copied other people's content. The key is that there will be errors in the actual application. The browser opened nearly 20 tabs, and several of them have problems. It doesn't work at all, and time is wasted. It will also make you very suffocated, so do it yourself.
I. preparation
1. First check and clean up the mysql-related files that exist in the system
# check for the existence of Mysql files find /-name mysql # Delete files or folders where mysql exists rm-rf / usr/lib64/mysql/ # check for the existence of mysql-related dependencies rpm-qa | grep mysql # uninstall mysql dependencies rpm-e mysql-.
2. Download the corresponding version of mysql installation file
Because I am using CentOS 7 64-bit, select the operating system shown below in the MySQL official website, and then select the tar package to download.
As explained here, why should I use the tar package for installation instead of using a normal installation that is common on the Internet and the other using the rpm installation method, because if the first one uses yum to install normally and the second one uses local installation, then the installation path cannot be specified and the two mysql cannot be put together for systematic management, so I use the tar package to install multiple instances here. And put it in the same directory for easy management and configuration.
# create a mysql user before downloading, why create a MySQL user? Because the extracted mysql files do not have any generic groups, and in order to avoid that MySQL cannot read some files during configuration and startup So it is recommended to use the mysql user to run mysql adduser mysql # to set the password passwd mysql # then enter the password # switch user su mysql # download Mysql's tar package wget https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-8.0.20-el7-x86_64.tar.gz # extract the file and rename the folder to mysql_01 tar xf mysql-8.0. 20-el7-x86_64.tar.gz. / mysql_01 # make a copy of mysql_01 and rename it mysql_02 cp-r. / mysql_01. / mysql_02/ # switch to root user Change the array of two mysql to mysql user, and then switch back to mysql user exit chown-R mysql:mysql / home/mysql/mysql_01/ / home/mysql/mysql_02/ su mysql
Second, modify the configuration
The next step is to configure MySQL. The configuration of the two MySQL is actually similar, only that the path is different. Here I will only show the configuration of mysql_01, and mysql_02 will replace the corresponding path with its own path.
1. Custom configuration my.cnf
# switch to cd. / mysql_01 # under the mysql_01 path to create a configuration file my.cnf, edit it directly with vim, and save it. Where # # is expressed as a required item # expressed as optional vim my.cnf-the following is the file content-[mysqld] # Port number port=10085 # # installation directory basedir=/home/mysql/mysql_01/ # data storage path datadir=/home/mysql/mysql_01/data/ # session file directory socket= / home/mysql/mysql_01/mysql.sock # maximum number of connection failures allowed max_connect_errors=10 # character set encoding on the server character-set-server=utf8 # default storage engine default-storage-engine=INNODB # default user user=mysql # enable slow query slow_query_log=on # slow query log file directory slow_query_log_file=/home/ Mysql/mysql_01/slow-query.log [client] # Port number used by the connection server port=10085 # session file socket=/home/mysql/mysql_01/mysql.sock # default character set encoding default-character-set=utf8-end of file content- # you can see that the data folder exists in the datadir entry in the configuration above But not under mysql_01, so you need to create a data folder mkdir data
2. Modify the default configuration that comes with it
Next, you need to modify the default configuration information of mysql.
# modify the default configuration information in the file vim. / support-files/mysql.server # modify all configurations related to basedir and datadir in the file to the current path
The figure below is as follows
And modify the path of the MySQL configuration file loaded in the file, and modify it to the my.cnf file you just created, as shown in the following figure. After the modification is completed, save and exit.
You also need to modify another file under support-files
# modify the mysqld_multi.server file vim. / support-files/mysqld_multi.server # in the support-files folder or modify the attributes basedir and datadir, as shown in the following figure
Initialize the installation and start the service
1. Initialize the installation
# switch to the root directory of mysql_01 cd / home/mysql/mysql_01/ # initialize the installation-- defaults-file indicates the configuration file specified for initialization-- console indicates that the initialization information will be printed on the console. / bin/mysqld-- defaults-file=/home/mysql/mysql_01/my.cnf-- initialize-- console-- user=mysql # initialization password will be printed in the console after successful initialization The approximate format is as follows: root@localhost: fa356fgss
2. Start the service
# when you start the mysql service of the current mysql_01 at the backend, you still need to specify the configuration file, because we set a socket parameter in the configuration file. Only by starting according to this configuration file will it be generated according to the path configured by socket. Otherwise, it will be automatically generated in / tmp/mysql.sock. If the mysql_02 is also generated in this way, an overlay will be formed, resulting in only one service being connected, or even an error. . / bin/mysqld_safe-- defaults-file=./my.cnf & # use the command to check whether the mysql service is started, as shown in the following figure netstat-nultp | grep 10085
Connect to the database and change the password
# from the above you can see that the mysql service has been started, then you can connect to MySQL. / bin/mysql-- socket=./mysql.sock-uroot-p # enter the initial password # modify the MySQL login password, here I change it to root, pay attention to the ending semicolon alter user root@localhost identified by "root"
After the same configuration, start mysql_02, and the effect is as follows
The above is the configuration of MySQL_01. The same MySQL_02 is the same as this. You only need to change the corresponding directory to your own file path. When multiple instances are installed, you can configure master-slave replication, read-write separation and other related configurations.
After reading this article on how to build multi-instance MySQL8 in CentOS 7, if you think the article is well written, you can share it with more people.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.