一、下载 tar.gz 安装包并解压
wget https://mirrors4.tuna.tsinghua.edu.cn/mysql/downloads/MySQL-5.7/mysql-5.7.28-el7-x86_64.tar.gz
tar -zxvf mysql-5.7.28-el7-x86_64.tar.gz
mv mysql-5.7.28-el7-x86_64 /usr/local/mysql
二、MySQL 单机安装
2.1 添加MySQL组及用户
sudo groupadd mysql
sudo useradd -r -g mysql mysql
2.2 修改MySQL文件夹权限
sudo chown -R mysql:mysql /usr/local/mysql
2.3 初始化MySQL(记录下MySQL的临时密码,这里的临时密码是F7f_2r4h7WNu)
[ifan@hadoop130 bin]$ cd /usr/local/mysql/bin
[ifan@hadoop130 bin]$ sudo ./mysqld --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --initialize
2020-06-02T00:42:51.198796Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2020-06-02T00:42:51.463650Z 0 [Warning] InnoDB: New log files created, LSN=45790
2020-06-02T00:42:51.487541Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2020-06-02T00:42:51.543374Z 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: fd3de093-a469-11ea-ab26-000c2900bcd4.
2020-06-02T00:42:51.544152Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2020-06-02T00:42:52.133913Z 0 [Warning] CA certificate ca.pem is self signed.
2020-06-02T00:42:52.784629Z 1 [Note] A temporary password is generated for root@localhost: F7f_2r4h7WNu
2.4 启动MySQL服务
[ifan@hadoop130 bin]$ sudo /usr/local/mysql/support-files/mysql.server start
Starting MySQL.Logging to '/usr/local/mysql/data/hadoop130.err'.
SUCCESS!
2.5 将MySQL添加到服务中
[ifan@hadoop130 bin]$ sudo cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
[ifan@hadoop130 bin]$ sudo chmod 755 /etc/init.d/mysqld
2.6 修改MySQL的配置文件
这里的内容为主库Master的配置文件
[mysqld]
port=3306
datadir=/usr/local/mysql/data
socket=/usr/local/mysql/mysql.sock
skip-name-resolve
#skip-grant-tables
max_connections=1000
character_set_server = utf8
wait_timeout=31536000
interactive_timeout=31536000
collation-server=utf8_general_ci
lower_case_table_names=1
server-id=1
log-bin=mysql-bin
expire-logs-days=14
read-only=0
binlog-ignore-db=mysql
symbolic-links=0
log-error=/usr/local/mysql/data/hadoop130.log
pid-file=/usr/local/mysql/data/hadoop130.pid
[client]
socket=/usr/local/mysql/data/mysql.sock
default-character-set = utf8
[mysql]
default-character-set = utf8
[mysql.server]
default-character-set = utf8
[mysqld_safe]
default-character-set = utf8
2.7 新建主从复制账号
GRANT REPLICATION SLAVE ON *.* TO 'replication'@'%' IDENTIFIED BY '123456';
flush privileges;
2.8 查看Master机器的状态,记录 File以及 Position
show master status;
2.9 从机上,按照如上的步骤,安装MySQL即可
2.10 进入从机,设置 从机复制的主库
# 将 MASTER_LOG_FILE 以及 MASTER_LOG_POS改成2.8中显示的值
CHANGE MASTER TO MASTER_HOST='192.168.137.130',MASTER_USER='replication',MASTER_PASSWORD='123456',MASTER_LOG_FILE='mysql-bin.000003',MASTER_LOG_POS=588;
2.11 启动主从复制
start slave;
查看slave的状态,如果 Slave_IO_Running 和 Slave_SQL_Running 都为yes的话,即为成功。
2.12 测试主从复制
新建数据库,新建表,以及插入数据,查看slave机器上是否能够看到相同的数据
2.13 关闭 MySQL主从复制
stop slave;