mysql-5.5.31主从复制
chown -R mysql:mysql /opt/mysql
準備工作:安裝基本依賴包,先用yum安裝cmake、automake 、autoconf ,另MySQL 5.5.x需要最少安裝的包有:bison,gcc、gcc-c++、ncurses-devel
yum -y install gcc gcc-c++ autoconf bison automake zlib* fiex* libxml* ncurses-devel libmcrypt* libtool-ltdl-devel*
安裝cmake(mysql5.5以后是通過cmake來編譯的)
axel -n ?10 http://www.cmake.org/files/v2.8/cmake-2.8.4.tar.gztar zxvf cmake-2.8.4.tar.gz./bootstrapgmake install下載解壓mysql 5.5.11axel ?-n 10 http://mirrors.sohu.com/mysql/MySQL-5.5/mysql-5.5.30.tar.gztar zxfv ?mysql-5.5.30.tar.gzcmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_DATADIR=/opt/mysql \
-DSYSCONFDIR=/etc \
-DMYSQL_UNIX_ADDR=/tmp/mysqld.sock \
-DMYSQL_USER=mysql \
-DMYSQL_TCP_PORT=3306 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_ARCHIVE_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DWITH_FEDERATED_STORAGE_ENGINE=0 \
-DWITH_PARTITION_STORAGE_ENGINE=1 \
-DENABLED_LOCAL_INFILE=1 \
-DWITH_SSL=no \
-DEXTRA_CHARSETS=all \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DWITH_READLINE=1 \
-DWITH_ZLIB=system \
-DINSTALL_PLUGINDIR=lib64/mysql/plugin \
-DINSTALL_LIBDIR=lib64/mysql \
-DINSTALL_INCLUDEDIR=include/mysql \
-DWITH_DEBUG=0
碰到了錯誤:-- Could NOT find Curses (missing: ?CURSES_LIBRARY CURSES_INCLUDE_PATH) CMake Error at cmake/readline.cmake:83 (MESSAGE): ?Curses library not found. ?Please install appropriate package, ? ? ?remove CMakeCache.txt and rerun cmake.On Debian/Ubuntu, package name is libncurses5-dev, on Redhat and derivates it is ncurses-devel.Call Stack (most recent call first): ?cmake/readline.cmake:127 (FIND_CURSES) ?cmake/readline.cmake:217 (MYSQL_USE_BUNDLED_LIBEDIT) ?CMakeLists.txt:269 (MYSQL_CHECK_READLINE)-- Configuring incomplete, errors occurred!是因為少了ncurses-devel這個包。用yum安裝后,然后把目錄下的CMakeCache.txt 刪除,否則還是報之前的錯誤然后就是make ?&& make ?install cp support-files/my-medium.cnf /etc/my.cnf chown -R mysql:mysql mysql/opt]# /opt/mysql/scripts/mysql_install_db --user=mysql ?--defaults-file=/etc/my.cnf --basedir=/usr/local/mysql --datadir=/opt/data/usr/local/mysql/bin/mysqld_safe --user=mysql & ?啟動mysqlcp ?mysql-5.5.30/support-files/mysql.server /etc/init.d/mysqldchmod +x ?/etc/init.d/mysqldchown .mysql ?/etc/init.d/mysqldchkconfig --add ?mysqld
chkconfig mysqld ?on
接下來開始部署主從環境
在主服務器上配置mysql的配置文件
確保/etc/my.cnf中有如下參數,沒有的話需手工添加,并重啟mysql服務。[mysqld]log-bin=mysql-bin 啟動二進制文件server-id=1 服務器ID
然后進入到mysql數據庫里進行授權
grant replication slave on *.* to 'backup'@'x.x.x.x' identified by 'backup';
查詢主數據庫狀態,并記下FILE及Position的值,這個在后面配置從服務器的時候要用到
show master status;
+------------------+----------+--------------+------------------+
| File ? ? ? ? ? ? | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+------------------+----------+--------------+------------------+
| mysql-bin.000010 | ? ? ?264 | ? ? ? ? ? ? ?| ? ? ? ? ? ? ? ? ?|
+------------------+----------+--------------+------------------+
1 row in set (0.00 sec)
主數據庫的操作就到這里,下面的操作在從服務器上操作
確保/etc/my.cnf中有log-bin=mysql-bin和server-id=1參數,并把server-id=1修改為server-id=10。修改之后如下所示:[mysqld]log-bin=mysql-bin 啟動二進制文件server-id=10 服務器ID
重啟mysql服務。登錄mysql,執行如下語句change master to master_host='o.o.o.o',master_user='backup',master_password='backup',master_log_file='mysql-bin.000010',master_log_pos=264;
啟動slave同步。start slave;檢查主從同步,如果您看到Slave_IO_Running和Slave_SQL_Running均為Yes,則主從復制連接正常。show slave status\G
注: 刪除mysql日志文件后報I/O error reading the header from the binary log, errno=175, io cache
data目錄下日志文件很多,很煩,把mysql-bin.000001~mysql-bin.0000018都刪掉了。結果報以下錯誤:
120914 10:23:31 [ERROR] I/O error reading the header from the binary log, errno=175, io cache code=0
120914 10:23:31 [ERROR] I/O error reading the header from the binary log
120914 10:23:31 [ERROR] Can't init tc log
120914 10:23:31 [ERROR] Aborting
解決辦法:
把剩下的有關日志的文件都刪掉。把ibdata1,ib_logfile0,ib_logfile1,mysql-bin.index,再啟動就可以了
轉載于:https://blog.51cto.com/sunway/1224903
創作挑戰賽新人創作獎勵來咯,堅持創作打卡瓜分現金大獎總結
以上是生活随笔為你收集整理的mysql-5.5.31主从复制的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: MySQL速忆笔记(更新中)
- 下一篇: WordPress中输出当前页面SQL语