[comment]在編譯安裝 MySQL 5.6.x 之前,需要最少安裝的包有:bison,gcc、gcc-c++、cmake、ncurses-devel,
安裝這些依賴包後,把原來解壓出來的mysql源碼目錄刪除掉,再重新解壓出來,再去編譯.
-- 0
Download mysql-5.6.10.tar.gz in dev.mysql.com
-- 1 安裝cmake軟體包
tar xzvf cmake-2.8.3.tar.gz
./bootstrap
gmake
gmake install
-- 2 create account of mysql
groupadd mysql
useradd -g mysql mysql
autoreconf --force --install
libtoolize --automake --force
automake --force --add-missing
-- 3 complie the sources
mkdir -p /data/mbdata
tar xvfz mysql-5.5.20.tar.gz
yum --install cmake
time cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql56 -DMYSQL_DATADIR=/data56 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DMYSQL_UNIX_ADDR==/data56/mysql.sock -DMYSQL_USER=mysql -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci
-- 4 build the db directy
time make
time make install
-- 5 init db
ll /usr/local/mysql56/
cd /usr/local/mysql56/
chown -R mysql .
chgrp -R mysql .
cp support-files/my-default.cnf /etc/my56.cnf
scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql56 --datadir=/data56 --defaults-file=/etc/my56.cnf
[root@mysql mysql56]# scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql56 --datadir=/data56 --defaults-file=/etc/my56.cnf
WARNING: The host 'mysql.yest.nos' could not be looked up with /usr/local/mysql56/bin/resolveip.
This probably means that your libc libraries are not 100 % compatible
with this binary MySQL version. The MySQL daemon, mysqld, should work
normally with the exception that host name resolving will not work.
This means that you should use IP addresses instead of hostnames
when specifying MySQL privileges !
Installing MySQL system tables...2013-02-08 04:31:20 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2013-02-08 04:31:20 63040 [Note] InnoDB: The InnoDB memory heap is disabled
2013-02-08 04:31:20 63040 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2013-02-08 04:31:20 63040 [Note] InnoDB: Compressed tables use zlib 1.2.3
2013-02-08 04:31:20 63040 [Note] InnoDB: CPU does not support crc32 instructions
2013-02-08 04:31:20 63040 [Note] InnoDB: Using Linux native AIO
2013-02-08 04:31:20 63040 [Note] InnoDB: Initializing buffer pool, size = 128.0M
2013-02-08 04:31:20 63040 [Note] InnoDB: Completed initialization of buffer pool
2013-02-08 04:31:20 63040 [Note] InnoDB: The first specified data file ./ibdata1 did not exist: a new database to be created!
2013-02-08 04:31:20 63040 [Note] InnoDB: Setting file ./ibdata1 size to 12 MB
2013-02-08 04:31:20 63040 [Note] InnoDB: Database physically writes the file full: wait...
2013-02-08 04:31:20 63040 [Note] InnoDB: Setting log file ./ib_logfile101 size to 48 MB
2013-02-08 04:31:20 63040 [Note] InnoDB: Setting log file ./ib_logfile1 size to 48 MB
2013-02-08 04:31:20 63040 [Note] InnoDB: Renaming log file ./ib_logfile101 to ./ib_logfile0
2013-02-08 04:31:20 63040 [Warning] InnoDB: New log files created, LSN=45781
2013-02-08 04:31:20 63040 [Note] InnoDB: Doublewrite buffer not found: creating new
2013-02-08 04:31:21 63040 [Note] InnoDB: Doublewrite buffer created
2013-02-08 04:31:21 63040 [Note] InnoDB: 128 rollback segment(s) are active.
2013-02-08 04:31:21 63040 [Warning] InnoDB: Creating foreign key constraint system tables.
2013-02-08 04:31:21 63040 [Note] InnoDB: Foreign key constraint system tables created
2013-02-08 04:31:21 63040 [Note] InnoDB: Creating tablespace and datafile system tables.
2013-02-08 04:31:21 63040 [Note] InnoDB: Tablespace and datafile system tables created.
2013-02-08 04:31:21 63040 [Note] InnoDB: Waiting for purge to start
2013-02-08 04:31:21 63040 [Note] InnoDB: 1.2.10 started; log sequence number 0
2013-02-08 04:31:26 63040 [Note] Binlog end
2013-02-08 04:31:26 63040 [Note] InnoDB: FTS optimize thread exiting.
2013-02-08 04:31:26 63040 [Note] InnoDB: Starting shutdown...
2013-02-08 04:31:28 63040 [Note] InnoDB: Shutdown completed; log sequence number 1625977
OK
Filling help tables...2013-02-08 04:31:28 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2013-02-08 04:31:28 63063 [Note] InnoDB: The InnoDB memory heap is disabled
2013-02-08 04:31:28 63063 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2013-02-08 04:31:28 63063 [Note] InnoDB: Compressed tables use zlib 1.2.3
2013-02-08 04:31:28 63063 [Note] InnoDB: CPU does not support crc32 instructions
2013-02-08 04:31:28 63063 [Note] InnoDB: Using Linux native AIO
2013-02-08 04:31:28 63063 [Note] InnoDB: Initializing buffer pool, size = 128.0M
2013-02-08 04:31:28 63063 [Note] InnoDB: Completed initialization of buffer pool
2013-02-08 04:31:28 63063 [Note] InnoDB: Highest supported file format is Barracuda.
2013-02-08 04:31:28 63063 [Note] InnoDB: 128 rollback segment(s) are active.
2013-02-08 04:31:28 63063 [Note] InnoDB: Waiting for purge to start
2013-02-08 04:31:28 63063 [Note] InnoDB: 1.2.10 started; log sequence number 1625977
2013-02-08 04:31:28 63063 [Note] Binlog end
2013-02-08 04:31:28 63063 [Note] InnoDB: FTS optimize thread exiting.
2013-02-08 04:31:28 63063 [Note] InnoDB: Starting shutdown...
2013-02-08 04:31:30 63063 [Note] InnoDB: Shutdown completed; log sequence number 1625987
OK
To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system
PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
To do so, start the server, then issue the following commands:
/usr/local/mysql56/bin/mysqladmin -u root password 'new-password'
/usr/local/mysql56/bin/mysqladmin -u root -h mysql.yest.nos password 'new-password'
Alternatively you can run:
/usr/local/mysql56/bin/mysql_secure_installation
which will also give you the option of removing the test
databases and anonymous user created by default. This is
strongly recommended for production servers.
See the manual for more instructions.
You can start the MySQL daemon with:
cd . ; /usr/local/mysql56/bin/mysqld_safe &
You can test the MySQL daemon with mysql-test-run.pl
cd mysql-test ; perl mysql-test-run.pl
Please report any problems with the ./bin/mysqlbug script!
The latest information about MySQL is available on the web at
http://www.mysql.com
Support MySQL by buying support/licenses at http://shop.mysql.com
New default config file was created as /usr/local/mysql56/my.cnf and
will be used by default by the server when you start it.
You may edit this file to change server settings
-- 6 copy start command
cp support-files/mysql.server /etc/init.d/mysqld56
chmod 700 /etc/init.d/mysqld56
echo "export PATH=$PATH:/usr/local/mysql56/bin">>/etc/profile
source /etc/profile
-- 7 add command to system parameter
cd /data/mbdata
chkconfig --add mysqld56
-- 8 start service
service mysqld56 start
- ==================================================================
【PS】半同步複製
-- =================================================================
MySQL AB複製原理:
Master 伺服器 (主伺服器) 通過把所有涉及到資料庫更新操作都記錄到二進位日誌當中,
然後Slave 伺服器(從伺服器)就會通過IO_THREAD線程如串連主伺服器,然後主伺服器會通過IO_THREAD應答從伺服器,然後開始傳輸二進位日誌。從伺服器接受到相應的日誌記錄之後,就會通過SQL_THREAD線程去執行日誌當中記錄的更改.
實現的層級:row level,statement level,mixed level
複製時延性:非同步複製(MySQL AB複製天然屬性),即時複製(MySQL + DRBD),半同步複製(>=5.5版本之後才有,暫時不算完善)
1、安裝半同步複製的模組
master> install plugin rpl_semi_sync_master soname 'semisync_master.so'; 參數rpl_semi_sync_master_enabled=1 才生效。如果在安裝的時候不注釋掉,會報unknown variable 'rpl_semi_sync_master_enabled=1'的錯誤。
slave1> install plugin rpl_semi_sync_slave soname 'semisync_slave.so';
2、啟用半同步複製
master> set global rpl_semi_sync_master_enabled = on;
slave> set global rpl_semi_sync_slave_enabled = on;
slave> stop slave IO_THREAD;
slave> start slave IO_THREAD;
master> show status like ‘rpl_semi_sync_master_status’;
+—————————–+——-+
| Variable_name | Value |
+—————————–+——-+
| Rpl_semi_sync_master_status | ON |
+—————————–+——-+
master> show status like ‘rpl_semi_sync_master_clients’;
+——————————+——-+
| Variable_name | Value |
+——————————+——-+
| Rpl_semi_sync_master_clients | 1 | <---說明一個從伺服器是使用半同步模式
+------------------------------+-------+
3、確定正在使用半同步模式
master> insert into user values (8,’moto’);
master> show status like ‘Rpl_semi_sync_master_yes_tx’;
+—————————–+——-+
| Variable_name | Value |
+—————————–+——-+
| Rpl_semi_sync_master_yes_tx | 1 | <– 數值代表有多少個事務被從伺服器確認
+—————————–+——-+
驗證:
關閉master的網路,然後提交更新資料,發現會等待10秒才返回,因為主伺服器在等待從伺服器的確認,10秒之後逾時,就會返回,主伺服器會恢複到非同步模式。