mysql5.7稳定版使用

mysql5.7稳定版使用

设置主机名关闭防火墙

bash 复制代码
[root@localhost ~ 09:49:25]# hostnamectl set-hostname mysql01
[root@localhost ~ 09:49:36]# bash
[root@mysql01 ~ 09:49:38]# systemctl disable firewalld.service --now
Removed symlink /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.

安装mysql5.7

bash 复制代码
[root@mysql01 ~ 09:49:45]#  yum -y install ncurses ncurses-devel bison cmake gcc gcc-c++
Loaded plugins: fastestmirror, langpacks
Existing lock /var/run/yum.pid: another copy is running as pid 2785.
Another app is currently holding the yum lock; waiting for it to exit...
[root@mysql01 ~ 09:51:26]# kill -9 2785
[root@mysql01 ~ 09:52:07]#  yum -y install ncurses ncurses-devel bison cmake gcc gcc-c++
BDB2053 Freeing read locks for locker 0x64c: 2785/140037824608064
[root@mysql01 ~ 09:52:47]# useradd -s /sbin/nologin mysql
[root@mysql01 ~ 09:53:12]# tar zxvf mysql-5.7.17.tar.gz -C /opt/
mysql-5.7.17/
mysql-5.7.17/.gitignore
mysql-5.7.17/BUILD/
[root@mysql01 ~ 09:49:45]# tar zxvf boost_1_59_0.tar.gz -C /usr/local/
boost_1_59_0/tools/quickbook/test/xml_escape-1_2.quickbook
boost_1_59_0/tools/quickbook/test/xml_escape-1_5.gold
boost_1_59_0/tools/quickbook/test/xml_escape-1_5.quickbook
[root@mysql01 ~ 09:55:57]# cd /usr/local/
[root@mysql01 local 09:56:35]# mv boost_1_59_0 boost
[root@mysql01 local 09:56:49]# cd /opt/mysql-5.7.17/
[root@mysql01 mysql-5.7.17 09:57:14]# cmake \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock \
-DSYSCONFDIR=/etc \
-DSYSTEMD_PID_DIR=/usr/local/mysql \
-DDEFAULT_CHARSET=utf8  \
-DDEFAULT_COLLATION=utf8_general_ci \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_ARCHIVE_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DWITH_PERFSCHEMA_STORAGE_ENGINE=1 \
-DMYSQL_DATADIR=/usr/local/mysql/data \
-DWITH_BOOST=/usr/local/boost \
-DWITH_SYSTEMD=1
[root@mysql01 mysql-5.7.17 10:00:30]# make && make install
Scanning dependencies of target INFO_BIN
[  0%] Built target INFO_BIN
等待1小时
-- Installing: /usr/local/mysql/support-files/magic
-- Installing: /usr/local/mysql/share/aclocal/mysql.m4
-- Installing: /usr/local/mysql/support-files/mysql.server
[root@mysql01 mysql-5.7.17 11:02:09]# chown -R mysql.mysql /usr/local/mysql/
[root@mysql01 mysql-5.7.17 11:03:31]# vim /etc/my.cnf
[root@mysql01 mysql-5.7.17 11:07:46]#  chown mysql:mysql /etc/my.cnf
[root@mysql01 mysql-5.7.17 11:07:52]# echo 'PATH=/usr/local/mysql/bin:/usr/local/mysql/lib:$PATH' >>/etc/profile
[root@mysql01 mysql-5.7.17 11:08:10]# echo 'export PATH' >> /etc/profile
[root@mysql01 mysql-5.7.17 11:08:18]# source /etc/profile
[root@mysql01 mysql-5.7.17 11:08:26]#  cd /usr/local/mysql/
[root@mysql01 mysql 11:08:32]# bin/mysqld \
> --initialize-insecure \--user=mysql \--basedir=/usr/local/mysql \--datadir=/usr/local/mysql/data
2026-06-05T03:08:51.736677Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2026-06-05T03:08:51.968786Z 0 [Warning] InnoDB: New log files created, LSN=45790
2026-06-05T03:08:52.015532Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2026-06-05T03:08:52.070541Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: e13bbd13-608b-11f1-9c13-000c2900c45c.
2026-06-05T03:08:52.071549Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2026-06-05T03:08:52.072084Z 1 [Warning] root@localhost is created with an empty password ! Please consider switching off the --initialize-insecure option.
[root@mysql01 mysql 11:08:53]# cp /usr/local/mysql/usr/lib/systemd/system/mysqld.service /usr/lib/systemd/system/
[root@mysql01 mysql 11:09:19]#  systemctl daemon-reload
[root@mysql01 mysql 11:09:26]# systemctl start mysqld
[root@mysql01 mysql 11:09:33]#  netstat -anpt | grep 3306
tcp6       0      0 :::3306                 :::*                    LISTEN      70961/mysqld
[root@mysql01 mysql 11:09:39]# systemctl enable mysqld
Created symlink from /etc/systemd/system/multi-user.target.wants/mysqld.service to /usr/lib/systemd/system/mysqld.service.
[root@mysql01 mysql 11:09:51]# mysqladmin -uroot password "huawei"
mysqladmin: [Warning] Using a password on the command line interface can be insecure.
Warning: Since password will be sent to server in plain text, use ssl connection to ensure password safety.
[root@mysql01 mysql 11:10:01]# mysql -uroot -phuawei
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.7.17 Source distribution

Copyright (c) 2000, 2016, 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>  grant all privileges on *.* to 'root'@'%' identified by 'huawei' with grant option;
Query OK, 0 rows affected, 1 warning (0.00 sec)

sql使用

sql 复制代码
[root@mysql01 ~ 11:14:14]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.17 Source distribution

Copyright (c) 2000, 2016, 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> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
4 rows in set (0.00 sec)

mysql> create database school;
Query OK, 1 row affected (0.00 sec)

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| school             |
| sys                |
+--------------------+
5 rows in set (0.00 sec)

mysql> use school;
Database changed
mysql> show tables;
Empty set (0.01 sec)

mysql> create table info (
    -> id int not null primary key auto_increment,
    -> name char(10) not null,
    -> score decimal(5,2),
    -> address char(50) default '南京',
    -> hobby int not null
    -> );
Query OK, 0 rows affected (0.01 sec)

mysql> show tables;
+------------------+
| Tables_in_school |
+------------------+
| info             |
+------------------+
1 row in set (0.00 sec)

mysql> describe info;
+---------+--------------+------+-----+---------+----------------+
| Field   | Type         | Null | Key | Default | Extra          |
+---------+--------------+------+-----+---------+----------------+
| id      | int(11)      | NO   | PRI | NULL    | auto_increment |
| name    | char(10)     | NO   |     | NULL    |                |
| score   | decimal(5,2) | YES  |     | NULL    |                |
| address | char(50)     | YES  |     | 南京    |                |
| hobby   | int(11)      | NO   |     | NULL    |                |
+---------+--------------+------+-----+---------+----------------+
5 rows in set (0.03 sec)

mysql> insert into info (name,score,address,hobby) values ('happysuperman',60,'星星球g',1);
ERROR 1406 (22001): Data too long for column 'name' at row 1
mysql> insert into info (name,score,address,hobby) values ('开心超人',60,'星星球g',1);
Query OK, 1 row affected (0.00 sec)

mysql> select * from info;
+----+--------------+-------+------------+-------+
| id | name         | score | address    | hobby |
+----+--------------+-------+------------+-------+
|  1 | 开心超人     | 60.00 | 星星球g    |     1 |
+----+--------------+-------+------------+-------+
1 row in set (0.00 sec)

mysql> insert into info (name,score,address,hobby) values ('谜亚星',90,'盟学园',2);
Query OK, 1 row affected (0.00 sec)

mysql> insert into info (name,score,address,hobby) values ('汤姆',20,'猫鼠',3);
Query OK, 1 row affected (0.00 sec)

mysql> select * from info;
+----+--------------+-------+------------+-------+
| id | name         | score | address    | hobby |
+----+--------------+-------+------------+-------+
|  1 | 开心超人     | 60.00 | 星星球g    |     1 |
|  2 | 谜亚星       | 90.00 | 盟学园     |     2 |
|  3 | 汤姆         | 20.00 | 猫鼠       |     3 |
+----+--------------+-------+------------+-------+
3 rows in set (0.00 sec)

mysql> insert into info (name,score,address,hobby) values ('华伦',80,default,4);
Query OK, 1 row affected (0.01 sec)

mysql> select * from info;
+----+--------------+-------+------------+-------+
| id | name         | score | address    | hobby |
+----+--------------+-------+------------+-------+
|  1 | 开心超人     | 60.00 | 星星球g    |     1 |
|  2 | 谜亚星       | 90.00 | 盟学园     |     2 |
|  3 | 汤姆         | 20.00 | 猫鼠       |     3 |
|  4 | 华伦         | 80.00 | 南京       |     4 |
+----+--------------+-------+------------+-------+
4 rows in set (0.00 sec)

mysql> update info set address='星星球' where name='开心超人';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 0

mysql> select * from info;
+----+--------------+-------+-----------+-------+
| id | name         | score | address   | hobby |
+----+--------------+-------+-----------+-------+
|  1 | 开心超人     | 60.00 | 星星球    |     1 |
|  2 | 谜亚星       | 90.00 | 盟学园    |     2 |
|  3 | 汤姆         | 20.00 | 猫鼠      |     3 |
|  4 | 华伦         | 80.00 | 南京      |     4 |
+----+--------------+-------+-----------+-------+
4 rows in set (0.00 sec)
mysql> select * from info where name='汤姆';
+----+--------+-------+---------+-------+
| id | name   | score | address | hobby |
+----+--------+-------+---------+-------+
|  3 | 汤姆   | 20.00 | 猫鼠    |     3 |
+----+--------+-------+---------+-------+
1 row in set (0.00 sec)

mysql> delete from info where id=3;
Query OK, 1 row affected (0.00 sec)

mysql> select * from info;
+----+--------------+-------+-----------+-------+
| id | name         | score | address   | hobby |
+----+--------------+-------+-----------+-------+
|  1 | 开心超人     | 60.00 | 星星球    |     1 |
|  2 | 谜亚星       | 90.00 | 盟学园    |     2 |
|  4 | 华伦         | 80.00 | 南京      |     4 |
+----+--------------+-------+-----------+-------+
3 rows in set (0.00 sec)

pycharm配置

python 复制代码
PS C:\Users\孟宇\PyCharmMiscProject> pip install https://mirrors.aliyun.com/pypi/packages/6c/4c/bf2100cbc1bd07f39bee3b09e7eef39beffe29f5453dc2477a2693737913/greenlet-3.2.3-cp39-cp39-win_amd64.whl
Looking in indexes: https://mirrors.aliyun.com/pypi/simple/
Collecting greenlet==3.2.3
  Downloading https://mirrors.aliyun.com/pypi/packages/6c/4c/bf2100cbc1bd07f39bee3b09e7eef39beffe29f5453dc2477a2693737913/greenlet-3.2.3-cp39-cp39-win_amd64.whl (296 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 296.4/296.4 KB 1.1 MB/s eta 0:00:00                                                              
Installing collected packages: greenlet
Successfully installed greenlet-3.2.3
WARNING: You are using pip version 22.0.4; however, version 26.0.1 is available.
You should consider upgrading via the 'G:\python.exe -m pip install --upgrade pip' command.
PS C:\Users\孟宇\PyCharmMiscProject> pip install pandas
Requirement already satisfied: pandas in g:\lib\site-packages (1.3.5)
Requirement already satisfied: python-dateutil>=2.7.3 in g:\lib\site-packages (from pandas) (2.9.0.post0)
Requirement already satisfied: pytz>=2017.3 in g:\lib\site-packages (from pandas) (2026.1.post1)
Requirement already satisfied: numpy>=1.17.3 in g:\lib\site-packages (from pandas) (1.19.5)
Requirement already satisfied: six>=1.5 in g:\lib\site-packages (from python-dateutil>=2.7.3->pandas) (1.17.0)
WARNING: You are using pip version 22.0.4; however, version 26.0.1 is available.                                                               
You should consider upgrading via the 'G:\python.exe -m pip install --upgrade pip' command.                                                    
PS C:\Users\孟宇\PyCharmMiscProject> pip install sqlalchemy
Looking in indexes: https://mirrors.aliyun.com/pypi/simple/
Collecting sqlalchemy
  Downloading https://mirrors.aliyun.com/pypi/packages/a4/30/3547a4d114e0b884b85750a394b0d5bb911b47cf011f5f311ef6591a1e39/sqlalchemy-2.0.50-cp3     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 2.1/2.1 MB 755.4 kB/s eta 0:00:00                                                                
Requirement already satisfied: greenlet>=1 in g:\lib\site-packages (from sqlalchemy) (3.2.3)
Requirement already satisfied: typing-extensions>=4.6.0 in g:\lib\site-packages (from sqlalchemy) (4.15.0)
Installing collected packages: sqlalchemy
Successfully installed sqlalchemy-2.0.50
WARNING: You are using pip version 22.0.4; however, version 26.0.1 is available.                                                               
You should consider upgrading via the 'G:\python.exe -m pip install --upgrade pip' command.                                                    
PS C:\Users\孟宇\PyCharmMiscProject> pip install pymysql
Looking in indexes: https://mirrors.aliyun.com/pypi/simple/
  Downloading https://mirrors.aliyun.com/pypi/packages/c4/bd/2534e130295c8cfd4f0a2e31623baab7502278f1e97bcfe61db75656a77f/pymysql-1.2.0-py3-none-any.whl (45 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 45.7/45.7 KB ? eta 0:00:00                                                                       
Installing collected packages: pymysql
Successfully installed pymysql-1.2.0
WARNING: You are using pip version 22.0.4; however, version 26.0.1 is available.                                                               
You should consider upgrading via the 'G:\python.exe -m pip install --upgrade pip' command.                                                    
PS C:\Users\孟宇\PyCharmMiscProject> pip install openpyxl
Looking in indexes: https://mirrors.aliyun.com/pypi/simple/
Collecting openpyxl
  Downloading https://mirrors.aliyun.com/pypi/packages/c0/da/977ded879c29cbd04de313843e76868e6e13408a94ed6b987245dc7c8506/openpyxl-3.1.5-py2.py3-none-any.whl (250 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 250.9/250.9 KB 1.2 MB/s eta 0:00:00                                                              
Collecting et-xmlfile
  Downloading https://mirrors.aliyun.com/pypi/packages/c1/8b/5fe2cc11fee489817272089c4203e679c63b570a5aaeb18d852ae3cbba6a/et_xmlfile-2.0.0-py3-none-any.whl (18 kB)
Installing collected packages: et-xmlfile, openpyxl
Successfully installed et-xmlfile-2.0.0 openpyxl-3.1.5
WARNING: You are using pip version 22.0.4; however, version 26.0.1 is available.
You should consider upgrading via the 'G:\python.exe -m pip install --upgrade pip' command.
python 复制代码
import pandas as pd
from sqlalchemy import create_engine
#创建数据连接
engine = create_engine('mysql+pymysql://root:huawei@192.168.108.144:3306/school')
#执行获取数据
df = pd.read_sql('select * from info', engine)
print(df)
#导出到excel表格
df.to_excel('info.xlsx', index=False)
print('excel 导出成功!')

结果

bash 复制代码
C:\Users\孟宇\PycharmProjects\PythonProject2\.venv\Scripts\python.exe C:\Users\孟宇\PycharmProjects\PythonProject2\main.py 
   id  name  score address  hobby
0   1  开心超人   60.0     星星球      1
1   2   谜亚星   90.0     盟学园      2
2   4    华伦   80.0      南京      4
excel 导出成功!

进程已结束,退出代码为 0

打开info.xlsx

id name score address hobby
1 开心超人 60 星星球 1
2 谜亚星 90 盟学园 2
4 华伦 80 南京 4

mysql的备份与恢复

冷备份

bash 复制代码
[root@mysql01 data 14:02:50]# systemctl stop mysqld
[root@mysql01 ~ 14:03:34]# cd /usr/local/mysql/data/
[root@mysql01 data 14:03:53]# mkdir /mysql_bak
[root@mysql01 data 14:04:05]# tar czf /mysql_bak/mysql-backup-$(date +%F).tar.gz *
[root@mysql01 data 14:05:27]# systemctl start mysqld
[root@mysql01 data 14:05:50]# systemctl stop mysqld
[root@mysql01 data 14:06:45]# cd ~
[root@mysql01 ~ 14:07:25]# rm -rf /usr/local/mysql/data/*
[root@mysql01 ~ 14:07:43]# systemctl start mysqld
[root@mysql01 ~ 14:07:52]# systemctl stop mysqld
[root@mysql01 ~ 14:08:13]# tar xzf /mysql_bak/mysql-backup-2026-06-05.tar.gz -C /usr/local/mysql/data/
[root@mysql01 ~ 14:08:53]# chown -R mysql:mysql /usr/local/mysql/data/
[root@mysql01 ~ 14:09:26]# systemctl start mysqld

逻辑备份

bash 复制代码
[root@mysql01 ~ 14:09:37]# systemctl start mysqld
[root@mysql01 ~ 14:11:21]# mysqldump -u root -p school > /mysql_bak/school.sql
[root@mysql01 ~ 14:11:34]# ls /mysql_bak/school.sql
[root@mysql01 ~ 14:11:43]# cat /mysql_bak/school.sql
[root@mysql01 ~ 14:13:11]# mysqldump -u root -p --databases school mysql > /mysql_bak/school-mysql.sql
[root@mysql01 ~ 14:13:43]# cat /mysql_bak/school-mysql.sql
[root@mysql01 ~ 14:14:59]# mysqldump -u root -p --opt --all-databases > /mysql_bak/all.sql
[root@mysql01 ~ 14:15:15]# cat /mysql_bak/all.sql
[root@mysql01 ~ 14:15:51]# mysqldump -u root -p --opt school info > /mysql_bak/info.sql
[root@mysql01 ~ 14:16:03]# cat /mysql_bak/info.sql

恢复数据

bash 复制代码
[root@mysql01 ~ 14:16:07]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 7
Server version: 5.7.17 Source distribution

Copyright (c) 2000, 2016, 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> use school
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> show tables;
+------------------+
| Tables_in_school |
+------------------+
| info             |
+------------------+
1 row in set (0.00 sec)

mysql> drop table info;
Query OK, 0 rows affected (0.01 sec)

mysql> source /mysql_bak/info.sql
Query OK, 0 rows affected (0.00 sec)

Query OK, 0 rows affected (0.00 sec)

Query OK, 0 rows affected (0.00 sec)

Query OK, 0 rows affected (0.00 sec)

Query OK, 0 rows affected (0.00 sec)

Query OK, 0 rows affected (0.00 sec)

Query OK, 0 rows affected (0.00 sec)

Query OK, 0 rows affected (0.00 sec)

Query OK, 0 rows affected, 1 warning (0.00 sec)

Query OK, 0 rows affected (0.00 sec)

Query OK, 0 rows affected (0.00 sec)

Query OK, 0 rows affected (0.00 sec)

Query OK, 0 rows affected (0.00 sec)

Query OK, 0 rows affected (0.01 sec)

Query OK, 0 rows affected (0.00 sec)

Query OK, 0 rows affected (0.00 sec)

Query OK, 0 rows affected (0.00 sec)

Query OK, 3 rows affected (0.00 sec)
Records: 3  Duplicates: 0  Warnings: 0

Query OK, 0 rows affected (0.00 sec)

Query OK, 0 rows affected (0.00 sec)

Query OK, 0 rows affected (0.00 sec)

Query OK, 0 rows affected, 1 warning (0.00 sec)

Query OK, 0 rows affected (0.00 sec)

Query OK, 0 rows affected (0.00 sec)

Query OK, 0 rows affected (0.00 sec)

Query OK, 0 rows affected (0.00 sec)

Query OK, 0 rows affected (0.00 sec)

Query OK, 0 rows affected (0.00 sec)

mysql> show tables;
+------------------+
| Tables_in_school |
+------------------+
| info             |
+------------------+

增量备份

bash 复制代码
[root@mysql01 ~ 14:28:45]# vim /etc/my.cnf
[root@mysql01 ~ 14:29:41]# systemctl restart mysqld.service
[root@mysql01 ~ 14:30:00]# ls /usr/local/mysql/data/
auto.cnf         client-key.pem  ib_logfile1       mysql-bin.index     school
ca-key.pem       ib_buffer_pool  ibtmp1            performance_schema  server-cert.pem
ca.pem           ibdata1         mysql             private_key.pem     server-key.pem
client-cert.pem  ib_logfile0     mysql-bin.000001  public_key.pem      sys
[root@mysql01 ~ 14:30:11]# mysqldump -uroot -p school > /opt/school.sql
Enter password:
[root@mysql01 ~ 14:30:46]# mysqladmin -uroot -p flush-logs
Enter password:
[root@mysql01 ~ 14:31:10]# ls /usr/local/mysql/data/
auto.cnf         client-key.pem  ib_logfile1       mysql-bin.000002    public_key.pem   sys
ca-key.pem       ib_buffer_pool  ibtmp1            mysql-bin.index     school
ca.pem           ibdata1         mysql             performance_schema  server-cert.pem
client-cert.pem  ib_logfile0     mysql-bin.000001  private_key.pem     server-key.pem
[root@mysql01 ~ 14:31:23]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 5
Server version: 5.7.17-log Source distribution

Copyright (c) 2000, 2016, 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> use school;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> select * from info;
+----+--------------+-------+-----------+-------+
| id | name         | score | address   | hobby |
+----+--------------+-------+-----------+-------+
|  1 | 开心超人     | 60.00 | 星星球    |     1 |
|  2 | 谜亚星       | 90.00 | 盟学园    |     2 |
|  4 | 华伦         | 80.00 | 南京      |     4 |
+----+--------------+-------+-----------+-------+
3 rows in set (0.00 sec)

mysql> insert into info (name,score,address,hobby) values ('赛小息',30,'赛尔号',1);
Query OK, 1 row affected (0.00 sec)

mysql> exit
Bye
[root@mysql01 ~ 14:33:51]# mysqladmin -uroot -p flush-log
Enter password:
[root@mysql01 ~ 14:34:10]# ls /usr/local/mysql/data/
auto.cnf         client-key.pem  ib_logfile1       mysql-bin.000002    private_key.pem  server-key.pem
ca-key.pem       ib_buffer_pool  ibtmp1            mysql-bin.000003    public_key.pem   sys
ca.pem           ibdata1         mysql             mysql-bin.index     school
client-cert.pem  ib_logfile0     mysql-bin.000001  performance_schema  server-cert.pem
[root@mysql01 ~ 14:34:25]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 7
Server version: 5.7.17-log Source distribution

Copyright (c) 2000, 2016, 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> use school;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> insert into info (name,score,address,hobby) values ('双面龟',30,'龟男',1);
Query OK, 1 row affected (0.00 sec)

mysql> select * from info;
+----+--------------+-------+-----------+-------+
| id | name         | score | address   | hobby |
+----+--------------+-------+-----------+-------+
|  1 | 开心超人     | 60.00 | 星星球    |     1 |
|  2 | 谜亚星       | 90.00 | 盟学园    |     2 |
|  4 | 华伦         | 80.00 | 南京      |     4 |
|  5 | 赛小息       | 30.00 | 赛尔号    |     1 |
|  6 | 双面龟       | 30.00 | 龟男      |     1 |
+----+--------------+-------+-----------+-------+
5 rows in set (0.00 sec)

mysql> exit
Bye
[root@mysql01 ~ 14:36:11]# mysqladmin -uroot -p flush-log
Enter password:
[root@mysql01 ~ 14:36:21]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 9
Server version: 5.7.17-log Source distribution

Copyright (c) 2000, 2016, 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> use school;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> delete from info where id=6;
Query OK, 1 row affected (0.00 sec)

mysql> delete from info where id=5;
Query OK, 1 row affected (0.00 sec)

mysql> select * from info;
+----+--------------+-------+-----------+-------+
| id | name         | score | address   | hobby |
+----+--------------+-------+-----------+-------+
|  1 | 开心超人     | 60.00 | 星星球    |     1 |
|  2 | 谜亚星       | 90.00 | 盟学园    |     2 |
|  4 | 华伦         | 80.00 | 南京      |     4 |
+----+--------------+-------+-----------+-------+
3 rows in set (0.00 sec)

mysql> exit
Bye
[root@mysql01 ~ 14:37:15]# ls /usr/local/mysql/data/
auto.cnf         client-key.pem  ib_logfile1       mysql-bin.000002  performance_schema  server-cert.pem
ca-key.pem       ib_buffer_pool  ibtmp1            mysql-bin.000003  private_key.pem     server-key.pem
ca.pem           ibdata1         mysql             mysql-bin.000004  public_key.pem      sys
client-cert.pem  ib_logfile0     mysql-bin.000001  mysql-bin.index   school
[root@mysql01 ~ 14:37:22]# mysqlbinlog --no-defaults --base64-output=decode-rows -v /usr/local/mysql/data/mysql-bin.000003
/*!50530 SET @@SESSION.PSEUDO_SLAVE_MODE=1*/;
/*!50003 SET @OLD_COMPLETION_TYPE=@@COMPLETION_TYPE,COMPLETION_TYPE=0*/;
DELIMITER /*!*/;
# at 4
#260605 14:34:10 server id 1  end_log_pos 123 CRC32 0x60a62d1a  Start: binlog v 4, server v 5.7.17-log created 260605 14:34:10
# at 123
#260605 14:34:10 server id 1  end_log_pos 154 CRC32 0x0dc2367c  Previous-GTIDs
# [empty]
# at 154
#260605 14:35:44 server id 1  end_log_pos 219 CRC32 0x92e08d0c  Anonymous_GTID  last_committed=0        sequence_number=1
SET @@SESSION.GTID_NEXT= 'ANONYMOUS'/*!*/;
# at 219
#260605 14:35:44 server id 1  end_log_pos 293 CRC32 0xf297d02c  Query   thread_id=7     exec_time=0     error_code=0
SET TIMESTAMP=1780641344/*!*/;
SET @@session.pseudo_thread_id=7/*!*/;
SET @@session.foreign_key_checks=1, @@session.sql_auto_is_null=0, @@session.unique_checks=1, @@session.autocommit=1/*!*/;
SET @@session.sql_mode=1437073414/*!*/;
SET @@session.auto_increment_increment=1, @@session.auto_increment_offset=1/*!*/;
/*!\C utf8 *//*!*/;
SET @@session.character_set_client=33,@@session.collation_connection=33,@@session.collation_server=33/*!*/;
SET @@session.lc_time_names=0/*!*/;
SET @@session.collation_database=DEFAULT/*!*/;
BEGIN
/*!*/;
# at 293
#260605 14:35:44 server id 1  end_log_pos 352 CRC32 0x48e6b677  Table_map: `school`.`info` mapped to number 118
# at 352
#260605 14:35:44 server id 1  end_log_pos 416 CRC32 0xcb62dc6e  Write_rows: table id 118 flags: STMT_END_F
### INSERT INTO `school`.`info`
### SET
###   @1=6
###   @2='双面龟'
###   @3=30.00
###   @4='龟男'
###   @5=1
# at 416
#260605 14:35:44 server id 1  end_log_pos 447 CRC32 0xeb88ee7b  Xid = 46
COMMIT/*!*/;
# at 447
#260605 14:36:21 server id 1  end_log_pos 494 CRC32 0x428d3d7a  Rotate to mysql-bin.000004  pos: 4
SET @@SESSION.GTID_NEXT= 'AUTOMATIC' /* added by mysqlbinlog */ /*!*/;
DELIMITER ;
# End of log file
/*!50003 SET COMPLETION_TYPE=@OLD_COMPLETION_TYPE*/;
/*!50530 SET @@SESSION.PSEUDO_SLAVE_MODE=0*/;
[root@mysql01 ~ 14:37:48]# mysqlbinlog --no-defaults --base64-output=decode-rows -v /usr/local/mysql/data/mysql-bin.000004
/*!50530 SET @@SESSION.PSEUDO_SLAVE_MODE=1*/;
/*!50003 SET @OLD_COMPLETION_TYPE=@@COMPLETION_TYPE,COMPLETION_TYPE=0*/;
DELIMITER /*!*/;
# at 4
#260605 14:36:21 server id 1  end_log_pos 123 CRC32 0xcfba4890  Start: binlog v 4, server v 5.7.17-log created 260605 14:36:21
# Warning: this binlog is either in use or was not closed properly.
# at 123
#260605 14:36:21 server id 1  end_log_pos 154 CRC32 0xb376cd69  Previous-GTIDs
# [empty]
# at 154
#260605 14:36:58 server id 1  end_log_pos 219 CRC32 0x10f3177c  Anonymous_GTID  last_committed=0        sequence_number=1
SET @@SESSION.GTID_NEXT= 'ANONYMOUS'/*!*/;
# at 219
#260605 14:36:58 server id 1  end_log_pos 293 CRC32 0x8f6d2834  Query   thread_id=9     exec_time=0     error_code=0
SET TIMESTAMP=1780641418/*!*/;
SET @@session.pseudo_thread_id=9/*!*/;
SET @@session.foreign_key_checks=1, @@session.sql_auto_is_null=0, @@session.unique_checks=1, @@session.autocommit=1/*!*/;
SET @@session.sql_mode=1437073414/*!*/;
SET @@session.auto_increment_increment=1, @@session.auto_increment_offset=1/*!*/;
/*!\C utf8 *//*!*/;
SET @@session.character_set_client=33,@@session.collation_connection=33,@@session.collation_server=33/*!*/;
SET @@session.lc_time_names=0/*!*/;
SET @@session.collation_database=DEFAULT/*!*/;
BEGIN
/*!*/;
# at 293
#260605 14:36:58 server id 1  end_log_pos 352 CRC32 0x2a8e7300  Table_map: `school`.`info` mapped to number 118
# at 352
#260605 14:36:58 server id 1  end_log_pos 416 CRC32 0x77bad621  Delete_rows: table id 118 flags: STMT_END_F
### DELETE FROM `school`.`info`
### WHERE
###   @1=6
###   @2='双面龟'
###   @3=30.00
###   @4='龟男'
###   @5=1
# at 416
#260605 14:36:58 server id 1  end_log_pos 447 CRC32 0xbef9cd3f  Xid = 57
COMMIT/*!*/;
# at 447
#260605 14:37:02 server id 1  end_log_pos 512 CRC32 0x66f43425  Anonymous_GTID  last_committed=1        sequence_number=2
SET @@SESSION.GTID_NEXT= 'ANONYMOUS'/*!*/;
# at 512
#260605 14:37:02 server id 1  end_log_pos 586 CRC32 0xa68091fb  Query   thread_id=9     exec_time=0     error_code=0
SET TIMESTAMP=1780641422/*!*/;
BEGIN
/*!*/;
# at 586
#260605 14:37:02 server id 1  end_log_pos 645 CRC32 0xfa83a963  Table_map: `school`.`info` mapped to number 118
# at 645
#260605 14:37:02 server id 1  end_log_pos 712 CRC32 0xbcb92426  Delete_rows: table id 118 flags: STMT_END_F
### DELETE FROM `school`.`info`
### WHERE
###   @1=5
###   @2='赛小息'
###   @3=30.00
###   @4='赛尔号'
###   @5=1
# at 712
#260605 14:37:02 server id 1  end_log_pos 743 CRC32 0xf8af18fc  Xid = 58
COMMIT/*!*/;
SET @@SESSION.GTID_NEXT= 'AUTOMATIC' /* added by mysqlbinlog */ /*!*/;
DELIMITER ;
# End of log file
/*!50003 SET COMPLETION_TYPE=@OLD_COMPLETION_TYPE*/;
/*!50530 SET @@SESSION.PSEUDO_SLAVE_MODE=0*/;
[root@mysql01 ~ 14:37:58]# mysqlbinlog --no-defaults /usr/local/mysql/data/mysql-bin.000003 | mysql -uroot -p
Enter password:
[root@mysql01 ~ 14:38:28]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 11
Server version: 5.7.17-log Source distribution

Copyright (c) 2000, 2016, 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> use school;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> select * from info;
+----+--------------+-------+-----------+-------+
| id | name         | score | address   | hobby |
+----+--------------+-------+-----------+-------+
|  1 | 开心超人     | 60.00 | 星星球    |     1 |
|  2 | 谜亚星       | 90.00 | 盟学园    |     2 |
|  4 | 华伦         | 80.00 | 南京      |     4 |
|  6 | 双面龟       | 30.00 | 龟男      |     1 |
+----+--------------+-------+-----------+-------+
4 rows in set (0.00 sec)

主从复制读写分离

bash 复制代码
#所有结点执行
ntpdate ntp.aliyun.com 
date -R
systemctl disable firewalld --now 
setenforce 0
[root@mysql-master ~ 15:38:55]# vim /etc/my.cnf
server-id = 11
log-bin = master-bin                         
log-slave-updates = true                     

[root@mysql-master ~ 15:42:44]# systemctl restart mysqld
[root@mysql-master ~ 15:42:59]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.17-log Source distribution

Copyright (c) 2000, 2016, 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> grant replication slave on*.* TO 'myslave '@'192 .168 .108 .%' IDENTIFIED BY
    -> 'huawei';
Query OK, 0 rows affected, 1 warning (0.01 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

mysql> show master status
    -> ;
+-------------------+----------+--------------+------------------+-------------------+
| File              | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+-------------------+----------+--------------+------------------+-------------------+
| master-bin.000001 |      607 |              |                  |                   |
+-------------------+----------+--------------+------------------+-------------------+
1 row in set (0.00 sec)

mysql> exit
Bye
[root@mysql-master ~ 15:46:11]# ls /usr/local/mysql/data
auto.cnf        ibdata1      ib_logfile1  master-bin.000001  mysql               sys
ib_buffer_pool  ib_logfile0  ibtmp1       master-bin.index   performance_schema

mysql> CREATE USER 'myslave'@'%' IDENTIFIED BY 'huawei';
Query OK, 0 rows affected (0.00 sec)

mysql> GRANT REPLICATION SLAVE ON *.* TO 'myslave'@'%';
Query OK, 0 rows affected (0.00 sec)

mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)
mysql> change master to master_host='192.168.108.101',master_user='myslave2',master_password='123456',master_log_file='master-bin.000001',master_log_pos=3138;
Query OK, 0 rows affected, 2 warnings (0.00 sec)

mysql> start slave;
Query OK, 0 rows affected (0.00 sec)

mysql> show slave status\G;
*************************** 1. row ***************************
               Slave_IO_State: Waiting for master to send event
                  Master_Host: 192.168.108.101
                  Master_User: myslave2
                  Master_Port: 3306
                Connect_Retry: 60
              Master_Log_File: master-bin.000001
          Read_Master_Log_Pos: 3138
               Relay_Log_File: relay-log-bin.000002
                Relay_Log_Pos: 321
        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: 3138
              Relay_Log_Space: 526
              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: 11
                  Master_UUID: e13bbd13-608b-11f1-9c13-000c2900c45c
             Master_Info_File: /usr/local/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> change master to master_host='192.168.108.101',master_user='myslave2',master_password='123456',master_log_file='master-bin.000001',master_log_pos=3138;
Query OK, 0 rows affected, 2 warnings (0.00 sec)

mysql> start slave ;
Query OK, 0 rows affected (0.00 sec)

mysql> show slave status\G ;
*************************** 1. row ***************************
               Slave_IO_State: Waiting for master to send event
                  Master_Host: 192.168.108.101
                  Master_User: myslave2
                  Master_Port: 3306
                Connect_Retry: 60
              Master_Log_File: master-bin.000001
          Read_Master_Log_Pos: 3138
               Relay_Log_File: relay-log-bin.000002
                Relay_Log_Pos: 321
        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: 3138
              Relay_Log_Space: 526
              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: 11
                  Master_UUID: e13bbd13-608b-11f1-9c13-000c2900c45c
             Master_Info_File: /usr/local/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)

验证主从

bash 复制代码
[root@mysql-master ~ 16:43:35]# mysql -uroot -phuawei
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 5
Server version: 5.7.17-log Source distribution

Copyright (c) 2000, 2016, 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> create database school ;
Query OK, 1 row affected (0.00 sec)

mysql>  use school ;
Database changed
mysql> CREATE TABLE student (
    -> id int UNSIGNED AUTO_INCREMENT PRIMARY KEY ,
    -> name VARCHAR(20) NOT NULL ,
    -> age tinyint UNSIGNED ,
    -> #height DECIMAL(5 ,2),
    -> gender ENUM('M ','F ') default 'M '
    -> )ENGINE=InnoDB AUTO_INCREMENT=10 DEFAULT CHARSET=utf8mb4 ;
Query OK, 0 rows affected (0.00 sec)

mysql> insert student (name ,age)values('路飞',20);
Query OK, 1 row affected (0.03 sec)
[root@mysql-slave01 ~ 16:43:44]# mysql -uroot -phuawei
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 5
Server version: 5.7.17 Source distribution

Copyright (c) 2000, 2016, 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> select * from school .student ;
+----+--------+------+--------+
| id | name   | age  | gender |
+----+--------+------+--------+
| 10 | 路飞   |   20 | M      |
+----+--------+------+--------+
1 row in set (0.00 sec)
[root@mysql-slave02 ~ 16:44:09]# mysql -uroot -phuawei
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 5
Server version: 5.7.17 Source distribution

Copyright (c) 2000, 2016, 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> select * from school .student ;
+----+--------+------+--------+
| id | name   | age  | gender |
+----+--------+------+--------+
| 10 | 路飞   |   20 | M      |
+----+--------+------+--------+
1 row in set (0.00 sec)

amoeba服务器、

bash 复制代码
#普通linux克隆得出amoeba
[root@amoeba ~]# hostnamectl set-hostname amoeba
[root@amoeba ~]# systemctl stop firewalld .service
[root@amoeba ~]# setenforce 0
[root@amoeba ~]# chmod +x jdk-6u14-linux-x64 .bin
[root@amoeba ~]# ./jdk-6u14-linux-x64 .bin
到yes的时候,输入yes按enter
[root@amoeba ~]# mv jdk1 .6 .0_14/ /usr/local/jdk1 .6
[root@amoeba ~]# vim /etc/profile
最下面加
export JAVA_HOME=/usr/local/jdk1 .6                   #java家目录
export CLASSPATH=$CLASSPATH:$JAVA_HOME/lib:$JAVA_HOME/jre/lib             #类环境
和jre
export PATH=$JAVA_HOME/lib:$JAVA_HOME/jre/bin/:$PATH:$HOME/bin
export AMOEBA_HOME=/usr/local/amoeba                  #指定amoeba路径
export PATH=$PATH:$AMOEBA_HOME/bin
[root@amoeba ~]# source /etc/profile
[root@amoeba ~]# mkdir /usr/local/amoeba
[root@amoeba ~]# tar zxvf amoeba-mysql-binary-2 .2 .0 .tar .gz -C /usr/local/amoeba/
[root@amoeba ~]# chmod -R 755 /usr/local/amoeba/
#执行结果显示amoeba start|stop说明安装成功
[root@amoeba ~]# /usr/local/amoeba/bin/amoeba 
amoeba start|stop

三台mysql为amoeba开小灶

bash 复制代码
grant all on *.* to test@'192.168.108.%' identified by '123.com';

回到amoeba服务器

bash 复制代码
[root@amoeba ~]# cd /usr/local/amoeba/
[root@amoeba amoeba]# vim conf/amoeba .xml
---30行--
<property name="user">amoeba</property           #客户端访问amoeba账号
----32行---------
<property name="password">123456</property>        #客户端访问ameoba密码
---117和120-去掉注释-
115行<property name="defaultPool">master</property>
116
117
118行<property name="writePool">master</property>
119行<property name="readPool">slaves</property>
120
[root@amoeba amoeba]# vim conf/dbServers .xml         #数据库配置
---23--注意!!!(mysql5 .7,默认没有test数据库所以需要修改为mysql数据库)-(mysql5 .5直接忽
略)--
<!-- mysql schema -->
<property name="schema">mysql</property>
--25行到30行,第30行-->移动到28行后面
25                         <!-- mysql user -->
26                         <property name="user">test</property>
27
28                         <!--  mysql password -->
29                         <property name="password">123.com</property>
30
-----45到50行主服务器地址---
45行<dbServer name="master "  parent="abstractServer ">
48行<property name="ipAddress">192 .168 .108 .101</property>
 --52到57行从服务器主机名-
52行<dbServer name="slave1 "  parent="abstractServer ">
 --55-从服务器地址-
55 <property name="ipAddress">192 .168 .108 .102</property>
 ---52到57行复制一份在58行后面
原52行<dbServer name="slave2 "  parent="abstractServer ">
 --55-从服务器地址-
原55 <property name="ipAddress">192 .168 .108 .103</property>
---仅跟在上面的配置后面,multiPool行(本来就有,修改)
<dbServer name="slaves " virtual="true ">
<poolConfig class="com .meidusa .amoeba .server .MultipleServerPool   #不改
<property name="poolNames">slave1 ,slave2</property>
</poolConfig>           #不改
[root@amoeba ~]# /usr/local/amoeba/bin/amoeba start&
[1] 33499
[root@amoeba ~]# netstat -anpt | grep java
tcp6       0      0 :::8066
33499/java
tcp6       0      0 127 .0 .0 .1 :21128
33499/java
tcp6       0      0 192 .168 .108 .110:41754
33499/java
tcp6       0      0 192 .168 .108 .110:41722
33499/java
tcp6       0      0 192 .168 .108 .110 :36956
33499/java

测试客户端

bash 复制代码
[root@mysql-client ~ 21:15:17]#  yum install -y mysql
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
base                                                                                | 3.6 kB  00:00:00
extras                                                                              | 2.9 kB  00:00:00
updates          
[root@mysql-client ~ 21:20:18]#  mysql -u amoeba -p123456 -h 192.168.108.110 -P8066
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MySQL connection id is 2138123066
Server version: 5.1.45-mysql-amoeba-proxy-2.2.0

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MySQL [(none)]>

master测试

bash 复制代码
[root@mysql-master ~ 21:22:13]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 5.7.17-log Source distribution

Copyright (c) 2000, 2016, 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> use school ;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> insert student (name ,age)values('鸣人',20);
Query OK, 1 row affected (0.01 sec)

切换到slave01

sql 复制代码
mysql> use school;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> select * from student ;
+----+--------+------+--------+
| id | name   | age  | gender |
+----+--------+------+--------+
| 10 | 路飞   |   20 | M      |
| 11 | 鸣人   |   20 | M      |
+----+--------+------+--------+
2 rows in set (0.00 sec)

切换到slave02

sql 复制代码
mysql> use school;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql>  select * from student ;
+----+--------+------+--------+
| id | name   | age  | gender |
+----+--------+------+--------+
| 10 | 路飞   |   20 | M      |
| 11 | 鸣人   |   20 | M      |
+----+--------+------+--------+
2 rows in set (0.00 sec)

从节点停止,客户端插入数据

bash 复制代码
# mysql-slave01
mysql> stop slave ;
# mysql-slave02
mysql> stop slave ;
#在客户端上插入数据,内容不会同步
#mysql-client上添加,由于不会同步,只有mysql-master192 .168 .108 .101节点有该记录
# mysql-client
MySQL [school]> insert student (name ,age)values('卡卡西',30);
在mysql-slave01上
#mysql-slave01
mysql> use school ;
mysql> insert student (name ,age)values('卡卡西',31);
mysql-slave02上
# mysql-slave02
mysql> use school ;
mysql> insert student (name ,age)values('卡卡西',32);

验证主从复制

bash 复制代码
mysql> select * from student;
+----+-----------+------+--------+
| id | name      | age  | gender |
+----+-----------+------+--------+
| 10 | 路飞      |   20 | M      |
| 11 | 鸣人      |   20 | M      |
| 12 | 卡卡西    |   31 | M      |
+----+-----------+------+--------+
3 rows in set (0.00 sec)

mysql> select * from student;
+----+-----------+------+--------+
| id | name      | age  | gender |
+----+-----------+------+--------+
| 10 | 路飞      |   20 | M      |
| 11 | 鸣人      |   20 | M      |
| 12 | 卡卡西    |   32 | M      |
+----+-----------+------+--------+
3 rows in set (0.00 sec)
#主节点上
mysql> select * from student;
+----+-----------+------+--------+
| id | name      | age  | gender |
+----+-----------+------+--------+
| 10 | 路飞      |   20 | M      |
| 11 | 鸣人      |   20 | M      |
| 12 | 卡卡西    |   30 | M      |
+----+-----------+------+--------+
3 rows in set (0.00 sec)

验证读写分离

bash 复制代码
MySQL [(none)]> select * from school .student ;
+----+-----------+------+--------+
| id | name      | age  | gender |
+----+-----------+------+--------+
| 10 | 路飞      |   20 | M      |
| 11 | 鸣人      |   20 | M      |
| 12 | 卡卡西    |   32 | M      |
+----+-----------+------+--------+
3 rows in set (0.01 sec)

MySQL [(none)]> select * from school .student ;
+----+-----------+------+--------+
| id | name      | age  | gender |
+----+-----------+------+--------+
| 10 | 路飞      |   20 | M      |
| 11 | 鸣人      |   20 | M      |
| 12 | 卡卡西    |   31 | M      |
+----+-----------+------+--------+
3 rows in set (0.00 sec)

mysql> select * from student;

±---±----------±-----±-------+

| id | name | age | gender |

±---±----------±-----±-------+

| 10 | 路飞 | 20 | M |

| 11 | 鸣人 | 20 | M |

| 12 | 卡卡西 | 32 | M |

±---±----------±-----±-------+

3 rows in set (0.00 sec)

#主节点上

mysql> select * from student;

±---±----------±-----±-------+

| id | name | age | gender |

±---±----------±-----±-------+

| 10 | 路飞 | 20 | M |

| 11 | 鸣人 | 20 | M |

| 12 | 卡卡西 | 30 | M |

±---±----------±-----±-------+

3 rows in set (0.00 sec)

复制代码
验证读写分离

~~~bash
MySQL [(none)]> select * from school .student ;
+----+-----------+------+--------+
| id | name      | age  | gender |
+----+-----------+------+--------+
| 10 | 路飞      |   20 | M      |
| 11 | 鸣人      |   20 | M      |
| 12 | 卡卡西    |   32 | M      |
+----+-----------+------+--------+
3 rows in set (0.01 sec)

MySQL [(none)]> select * from school .student ;
+----+-----------+------+--------+
| id | name      | age  | gender |
+----+-----------+------+--------+
| 10 | 路飞      |   20 | M      |
| 11 | 鸣人      |   20 | M      |
| 12 | 卡卡西    |   31 | M      |
+----+-----------+------+--------+
3 rows in set (0.00 sec)
相关推荐
活宝小娜14 天前
mysql详细安装教程
数据库·mysql·adb
zhangjin112014 天前
adb install和 pm install 的区别是什么?
adb
炼川淬海DB15 天前
数据库开发规范
android·adb·数据库开发
何极光15 天前
MySQL 8.0详细安装教程(附下载地址)
数据库·mysql·adb
sevencheng79816 天前
【ADB】adb命令行常用按键模拟代码
linux·adb·模拟按键,返回键,音量键
QX_hao16 天前
mysqldump-vs-xtrabackup
adb·mysql备份
云计算磊哥@17 天前
运维开发宝典028-MySQL04数据库热备
数据库·adb·运维开发
charlee4417 天前
Unity在安卓端如何调试输出信息
android·unity·adb·游戏引擎·真机调试
ai_coder_ai18 天前
如何使用adb实现自动化脚本?
运维·adb·自动化
pigs201818 天前
mysql8.0 access denied for user root localhost account is locked
数据库·adb