centos下mysql源碼編譯安裝和主備非同步配置

來源:互聯網
上載者:User

標籤:

安裝機器:10.11.1.193、10.11.1.194

主備同步方式:非同步同步

mysql版本:mysql community5.6.28


下載源碼並解壓:

tar -zxf mysql-5.6.28.tar.gz



cmake安裝:




安裝編譯所需環境:

sudo yum install make gcc-c++ cmake bison-develncurses-devel libaio libaio-devel net-tools perl




編譯安裝mysql

cmake-DCMAKE_INSTALL_PREFIX=/home/liyuming/mysql/mysqld -DCMAKE_INSTALL_DATADIR=/home/liyuming/mysql/mysqld/data-DWITH_DEBUG=0 -DMYSQL_MAINTAINER_MODE=0

 

依次在源碼目錄執行下面的命令即可

make distclean

make -j 20

make install

切記不能執行rm -f CMakeCache.txt!


初始化資料庫

cd /home/liyuming/mysql/mysqld

scripts/mysql_install_db--user=mysql --basedir=/home/liyuming/mysql/mysqld --datadir=/home/liyuming/mysql/mysqld/data

 

啟動資料庫

編輯my.cnf 和 run.sh檔案

 

run.sh的內容:



my.cnf的內容:



檔案路徑:



啟動資料庫伺服器

sh run.sh server



資料庫用戶端

sh run.sh client



關閉資料庫伺服器

sh run.sh stop



資料庫調優:

將下面資訊追加到my.cnf檔案中

back_log=1000

wait_timeout=3600

max_connections=3000

thread_concurrency=48

default-storage-engine=InnoDB

key_buffer_size=8G

innodb_buffer_pool_size=40G

innodb_additional_mem_pool_size=1G

innodb_log_buffer_size=32M

query_cache_size=40G

read_buffer_size=20M

sort_buffer_size=20M

read_rnd_buffer_size=20M

thread_cache_size=640

配置後重新啟動資料庫服務

 

設定資料庫伺服器初始資訊

 

在啟動資料庫伺服器下操作

mysqladmin -u root password ‘root‘


or

mysqladmin -h 10.11.1.194 -P 13306 -u root password ‘root‘


測試

mysql -uroot -proot

mysql -hlocalhost -u root -p

OK


mysql -h 10.11.1.193 -P 13306 -u root -p


此時jdbc也無法串連上mysql


解決方案:

./mysqld_safe--user=mysql --skip-grant-tables --skip-networking &



再開一個用戶端

在安裝的bin目錄下

mysql -uroot mysql

updateuser set host =‘%‘ where user =‘root‘;

UPDATE user SET Password=PASSWORD(‘root‘) where USER=‘root‘ and host=‘root‘ or host=‘localhost‘;

UPDATE user SET Password=PASSWORD(‘root‘) where USER=‘root‘;

deletefrom user where USER=‘‘;

FLUSHPRIVILEGES;



然後正常關閉資料庫



再次啟動資料庫伺服器,一切可正常使用

 

配置主備

主從同步的條件:

Master:

a 啟用二進位日誌;

b 選擇一個server-id

c 建立具有複製許可權的使用者

在my.cnf檔案中追加下面資訊

server-id=1

log-bin=mysql-bin

binlog-do-db=test

binlog-ignore-db= mysql

 

在資料庫中執行:

grant replication slave on *.* to‘slave‘@‘10.11.1.194‘ identifiedby ‘slave‘;

flush privileges;

 

重啟資料庫服務

show masterstatus;



Slave:

a 啟用中繼日誌

b 選擇一個唯一的server-id

c 串連主伺服器,並開始複製資料


在my.cnf檔案中追加下面資訊

server-id=2

replicate-do-db=test

 

在資料庫中執行:

stop slave;

change master to master_host=‘10.11.1.193‘, master_port=13306,master_user=‘slave‘, master_password=‘slave‘;

start slave;

show slave status \G;


一切OK!

centos下mysql源碼編譯安裝和主備非同步配置

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.