Ubuntu下編譯安裝MySQL雙執行個體並配置主從複製

來源:互聯網
上載者:User

一.安裝前準備
   下載Mysql源碼包:推薦官方網站http://www.mysql.com/
   配置Ubuntu環境
   添加mysql使用者組和使用者:
   groupadd mysql
   useradd -g mysql mysql
   建立安裝所需目錄
   master執行個體安裝目錄:
   mkdir /opt/mastermysql/
   mkdir /opt/mastermysql/data/
   slave執行個體安裝目錄:
   mkdir /opt/slavemysql/
   mkdir /opt/slavemysql/data
  
   更改許可權:
   chown mysql:mysql -R /opt/mastermysql/data
   chown mysql:mysql -R /opt/slavemysql/data  
二. 安裝master執行個體
   將源碼包複製到主目錄 /root
   解壓:
   cd /root
   mkdir mastermysql
   tar -xv -f  mysql-5.5.18.tar.gz -C ~/mastermysql
   進入到源碼目錄:
   cd mastermysql/mysql-5.5.18
   編譯配置:  
    cmake -DCMAKE_INSTALL_PREFIX=/opt/mastermysql 
-DSYSCONFDIR=/opt/mastermysql/etc   
    -DMYSQL_DATADIR=/opt/mastermysql/data -DMYSQL_TCP_PORT=3307
-DMYSQL_UNIX_ADDR=/tmp/mysqld.sock -DMYSQL_USER=mysql
-DEXTRA_CHARSETS=all
-DWITH_READLINE=1 -DWITH_SSL=system
-DWITH_EMBEDDED_SERVER=1 -DENABLED_LOCAL_INFILE=1
-DWITH_INNOBASE_STORAGE_ENGINE=1
    -DWITHOUT_PARTITION_STORAGE_ENGINE=1
   make
   make install
   安裝完成,配置並初始化資料庫
   make /opt/mastermysql/etc
   cp support-files/my-medium.cnf /opt/mastermysql/etc/my.cnf
   初始化資料庫
   chmod 755 scripts/mysql_install_db
   scripts/mysql_install_db --user=mysql --basedir=/opt/mastermysql
   --datadir=/opt/mastermysql/data
   建立管理mysql資料庫的shell指令碼
   mkdir /opt/mysql/init.d
   cp support-files/mysql.server /opt/mastermysql/init.d/mysql
   賦予shell指令碼可執行許可權:
   chmod +x /opt/mastermysql/init.d/mysql
  
三. 安裝slave執行個體
   將第二步中所有的master字元替換成slave,configure中的DMYSQL_TCP_PORT參數換成3308
四.配置master-slave
   啟動master-slave執行個體:
   /opt/mastermysql/init.d/mysql start
   /opt/slavemysql/init.d/mysql start
   配置master
   vi /opt/mastermysql/etc/my.cnf
      添加:server-id=1
log-bin=mysql-bin
   登陸master執行個體
   /opt/mastermysql/bin/mysql -uroot
   建立複製賬戶
   grant replication on *.* repl@localhost identified by '123456'
   show master status\G;
   記錄File,Position的值後面會用到
   登陸slave執行個體
   /opt/slavemysql/bin/mysql -uroot
   配置master-slave
   change master to master_host='127.0.0.1',master_port=3307,master_user='repl',
   master_password='123456',master_log_file='上述File的內容’,
   master_log_pos='上述Position的內容';
   start slave;
五.測試
   因為兩個資料庫都是同一份原始碼最新的安裝,所以他們資料庫的內容是以一樣的,也就
   不需要同步。 在master上建立表,並插入資料,在slave上查看是否有此表和資料。
六.總結
   上述步驟是在本人配置成功後邊回憶邊寫的,難免有疏漏的地方,歡迎大家批評指正。只要
   能夠明白源碼 安裝的過程,主從複製便十分簡單。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.