CentOS 7 下 MySQL 5.7.x 安装
安装准备
安装包准备
mysql-5.7.25-1.el7.x86_64.rpm-bundle.tar
卸载 MariaDB
mariadb-libs-5.5.56-2.el7.x86_64
MySQL 5.7.x 安装
安装 mysql-community-common
warning: mysql-community-common-5.7.25-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing.. .
Updating / installing.. .
1:mysql-community-common-5.7.25-1.e
warning: mysql-community-libs-5.7.25-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing.. .
Updating / installing.. .
1:mysql-community-libs-5.7.25-1.el7
安装 mysql-community-client
warning: mysql-community-client-5.7.25-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing.. .
Updating / installing.. .
1:mysql-community-client-5.7.25-1.e
warning: mysql-community-server-5.7.25-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
error: Failed dependencies:
net-tools is needed by mysql-community-server-5.7.25-1.el7.x86_64
Loaded plugins: fastestmirror
Determining fastest mirrors
* base: mirror.bit.edu.cn
* extras: mirror.bit.edu.cn
* updates: mirrors.huaweicloud.com
base | 3.6 kB 00:00:00
extras | 2.9 kB 00:00:00
updates | 2.9 kB 00:00:00
( 1/4) : base/7/x86_64/group_gz | 153 kB 00:00:00
( 2/4) : extras/7/x86_64/primary_db | 205 kB 00:00:00
( 3/4) : updates/7/x86_64/primary_db | 3.0 MB 00:00:00
( 4/4) : base/7/x86_64/primary_db | 6.1 MB 00:00:01
Resolving Dependencies
--> Running transaction check
---> Package net-tools.x86_64 0:2.0-0.25.20131004git.el7 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
== == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == =
Package Arch Version Repository Size
== == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == =
Installing:
net-tools x86_64 2.0-0.25.20131004git.el7 base 306 k
Transaction Summary
== == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == =
Install 1 Package
Total download size: 306 k
Installed size: 917 k
Downloading packages:
warning: /var/cache/yum/x86_64/7/base/packages/net-tools-2.0-0.25.20131004git.el7.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID f4a80eb5: NOKEY
Public key for net-tools-2.0-0.25.20131004git.el7.x86_64.rpm is not installed
net-tools-2.0-0.25.20131004git.el7.x86_64.rpm | 306 kB 00:00:00
Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
Importing GPG key 0xF4A80EB5:
Userid : "CentOS-7 Key (CentOS 7 Official Signing Key) <security@centos.org>"
Fingerprint: 6341 ab27 53d7 8a78 a7c2 7bb1 24c6 a8a7 f4a8 0eb5
Package : centos-release-7-5.1804.el7.centos.x86_64 ( @anaconda)
From : /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Warning: RPMDB altered outside of yum.
** Found 2 pre-existing rpmdb problem( s) , 'yum check' output follows:
2:postfix-2.10.1-6.el7.x86_64 has missing requires of libmysqlclient.so.18( ) ( 64bit)
2:postfix-2.10.1-6.el7.x86_64 has missing requires of libmysqlclient.so.18( libmysqlclient_18) ( 64bit)
Installing : net-tools-2.0-0.25.20131004git.el7.x86_64 1/1
Verifying : net-tools-2.0-0.25.20131004git.el7.x86_64 1/1
Installed:
net-tools.x86_64 0:2.0-0.25.20131004git.el7
Complete!
安装 mysql-community-server
warning: mysql-community-server-5.7.25-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Sign ature, key ID 5072e1f5: NOKEY
Preparing.. .
Updating / installing.. .
1:mysql-community-server-5.7.25-1.e
datadir= /home/autoInstall_1.2.1/mysql/data
character-set-server= utf8
collation-server= utf8_general_ci
2020-07-13T05:21:02.798254Z 1 [ Note] A temporary password is generated for root@localhost: *) 3QpY%yh1rw
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.25
Copyright ( c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
mysql> set password = password( "Test@MySQL1234!" ) ;
Query OK, 0 rows affected, 1 warning ( 0.00 sec)
mysql> grant all privileges on *.* to 'root' @'%' identified by 'Test@MySQL1234!' ;
Query OK, 0 rows affected, 1 warning ( 0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected ( 0.00 sec)
MySQL 主从配置
主节点
server-id = 119
log-bin = master-bin
mysql> GRANT REPLICATION SLAVE,REPLICATION CLIENT ON *.* TO 'mysql132' @'%' identified by 'Jhmk@MySQL2345!' ;
Query OK, 0 rows affected, 1 warning ( 0.00 sec)
mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected ( 0.01 sec)
从节点
server-id = 119
mysql> CHANGE MASTER TO MASTER_HOST= '10.1.0.119' ,MASTER_PORT= 3306,MASTER_user= 'mysql132' ,MASTER_PASSWORD= 'Jhmk@MySQL2345!' ;
Query OK, 0 rows affected, 2 warnings ( 0.03 sec)
mysql> start slave;
Query OK, 0 rows affected ( 0.00 sec)
mysql> show master status \G
*************************** 1. row ***************************
File: master-bin.000001
Position: 613
Binlog_Do_DB:
Binlog_Ignore_DB:
Executed_Gtid_Set:
1 row in set ( 0.00 sec)
mysql> show slave status \G
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 10.1.0.119
Master_User: mysql132
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: master-bin.000001
Read_Master_Log_Pos: 613
Relay_Log_File: hessian05-relay-bin.000002
Relay_Log_Pos: 828
Relay_Master_Log_File: master-bin.000001
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
Replicate_Do_DB:
Replicate_Ignore_DB:
Replicate_Do_Table:
Replicate_Ignore_Table:
Replicate_Wild_Do_Table:
Replicate_Wild_Ignore_Table:
Last_Errno: 0
Last_Error:
Skip_Counter: 0
Exec_Master_Log_Pos: 613
Relay_Log_Space: 1039
Until_Condition: None
Until_Log_File:
Until_Log_Pos: 0
Master_SSL_Allowed: No
Master_SSL_CA_File:
Master_SSL_CA_Path:
Master_SSL_Cert:
Master_SSL_Cipher:
Master_SSL_Key:
Seconds_Behind_Master: 0
Master_SSL_Verify_Server_Cert: No
Last_IO_Errno: 0
Last_IO_Error:
Last_SQL_Errno: 0
Last_SQL_Error:
Replicate_Ignore_Server_Ids:
Master_Server_Id: 119
Master_UUID: bbce4327-b150-11ea-942f-fa163e3f3868
Master_Info_File: /home/autoInstall_1.2.1/mysql/data/master.info
SQL_Delay: 0
SQL_Remaining_Delay: NULL
Slave_SQL_Running_State: Slave has read all relay log; waiting for more updates
Master_Retry_Count: 86400
Master_Bind:
Last_IO_Error_Timestamp:
Last_SQL_Error_Timestamp:
Master_SSL_Crl:
Master_SSL_Crlpath:
Retrieved_Gtid_Set:
Executed_Gtid_Set:
Auto_Position: 0
Replicate_Rewrite_DB:
Channel_Name:
Master_TLS_Version:
1 row in set ( 0.00 sec)
主从测试
主节点
mysql> CREATE DATABASE ` TEST_SYNC` ;
Query OK, 1 row affected ( 0.01 sec)
mysql> USE ` TEST_SYNC`
Database changed
mysql> CREATE TABLE ` SYNC_01` ( ` ID` INT( 11) NOT NULL AUTO_INCREMENT,` NAME` VARCHAR( 255) NOT NULL,PRIMARY KEY ( ` ID` )) ENGINE= InnoDB AUTO_INCREMENT= 2 DEFAULT CHARSET= utf8;
Query OK, 0 rows affected ( 0.03 sec)
mysql> SHOW DATABASES;
+--------------------+
| Database |
+--------------------+
| information_schema |
| TEST_SYNC |
| mysql |
| performance_schema |
| sys |
+--------------------+
5 rows in set ( 0.00 sec)
mysql> USE TEST_SYNC
Database changed
mysql> SHOW TABLES;
+---------------------+
| Tables_in_TEST_SYNC |
+---------------------+
| SYNC_01 |
+---------------------+
1 row in set ( 0.00 sec)
mysql> DESC SYNC_01;
+-------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------+--------------+------+-----+---------+----------------+
| ID | int( 11) | NO | PRI | NULL | auto_increment |
| NAME | varchar( 255) | NO | | NULL | |
+-------+--------------+------+-----+---------+----------------+
2 rows in set ( 0.01 sec)
mysql> show slave hosts;
+-----------+------+------+-----------+--------------------------------------+
| Server_id | Host | Port | Master_id | Slave_UUID |
+-----------+------+------+-----------+--------------------------------------+
| 132 | | 3306 | 119 | a909a62d-c1cd-11ea-ab37-fa163e651b69 |
+-----------+------+------+-----------+--------------------------------------+
1 row in set ( 0.00 sec)
mysql> show binary logs;
+-------------------+-----------+
| Log_name | File_size |
+-------------------+-----------+
| master-bin.000001 | 1099 |
+-------------------+-----------+
1 row in set ( 0.00 sec)
mysql> show binlog events;
+-------------------+-----+----------------+-----------+-------------+---------------------------------------------------------------------
| Log_name | Pos | Event_type | Server_id | End_log_pos | Info
+-------------------+-----+----------------+-----------+-------------+---------------------------------------------------------------------
| master-bin.000001 | 4 | Format_desc | 119 | 123 | Server ver: 5.7.25-log, Binlog ver: 4
| master-bin.000001 | 123 | Previous_gtids | 119 | 154 |
| master-bin.000001 | 154 | Anonymous_Gtid | 119 | 219 | SET @@SESSION.GTID_NEXT= 'ANONYMOUS'
| master-bin.000001 | 219 | Query | 119 | 461 | GRANT REPLICATION SLAVE, REPLICATION CLIENT ON *.* TO 'mysql132' @'%'
| master-bin.000001 | 461 | Anonymous_Gtid | 119 | 526 | SET @@SESSION.GTID_NEXT= 'ANONYMOUS'
| master-bin.000001 | 526 | Query | 119 | 613 | FLUSH PRIVILEGES
| master-bin.000001 | 613 | Anonymous_Gtid | 119 | 678 | SET @@SESSION.GTID_NEXT= 'ANONYMOUS'
| master-bin.000001 | 678 | Query | 119 | 789 | CREATE DATABASE ` TEST_SYNC`
| master-bin.000001 | 789 | Anonymous_Gtid | 119 | 854 | SET @@SESSION.GTID_NEXT= 'ANONYMOUS'
| master-bin.000001 | 854 | Query | 119 | 1099 | use ` TEST_SYNC` ; CREATE TABLE ` SYNC_01` ( ` ID` INT( 11) NOT NULL AUTO_
+-------------------+-----+----------------+-----------+-------------+---------------------------------------------------------------------
10 rows in set ( 0.00 sec)
从节点
mysql> SHOW DATABASES;
+--------------------+
| Database |
+--------------------+
| information_schema |
| TEST_SYNC |
| mysql |
| performance_schema |
| sys |
+--------------------+
5 rows in set ( 0.00 sec)
mysql> USE TEST_SYNC
Database changed
mysql> SHOW TABLES;
+---------------------+
| Tables_in_TEST_SYNC |
+---------------------+
| SYNC_01 |
+---------------------+
1 row in set ( 0.00 sec)
mysql> DESC SYNC_01;
+-------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------+--------------+------+-----+---------+----------------+
| ID | int( 11) | NO | PRI | NULL | auto_increment |
| NAME | varchar( 255) | NO | | NULL | |
+-------+--------------+------+-----+---------+----------------+
2 rows in set ( 0.01 sec)