MySQL 5.6.10 Innodb引擎數據庫升級方法

MySQL5.6.10Innodb引擎數據庫升級方法

數據庫環境:

MySQL5.1.50(MyISAM、master)192.168.1.16主庫

MySQL5.1.46(MyISAM、master)192.168.1.13主庫

MySQL5.1.50(MyISAM、slave)192.168.1.1413從庫

目標:升級192.168.1.16數據庫,更換數據庫引擎,完成後如下:

MySQL5.6.10(InnoDB、master)192.168.1.16主庫

MySQL5.1.46(MyISAM、master)192.168.1.13主庫

MySQL5.1.50(MyISAM、slave)192.168.1.1413從庫

1.把1.16數據庫從使用中分離出來(包括數據備份,原MySQL卸載等,省略)

2.編譯安裝MySQL5.6.10(1.16上面操作)

2.1檢查所需軟件包,上傳MySQL安裝程序

rpm-qagccgcc-c++makencurses-devel

軟件安裝程序存放目錄:/usr/local/software

cmake-2.8.5.tar.gzmysql-5.6.10.tar.gz

2.2安裝cmake

cd/usr/local/software

tarzxvfcmake-2.8.5.tar.gz

cdcmake-2.8.5

./configure

make

makeinstall

2.3安裝Mysql5.6.10

cmake-DCMAKE_INSTALL_PREFIX=/usr/local/mysql-5.6.10\

-DMYSQL_DATADIR=/usr/local/mysql-5.6.10/data\

-DWITH_MYISAM_STORAGE_ENGINE=1\

-DWITH_INNOBASE_STORAGE_ENGINE=1\

-DWITH_ARCHIVE_STORAGE_ENGINE=1\

-DWITH_BLACKHOLE_STORAGE_ENGINE=1\

-DENABLED_LOCAL_INFILE=1\

-DDEFAULT_CHARSET=utf8\

-DDEFAULT_COLLATION=utf8_general_ci

make

makeinstall

2.4配置MySQL(由於之前這臺機器已經創建好數據庫賬戶,此步省略)

groupadd-g3306mysql

useradd-u3306-gmysql-M-s/sbin/nologinmysql

2.5初始化數據庫

chown-Rmysql:mysql/usr/local/mysql-5.6.10/data

chmod-R755/usr/local/mysql-5.6.10/data

/usr/local/mysql-5.6.10/scripts/mysql_install_db--user=mysql--basedir=/usr/local/mysql-5.6.10--datadir=/usr/local/mysql-5.6.10/data--socket=/usr/local/mysql-5.6.10/data/mysql.sock--pid-file=/usr/local/mysql-5.6.10/data/hk16.pid

2.6配置MySQL服務,啓動MySQL

rm-rf/etc/my.cnf\\刪除原有my.cnf配置文件

vim/etc/my.cnf\\直接編輯新的my.cnf

my.cnf配置文件內容如下:

[mysqld]

character-set-server=utf8

wait_timeout=31536000

max_connections=3000

max_connect_errors=10000

max_allowed_packet=32M

skip-name-resolve

lower_case_table_names=1

thread_cache=128

table_open_cache=1024

query_cache_type=1

query_cache_size=128M

join_buffer_size=128M

sort_buffer_size=2M

read_buffer_size=2M

read_rnd_buffer_size=2M

open_files_limit=30720

max_heap_table_size=128M

tmp_table_size=128M

tmpdir=/dev/shm

binlog_cache_size=12M

max_binlog_size=1G

expire_logs_days=7

binlog_checksum=none

sync_binlog=0

innodb_buffer_pool_size=15G

innodb_use_sys_malloc=1

innodb_log_file_size=256M

innodb_log_buffer_size=16M

innodb_flush_log_at_trx_commit=2

innodb_flush_method=O_DIRECT

innodb_lock_wait_timeout=50

innodb_read_io_threads=8

innodb_write_io_threads=8

innodb_thread_concurrency=0

innodb_rollback_segments=128

innodb_change_buffer_max_size=50

log-bin=hk16-bin

explicit_defaults_for_timestamp

basedir=/usr/local/mysql-5.6.10

datadir=/usr/local/mysql-5.6.10/data

port=3306

server-id=100

socket=/usr/local/mysql-5.6.10/data/mysql.sock

[safe_mysqld]

log-error=/usr/local/mysql-5.6.10/data/hk16.err

pid-file=/usr/local/mysql-5.6.10/data/hk16.pid

user=mysql

[mysql]

socket=/usr/local/mysql-5.6.10/data/mysql.sock

default-character-set=utf8

auto-rehash

[mysqldump]

quick

max_allowed_packet=512M

[myisamchk]

key_buffer_size=512M

sort_buffer_size=512M

read_buffer=80M

write_buffer=80M

[mysqlhotcopy]

interactive-timeout

cp/usr/local/mysql-5.6.10/support-files/mysql.server/etc/init.d/mysqld

chmod+x/etc/init.d/mysqld

chkconfig--addmysqld

chkconfigmysqldon

servicemysqldrestart

netstat-tnlp|grep3306\\查看監聽端口

2.7配置環境變量,設置root密碼

vim/etc/profile

MYSQL_HOME=/usr/local/mysql-5.6.10

PATH=$PATH:$MYSQL_HOME/bin

exportPATHMYSQL_HOME

source/etc/profile

/usr/local/mysql-5.6.10/bin/mysqladmin-urootpassword'xxxx’

3.配置數據庫複製

3.1導出數據庫表結構(1.13數據庫上面操作)

mysqldump–uroot–pxxxx–danytracking4_1>anytracking4_1.sql

mysqldump–uroot–pxxxx–danytracking4_2>anytracking4_2.sql

mysqldump–uroot–pxxxx–danytracking4_3>anytracking4_3.sql

mysqldump–uroot–pxxxx–danytracking4_4>anytracking4_4.sql

3.2創建數據庫,拷貝表結構,更改數據庫引擎(1.16數據庫上面操作)

mysql–uroot-pxxx

createdatabaseanytracking4_1;

createdatabaseanytracking4_2;

createdatabaseanytracking4_3;

createdatabaseanytracking4_4;

exit;

cd/usr/local/backup

scp[email protected]:/usr/local/backup/db/*.

vimanytracking4_1.sql替換引擎:%s/MyISAM/InnoDB/g

vimanytracking4_2.sql替換引擎:%s/MyISAM/InnoDB/g

vimanytracking4_3.sql替換引擎:%s/MyISAM/InnoDB/g

vimanytracking4_4.sql替換引擎:%s/MyISAM/InnoDB/g

3.3導入表結構,修改my.cnf配置(192.168.1.16上面操作)

cd/usr/local/backup

mysql–uroot–pxxxanytracking4_1<anytracking4_1.sql

mysql–uroot–pxxxanytracking4_2<anytracking4_2.sql

mysql–uroot–pxxxanytracking4_3<anytracking4_3.sql

mysql–uroot–pxxxanytracking4_4<anytracking4_4.sql

vim/etc/my.cnf\\只同步特定的數據庫,在[mysqld]下添加

binlog-ignore-db=mysql

replicate-ignore-db=test

replicate-ignore-db=mysql

replicate-ignore-db=information-schema

replicate-ignore-db=performance_schema

replicate-do-db=anytracking4_1

replicate-do-db=anytracking4_2

replicate-do-db=anytracking4_3

replicate-do-db=anytracking4_4

保存,重啓數據庫servicemysqldrestart

4.配置數據庫主主同步

4.1清空1.16上面的binlog日誌,停止1.14從複製,防止數據丟失!

mysql–uroot–pxxxx(1.16上面操作)

RESETMASTER;

mysql–uroot–pxxxx(1.14上面操作)

stopslave;

4.2配置1.16從複製

flushtableswithreadlock;(1.13上面操作,全局鎖表)

showmasterstatus;\\查詢masterlog_file以及Postition,如下所示

mysql>showmasterstatus;

+------------------+-----------+--------------+------------------+

|File|Position|Binlog_Do_DB|Binlog_Ignore_DB|

+------------------+-----------+--------------+------------------+

|mysql-bin.003581|341699908||mysql|

+------------------+-----------+--------------+------------------+

1rowinset(0.00sec)

mysql–uroot–pxxx(1.16上面操作,指定主庫)

changemastertomaster_host='192.168.1.13',master_user='root',master_password='xxx',master_log_file='mysql-bin.003581',master_log_pos=341699908;

startslave;\\啓動從複製線程

showslavestatus\G\\查看主從複製狀態,如有錯誤,需看具體錯誤代碼內容

mysql>showslavestatus\G

***************************1.row***************************

Slave_IO_State:Waitingformastertosendevent

Master_Host:192.168.1.13

Master_User:root

Master_Port:3306

Connect_Retry:60

Master_Log_File:mysql-bin.003581

Read_Master_Log_Pos:369453801

Relay_Log_File:HK16-relay-bin.000016

Relay_Log_Pos:265

Relay_Master_Log_File:mysql-bin.003581

Slave_IO_Running:Yes

Slave_SQL_Running:Yes

Replicate_Do_DB:anytracking4_1,anytracking4_2,anytracking4_3,anytracking4_4

Replicate_Ignore_DB:test,mysql,information-schema,performance_schema

Replicate_Do_Table:

Replicate_Ignore_Table:

Replicate_Wild_Do_Table:

Replicate_Wild_Ignore_Table:

Last_Errno:0

Last_Error:

Skip_Counter:0

Exec_Master_Log_Pos:369453801

Relay_Log_Space:476

Until_Condition:None

Until_Log_File:

Until_Log_Pos:0

Master_SSL_Allowed:No

Master_SSL_CA_File:

Master_SSL_CA_Path:

Master_SSL_Cert:

Master_SSL_Cipher:

Master_SSL_Key:

Seconds_Behind_Master:0

Master_SSL_Verify_Server_Cert:No

Last_IO_Errno:0

Last_IO_Error:

Last_SQL_Errno:0

Last_SQL_Error:

Replicate_Ignore_Server_Ids:

Master_Server_Id:12

Master_UUID:

Master_Info_File:/usr/local/mysql-5.6.10/data/master.info

SQL_Delay:0

SQL_Remaining_Delay:NULL

Slave_SQL_Running_State:Slavehasreadallrelaylog;waitingfortheslaveI/Othreadtoupdateit

Master_Retry_Count:86400

Master_Bind:

Last_IO_Error_Timestamp:

Last_SQL_Error_Timestamp:

Master_SSL_Crl:

Master_SSL_Crlpath:

Retrieved_Gtid_Set:

Executed_Gtid_Set:

Auto_Position:0

1rowinset(0.00sec)

unlocktables;(1.13上面操作,解鎖)

這樣就完成了1.13與1.16不同版本、不同引擎數據庫主從複製!!

4.3配置1.13主複製

mysql–uroot–pxxxx(1.16上面操作)

showmasterstatus;\\查詢masterlog_file以及Postition,如下所示

mysql>showmasterstatus;

+-----------------+-----------+--------------+------------------+-------------------+

|File|Position|Binlog_Do_DB|Binlog_Ignore_DB|Executed_Gtid_Set|

+-----------------+-----------+--------------+------------------+-------------------+

|hk16-bin.000003|818885460||mysql||

+-----------------+-----------+--------------+------------------+-------------------+

1rowinset(0.00sec)

mysql–uroot–pxxx(1.13上面操作)

changemastertomaster_host='192.168.1.16',master_user='root',master_password='xxx',master_log_file='hk16-bin.000003',master_log_pos=818885460;

startslave;\\啓動從複製線程

showslavestatus\G\\查看主從複製狀態,如有錯誤,需看具體錯誤代碼內容

mysql>showslavestatus\G

***************************1.row***************************

Slave_IO_State:Waitingformastertosendevent

Master_Host:192.168.1.16

Master_User:root

Master_Port:3306

Connect_Retry:60

Master_Log_File:hk16-bin.000003

Read_Master_Log_Pos:823385525

Relay_Log_File:localhost-relay-bin.000023

Relay_Log_Pos:823385669

Relay_Master_Log_File:hk16-bin.000003

Slave_IO_Running:Yes

Slave_SQL_Running:Yes

Replicate_Do_DB:anytracking4_1,anytracking4_2,anytracking4_3,anytracking4_4

Replicate_Ignore_DB:test,mysql,information-schema

Replicate_Do_Table:

Replicate_Ignore_Table:

Replicate_Wild_Do_Table:

Replicate_Wild_Ignore_Table:

Last_Errno:0

Last_Error:

Skip_Counter:0

Exec_Master_Log_Pos:823385525

Relay_Log_Space:823385870

Until_Condition:None

Until_Log_File:

Until_Log_Pos:0

Master_SSL_Allowed:No

Master_SSL_CA_File:

Master_SSL_CA_Path:

Master_SSL_Cert:

Master_SSL_Cipher:

Master_SSL_Key:

Seconds_Behind_Master:0

Master_SSL_Verify_Server_Cert:No

Last_IO_Errno:0

Last_IO_Error:

Last_SQL_Errno:0

Last_SQL_Error:

1rowinset(0.00sec)

這樣就完成了1.16與1.13不同版本、不同引擎數據庫主主複製!!

注:同步過程中,出現的錯誤,在此不做說明!請查詢相關錯誤代碼解決。

5啓動1.14從服務

mysql–uroot–pxxx(1.14上面操作)

startslave;\\啓動從複製線程

showslavestatus\G\\查看主從複製狀態,如下所示

mysql>showslavestatus\G

***************************1.row***************************

Slave_IO_State:Waitingformastertosendevent

Master_Host:192.168.1.13

Master_User:root

Master_Port:3306

Connect_Retry:60

Master_Log_File:mysql-bin.003581

Read_Master_Log_Pos:427635071

Relay_Log_File:hk14-relay-bin.000024

Relay_Log_Pos:427635216

Relay_Master_Log_File:mysql-bin.003581

Slave_IO_Running:Yes

Slave_SQL_Running:Yes

Replicate_Do_DB:anytracking4_1,anytracking4_2,anytracking4_3,anytracking4_4

Replicate_Ignore_DB:test,mysql,information-schema

Replicate_Do_Table:

Replicate_Ignore_Table:

Replicate_Wild_Do_Table:

Replicate_Wild_Ignore_Table:

Last_Errno:0

Last_Error:

Skip_Counter:0

Exec_Master_Log_Pos:427635071

Relay_Log_Space:427635413

Until_Condition:None

Until_Log_File:

Until_Log_Pos:0

Master_SSL_Allowed:No

Master_SSL_CA_File:

Master_SSL_CA_Path:

Master_SSL_Cert:

Master_SSL_Cipher:

Master_SSL_Key:

Seconds_Behind_Master:0

Master_SSL_Verify_Server_Cert:No

Last_IO_Errno:0

Last_IO_Error:

Last_SQL_Errno:0

Last_SQL_Error:

1rowinset(0.00sec)

到這裏就已經完成整個升級操作,接下來就進行相應的測試下!

6寫入數據測試複製集

方法一:手動插入數據到一個表裏面,然後進行其他機器上繼續查詢看是否同步過來

方法二:寫個批量插入程序,在此不做說明!!

7優化1.16數據庫my.cnf配置

1.16服務器硬件配置如下:

機器型號:DELLPowerEdgeR7102U

CPU:4n16線程

內存:24GB

硬盤:1TB

操作系統版本:centos5.5

優化後的my.cnf配置文件參數示例如下:

[mysqld]

character-set-server=utf8

wait_timeout=31536000

max_connections=3000

max_connect_errors=10000

max_allowed_packet=32M

skip-name-resolve

lower_case_table_names=1

thread_cache=128

table_open_cache=1024

query_cache_type=1

query_cache_size=128M

join_buffer_size=128M

sort_buffer_size=2M

read_buffer_size=2M

read_rnd_buffer_size=2M

open_files_limit=30720

max_heap_table_size=128M

tmp_table_size=128M

tmpdir=/dev/shm

binlog_cache_size=12M

max_binlog_size=1G

expire_logs_days=7

binlog_checksum=none

sync_binlog=0

innodb_buffer_pool_size=15G

innodb_use_sys_malloc=1

innodb_log_file_size=256M

innodb_log_buffer_size=16M

innodb_flush_log_at_trx_commit=2

innodb_flush_method=O_DIRECT

innodb_lock_wait_timeout=50

innodb_read_io_threads=8

innodb_write_io_threads=8

innodb_thread_concurrency=0

innodb_rollback_segments=128

innodb_change_buffer_max_size=50

log-bin=hk16-bin

explicit_defaults_for_timestamp

basedir=/usr/local/mysql-5.6.10

datadir=/usr/local/mysql-5.6.10/data

port=3306

server-id=100

socket=/usr/local/mysql-5.6.10/data/mysql.sock

binlog-ignore-db=mysql

replicate-ignore-db=test

replicate-ignore-db=mysql

replicate-ignore-db=information-schema

replicate-ignore-db=performance_schema

replicate-do-db=anytracking4_1

replicate-do-db=anytracking4_2

replicate-do-db=anytracking4_3

replicate-do-db=anytracking4_4

[safe_mysqld]

log-error=/usr/local/mysql-5.6.10/data/hk16.err

pid-file=/usr/local/mysql-5.6.10/data/hk16.pid

user=mysql

[mysql]

socket=/usr/local/mysql-5.6.10/data/mysql.sock

default-character-set=utf8

auto-rehash

[mysqldump]

quick

max_allowed_packet=512M

[myisamchk]

key_buffer_size=512M

sort_buffer_size=512M

read_buffer=80M

write_buffer=80M

[mysqlhotcopy]

interactive-timeout

8預熱數據表

有一種新的預熱方法需要調參數:

8.1如果是正常關閉,可以使用5.6的快速預熱備份!

你只需在my.cnf裏,加入如下:

innodb_buffer_pool_dump_at_shutdown=1\\解釋:在關閉時把熱數據dump到本地磁盤。

innodb_buffer_pool_dump_now=1\\解釋:採用手工方式把熱數據dump到本地磁盤。

innodb_buffer_pool_load_at_startup=1\\解釋:在啓動時把熱數據加載到內存。

innodb_buffer_pool_load_now=1\\解釋:採用手工方式把熱數據加載到內存。

在關閉MySQL時,會把內存中的熱數據保存在磁盤裏ib_buffer_pool文件中,位於數據目錄下。

預熱後,查看innodb_buffer_pool是不是變化較大

SHOWGLOBALSTATUSLIKE'%innodb_buffer%';

Innodb_buffer_pool_pages_data和Innodb_buffer_pool_pages_free是否變化較大!

8.2如果是異常關閉,就只能用5.1的手動預熱方法了!

Innodb數據庫數據手動預熱方法:

SELECTtable_nameFROMinformation_schema.tablesWHEREtable_schemaNOTIN('mysql','information_schema','performance_schema')\\查詢出所有的表

SELECTCONCAT('selectcount(1)from',table_schema,'.',table_name,';')FROMinformation_schema.tablesWHEREtable_schemaNOTIN('mysql','information_schema','performance_schema');\\組裝預熱表

SELECTCONCAT('select*from',table_schema,'.',table_name,'limit10;')FROMinformation_schema.tablesWHEREtable_schemaNOTIN('mysql','information_schema','performance_schema');\\組裝預熱表

將組裝預熱表查詢出來的語句拷貝出來,然後在去數據庫裏執行!!可以只針對業務使用比較多的表進行預熱。

編寫者:李惟忠

公司:廣州埃立方通信技術有限公司

日期:2013-09-26

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章