Centos MySQL二進制包安裝并配置主從同步

  • 官網(wǎng)下載:
wget https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-8.0.13-linux-glibc2.12-i686.tar.xz
  • 創(chuàng)建用戶:
groupadd mysql
useradd -g mysql mysql
  • 創(chuàng)建目錄屋厘,并修改所屬用戶:
mkdir -p /data/mysql
mkdir -p /data/mysql_data
mkdir -p /data/mysql_log
mkdir -p /data/mysql_tmp
mkdir -p /var/run/mysqld
chown -R mysql.mysql /data/mysql*
chown -R mysql.mysql /var/run/mysqld
  • 解包:
tar -xvf mysql-8.0.13-linux-glibc2.12-i686.tar.xz 
cp -R mysql-8.0.13-linux-glibc2.12-i686/* /data/mysql/
  • 配置環(huán)境變量
vim /etc/bashrc
export PATH=/data/mysql/bin:$PATH
  • 檢查
$ mysql --version
bash: /data/mysql/bin/mysql: /lib/ld-linux.so.2: bad ELF interpreter: 沒有那個文件或目錄
$ yum install -y glibc.i686 
$ mysql --version
mysql: error while loading shared libraries: libtinfo.so.5: cannot open shared object file: No such file or directory
$ yum install -y libtinfo.so.5
$ mysql --version
mysql  Ver 8.0.13 for linux-glibc2.12 on i686 (MySQL Community Server - GPL)
  • 開始導(dǎo)入配置文件(以下配置文件可以直接使用):
    Master:
# Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA

#
# The MySQL Community Server configuration file.
#
# For explanations see
# http://dev.mysql.com/doc/mysql/en/server-system-variables.html

[client]
port                    = 3306
socket                  = /data/mysql/mysqld.sock
default-character-set   = utf8mb4

[mysql]
default-character-set   = utf8mb4

[mysqld_safe]
pid-file    = /var/run/mysqld/mysqld.pid
socket      = /var/run/mysqld/mysqld.sock
log-error   = /data/mysql_log/mysqld.err
nice        = 0

[mysqld]
user        = mysql
pid-file    = /data/mysql/mysqld.pid
socket      = /data/mysql/mysqld.sock
log-error   = /data/mysql_log/error.err
port        = 3306
basedir     =  /usr/share/mysql
datadir     = /data/mysql_data
tmpdir      = /data/mysql_tmp
lc-messages-dir = /usr/share/mysql
interactive_timeout = 120
wait_timeout = 120
max_allowed_packet = 32M

# mysqld character
character-set-client-handshake = FALSE
character-set-server = utf8mb4
collation-server = utf8mb4_unicode_ci
init_connect='SET NAMES utf8mb4'

# when innodb_buffer_pool_size too big, the container is shutdown
innodb_buffer_pool_size = 1024M
explicit_defaults_for_timestamp
# innodb_flush_log_at_trx_commit=2

# Instead of skip-networking the default is now to listen only on
# localhost which is more compatible and is not less secure.
#bind-address   = 127.0.0.1
max_connections=10240

# Recommended in standard MySQL setup
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES

# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0

#master-slave config
log-bin=mysql-bin
server-id=19

# * IMPORTANT: Additional settings that can override those from this file!
#   The files must end with '.cnf', otherwise they'll be ignored.
#
#!includedir /etc/mysql/conf.d/

Slave:

# Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA

#
# The MySQL Community Server configuration file.
#
# For explanations see
# http://dev.mysql.com/doc/mysql/en/server-system-variables.html

[client]
port                    = 3306
socket                  = /data/mysql/mysqld.sock
default-character-set   = utf8mb4

[mysql]
default-character-set   = utf8mb4

[mysqld_safe]
pid-file    = /var/run/mysqld/mysqld.pid
socket      = /var/run/mysqld/mysqld.sock
log-error   = /data/mysql_log/mysqld.err
nice        = 0

[mysqld]
user        = mysql
pid-file    = /data/mysql/mysqld.pid
socket      = /data/mysql/mysqld.sock
log-error   = /data/mysql_log/error.err
port        = 3306
basedir     =  /usr/share/mysql
datadir     = /data/mysql_data
tmpdir      = /data/mysql_tmp
lc-messages-dir = /usr/share/mysql
interactive_timeout = 120
wait_timeout = 120
max_allowed_packet = 32M

# mysqld character
character-set-client-handshake = FALSE
character-set-server = utf8mb4
collation-server = utf8mb4_unicode_ci
init_connect='SET NAMES utf8mb4'

# when innodb_buffer_pool_size too big, the container is shutdown
innodb_buffer_pool_size = 1024M
explicit_defaults_for_timestamp
# innodb_flush_log_at_trx_commit=2

# Instead of skip-networking the default is now to listen only on
# localhost which is more compatible and is not less secure.
#bind-address   = 127.0.0.1
max_connections=10240

# Recommended in standard MySQL setup
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES

# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0

#master-slave config
server-id=2
relay-log-index=slave-relay-bin.index
relay-log=slave-relay-bin
#slave-slave config
#server-id=2
#log-bin=slave-bin
#log-bin-index=slave-bin.index

# * IMPORTANT: Additional settings that can override those from this file!
#   The files must end with '.cnf', otherwise they'll be ignored.
#
#!includedir /etc/mysql/conf.d/
  • 初始化
$ /data/mysql/bin/mysqld --initialize --user=mysql
/data/mysql/bin/mysqld: error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory
$ yum install -y libaio.so.1
$ /data/mysql/bin/mysqld --initialize --user=mysql
/data/mysql/bin/mysqld: error while loading shared libraries: libnuma.so.1: cannot open shared object file: No such file or directory
$ yum install -y libnuma.so.1 --setopt=protected_multilib=false
$ /data/mysql/bin/mysqld --initialize --user=mysql
  • 啟動實例
/data/mysql/bin/mysqld --user=mysql --port=3306 &
  • 修改root密碼
$ cat /data/mysql_log/error.err | grep pass
2018-12-30T08:31:19.029232Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: temppass  #查詢臨時密碼
$ mysqladmin -u root -p password 'temppass'
  • 安裝完成, 最后一步

配置主從

#主庫執(zhí)行
> create user 'slave_sync'@'slaveip' identified by 'pass';   #創(chuàng)建用于同步的賬戶
> GRANT REPLICATION SLAVE ON *.* to 'slave_sync'@'slaveip';
> flush privileges;
> show master status;
ERROR 2006 (HY000): MySQL server has gone away
No connection. Trying to reconnect...
Connection id:    27
Current database: *** NONE ***

+------------------+----------+--------------+------------------+-------------------+
| File             | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+------------------+----------+--------------+------------------+-------------------+
| mysql-bin.000007 |     1596 |              |                  |                   |
+------------------+----------+--------------+------------------+-------------------+
1 row in set (0.01 sec)
# 從庫執(zhí)行  記錄下主庫當(dāng)前日志和position,從此處開始同步
> change master to master_host='masterip',master_user='slave_sync',master_password='pass',master_log_file='mysql-bin.000007',master_log_pos=1596; 
###重啟mysql,檢查服務(wù)
mysql> show slave status\G;
*************************** 1. row ***************************
               Slave_IO_State: Waiting for master to send event
                  Master_Host: masterip
                  Master_User: slave_sync
                  Master_Port: 3306
                Connect_Retry: 60
              Master_Log_File: mysql-bin.000007
          Read_Master_Log_Pos: 1596
               Relay_Log_File: slave-relay-bin.000003
                Relay_Log_Pos: 503
        Relay_Master_Log_File: mysql-bin.000007
             Slave_IO_Running: Yes
            Slave_SQL_Running: Yes
              Replicate_Do_DB:
          Replicate_Ignore_DB:
        ...
        ...

Slave_IO_Running為Yes睬隶,到主庫創(chuàng)建test數(shù)據(jù)庫檢查同步結(jié)果郁副,安裝完成

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末减牺,一起剝皮案震驚了整個濱河市,隨后出現(xiàn)的幾起案子存谎,更是在濱河造成了極大的恐慌拔疚,老刑警劉巖,帶你破解...
    沈念sama閱讀 218,451評論 6 506
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件愕贡,死亡現(xiàn)場離奇詭異草雕,居然都是意外死亡,警方通過查閱死者的電腦和手機固以,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 93,172評論 3 394
  • 文/潘曉璐 我一進店門墩虹,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人憨琳,你說我怎么就攤上這事诫钓。” “怎么了篙螟?”我有些...
    開封第一講書人閱讀 164,782評論 0 354
  • 文/不壞的土叔 我叫張陵菌湃,是天一觀的道長。 經(jīng)常有香客問我遍略,道長惧所,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 58,709評論 1 294
  • 正文 為了忘掉前任绪杏,我火速辦了婚禮下愈,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘蕾久。我一直安慰自己势似,他們只是感情好,可當(dāng)我...
    茶點故事閱讀 67,733評論 6 392
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著履因,像睡著了一般障簿。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上栅迄,一...
    開封第一講書人閱讀 51,578評論 1 305
  • 那天站故,我揣著相機與錄音,去河邊找鬼霞篡。 笑死世蔗,一個胖子當(dāng)著我的面吹牛,可吹牛的內(nèi)容都是我干的朗兵。 我是一名探鬼主播污淋,決...
    沈念sama閱讀 40,320評論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼,長吁一口氣:“原來是場噩夢啊……” “哼余掖!你這毒婦竟也來了寸爆?” 一聲冷哼從身側(cè)響起,我...
    開封第一講書人閱讀 39,241評論 0 276
  • 序言:老撾萬榮一對情侶失蹤盐欺,失蹤者是張志新(化名)和其女友劉穎赁豆,沒想到半個月后,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體冗美,經(jīng)...
    沈念sama閱讀 45,686評論 1 314
  • 正文 獨居荒郊野嶺守林人離奇死亡魔种,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 37,878評論 3 336
  • 正文 我和宋清朗相戀三年,在試婚紗的時候發(fā)現(xiàn)自己被綠了粉洼。 大學(xué)時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片节预。...
    茶點故事閱讀 39,992評論 1 348
  • 序言:一個原本活蹦亂跳的男人離奇死亡,死狀恐怖属韧,靈堂內(nèi)的尸體忽然破棺而出安拟,到底是詐尸還是另有隱情,我是刑警寧澤宵喂,帶...
    沈念sama閱讀 35,715評論 5 346
  • 正文 年R本政府宣布糠赦,位于F島的核電站,受9級特大地震影響锅棕,放射性物質(zhì)發(fā)生泄漏拙泽。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點故事閱讀 41,336評論 3 330
  • 文/蒙蒙 一裸燎、第九天 我趴在偏房一處隱蔽的房頂上張望顾瞻。 院中可真熱鬧,春花似錦顺少、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,912評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽梅猿。三九已至,卻和暖如春秒裕,著一層夾襖步出監(jiān)牢的瞬間袱蚓,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 33,040評論 1 270
  • 我被黑心中介騙來泰國打工几蜻, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留喇潘,地道東北人。 一個月前我還...
    沈念sama閱讀 48,173評論 3 370
  • 正文 我出身青樓梭稚,卻偏偏與公主長得像颖低,于是被迫代替她去往敵國和親。 傳聞我的和親對象是個殘疾皇子弧烤,可洞房花燭夜當(dāng)晚...
    茶點故事閱讀 44,947評論 2 355

推薦閱讀更多精彩內(nèi)容