1. 程式人生 > 實用技巧 >二進位制安裝MySQL5.7.26

二進位制安裝MySQL5.7.26

目錄

mysql5.7.26二進位制安裝

  • 總結
· 搭建主從後新增新的從庫,發現無法進行同步
· 搭建主從同步使用為gtid方式,可無需對主庫的一個值記錄,這樣主要方便ansible使用
  • 二進位制方式安裝資料庫
# 0.基礎豬呢比:建立mysql存放目錄和刪除centos7自帶軟體,建立mysql使用者
 yum -y remove mariadb*
 mkdir -p /application/
useradd mysql -M -s /sbin/nologin -u 1111
[root@lb02 /application]# mkdir /data/mysql/data -p
yum install -y libaio-devel
yum install perl-DBD-MySQL -y
yum install -y dos2unix
# 1. 使用二進位制方式安裝
mysql-5.7.26-linux-glibc2.12-x86_64.tar.gz將此安裝包上傳

# 2. 解壓安裝包
[root@lb02 ~]# tar xf mysql-5.7.26-linux-glibc2.12-x86_64.tar.gz -C /application/

# 3. 將安裝包重新命名
[root@lb02 /application]# mv mysql-5.7.26-linux-glibc2.12-x86_64/ mysql-5.7

# 4. 建立軟連線
[root@lb02 /application]# ln -s mysql-5.7/ mysql

# 5. 環境變數
[root@lb02 /application]# echo "export PATH=/application/mysql/bin:$PATH" >> /etc/profile
[root@lb02 /application]# source /etc/profile


# 6.授權目錄
[root@lb02 /application]# chown -R mysql.mysql /application/*
[root@lb02 /application]# chown -R mysql.mysql /data/mysql/data

# 7. 初始化
[root@lb02 /application]# cd /application/mysql/support-files && mysqld --initialize-insecure  --user=mysql --basedir=/application/mysql --datadir=/data/mysql/data

# 8. 支援使用service方式啟動mysql
cp mysql.server    /etc/init.d/mysqld

# 9. 授權
 mkdir -p /data/binlog/
 chown -R mysql.mysql /data

# 8.書寫配置檔案(主)
[mysqld]
basedir=/application/mysql/
datadir=/data/mysql/data
socket=/tmp/mysql.sock
server_id=51
port=3306
secure-file-priv=/tmp
autocommit=0
log_bin=/data/binlog/mysql-bin
binlog_format=row
gtid-mode=on
enforce-gtid-consistency=true
log-slave-updates=1
[mysql]
prompt=db01 [\\d]>

###從1:
[mysqld]
basedir=/application/mysql
datadir=/data/mysql/data
socket=/tmp/mysql.sock
server_id=52
port=3306
secure-file-priv=/tmp
autocommit=0
log_bin=/data/binlog/mysql-bin
binlog_format=row
gtid-mode=on
enforce-gtid-consistency=true
log-slave-updates=1
[mysql]
prompt=db02 [\\d]>

### 從2:
[mysqld]
basedir=/application/mysql
datadir=/data/mysql/data
socket=/tmp/mysql.sock
server_id=52
port=3306
secure-file-priv=/tmp
autocommit=0
log_bin=/data/binlog/mysql-bin
binlog_format=row
gtid-mode=on
enforce-gtid-consistency=true
log-slave-updates=1
[mysql]
prompt=db02 [\\d]>

# 從3
[mysqld]
basedir=/application/mysql
datadir=/data/mysql/data
socket=/tmp/mysql.sock
server_id=53
port=3306
secure-file-priv=/tmp
autocommit=0
log_bin=/data/binlog/mysql-bin
binlog_format=row
gtid-mode=on
enforce-gtid-consistency=true
log-slave-updates=1
[mysql]
prompt=db03 [\\d]>


# 9. 啟動服務
[root@lb02 /application]# service mysqld start