Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to start two mysql instances on one CVM at the same time

2025-01-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

The following is about how to start two mysql instances on one CVM at the same time. I'm sure you've read similar articles. What's the difference between what we bring to everyone? Let's take a look at the body. I'm sure you'll get something after seeing how to start two mysql instances on one CVM at the same time.

Operating environment: centos6.8

Sometimes, due to the shortage of hardware resources of CVM, new mysql services are needed. At this point, we can deploy two mysql instances on one CVM to solve the problem.

1. Create a new mysql instance data storage directory:

Mkdir-p / data/mysql_3307

2. Make a copy of the my.cnf configuration file, and make several copies if you open several ports.

Cp / etc/my.cnf / data/mysql_3307/my.cnf

3. Modify the / data/mysql_3307/my.cnf file, change the default port 3306 to 3307, and modify socket,basedir,datadir according to the actual situation.

[client]

Port = 3307

Socket = / tmp/mysql_3307.sock

Default-character-set = utf8

The MySQL server

[mysqld]

Port = 3307

User = mysql

Socket = / tmp/mysql_3307.sock

Basedir = / usr

Datadir = / data/mysql_3307

Character-set-server = utf8

Log-error = / data/mysql_3307/error.log

Pid-file = / data/mysql_3307/localhost.localdomain.pid

4. Initialize the database:

Mysql_install_db-basedir=/usr-datadir=/data/mysql_3307-user=mysql

Mysql is installed by yum, so basedir=/usr is fine, and it automatically looks for the installation directory of mysql under / usr.

If the mysql is compiled and installed by the source package, if the installation path is in / usr/local/mysql

Cd / usr/local/mysql/scripts/

. / mysql_install_db-- basedir=/usr/local/mysql-- datadir=/data/mysql_3307-- user=mysql

5. To start mysql, specify the .cnf file to start

Mysqld_safe-defaults-file=/data/mysql_3307/my.cnf-user=mysql &

6. To stop MYSQL, you need to specify the corresponding sock file.

Mysqladmin-uroot-S / tmp/mysql_3307.sock shutdown

7. Log in to the mysql of port 3307

Mysql-S / tmp/mysql_3307.sock-P 3307

Start, stop, restart mysql scripts:

#! / bin/bash

# mysql stop\ start\ restart script this script is only for mysql installed by yum and a password has been set for root.

# init

Port=3307

Mysql_user= "root"

Mysql_pwd= "123456"

CmdPath= "/ usr/bin"

Mysqlsock= "/ tmp/mysql$ {port} .sock"

# startup function

Function_start_mysql ()

{

If [!-e "$mysql_sock"]; then

Printf "Starting MySQL...\ n"

${CmdPath} / mysqld_safe-defaults-file=/data/mysql_3307/my.cnf-user=mysql 2 > & 1 > / dev/null &

Else

Printf "MySQL is running...\ n"

Exit

Fi

}

# stop function

Function_stop_mysql ()

{

If [!-e "$mysql_sock"]; then

Printf "MySQL is stopped...\ n"

Exit

Else

Printf "Stoping MySQL...\ n"

${CmdPath} / mysqladmin-u ${mysql_user}-p$ {mysql_pwd}-S ${mysql_sock} shutdown

Fi

}

# restart function

Function_restart_mysql ()

{

Printf "Restarting MySQL...\ n"

Function_stop_mysql

Sleep 2

Function_start_mysql

}

Case $1 in

Start)

Function_start_mysql

Stop)

Function_stop_mysql

Restart)

Function_restart_mysql

*)

Printf "Usage: / data/mysql_3307 {start | stop | restart}\ n"

Esac

Do you think you want to start two mysql instances on one CVM at the same time? If you want to know more about it, you can continue to follow our industry information section.

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.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report