Recently, the amount of data on the company's server has increased, and I need to do a load and database read-write separation, so I set up a mysql master-slave server between the two servers, and recorded my ideas for other friends to learn.
1. Install two mysql instances. Readers install them by themselves (if they are installed on the same server, note that the mysql port cannot be the same). The figure shows the two services that I installed MySQL master and mysqlslave from:
Second, configure the main library
1. Stop the main mysql: net stop mysql
2. The my.ini file in the main library
[mysql]
# Set the default character set of the mysql client
default-character-set=utf8
[mysqld]
#Set 3306 port
port = 3306
# Set mysql installation directory
# Set the storage directory of mysql database data
# Maximum number of connections allowed
max_connections=200
# The character set used by the server defaults to the 8-bit encoding latin1 character set
character-set-server=utf8
# The default storage engine that will be used when creating a new table
default-storage-engine=INNODB
#=========Master-slave replication key configuration=====================
server_id=1 #The main library and the slave library need to be inconsistent, with a unique ID number, 1 to 32. Manual setting
log-bin=mysql-bin #Binary file storage path, stored in the root directory data
#binlog-do-db=test #Libraries that need to be copied, multiple libraries are separated by commas, if this item is not configured, all main libraries participate in replication
#binlog-ignore-db=mysql #Do not need to copy the library, the same as the previous item
#=========Master-slave replication key configuration=====================
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
3. Save, restart the main database, net start mysql
4. Create a user in the main library (specially used to connect from the library, note that this is established in the main library)
grant replication slave,reload,super on . to myslave@localhost identified by ‘myslave密码’ ;
myslave is the user name, myslave password is the password corresponding to the user, localhost can also write ip
5. flush privileges;
6.show master status; # Find the value of File and Position and record it
Three, configure the slave library:
1. Stop the slave library, net stop mysqlslave
2. From the library my.ini
[mysql]
# Set the default character set of the mysql client
default-character-set=utf8
[mysqld]
#Set 3306 port
port = 3307
# Set mysql installation directory
# Set the storage directory of mysql database data
# Maximum number of connections allowed
max_connections=200
# The character set used by the server defaults to the 8-bit encoding latin1 character set
character-set-server=utf8
# The default storage engine that will be used when creating a new table
default-storage-engine=INNODB
#========Master-slave replication key configuration======================
server_id=2 #The main library and the slave library need to be inconsistent
#binlog-do-db=test #Consistent with the description of the main library
#binlog-ignore-db=mysql # consistent with the main library description
#========Master-slave replication key configuration======================
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
3. Restart the slave library, net start mysqlslave and log in as root
4. Execute in the slave library
change master to master_host=’127.0.0.1’,master_user=’myslave’,master_password=’myslave’, master_log_file=’mysql-bin.000002’,master_log_pos=423;
//————————-
master_host= Fill in the IP of your main library here.
master_user='myslave' The user we created just now.
master_user='myslave' .. No explanation.
This is the value we got from show master status in the main library just now. Fill in by yourself according to the actual situation
master_log_file=’mysql-bin.000002’
master_log_pos=423
If your main library has other ports,
master_port=Port number
5. Execute stop slave from the library; then execute start slave;
6. View from the library: show slave status
that's it.
Fourth, verify master-slave replication
This concludes, I focus on the Internet of Things industry, and have a deep research on java docking with Internet of Things hardware devices. Welcome everyone to learn and communicate.