您好,登錄后才能下訂單哦!
一、mysql數據庫的安裝
分別在master 和slave上源碼安裝mysql數據庫
1.1 安裝相關包
1.1.1 cmake軟件
cd /home/oldboy/tools/
tar xf cmake-2.8.8.tar.gz
cd cmake-2.8.8
./configure
#CMake has bootstrapped. Now run gmake.
gmake
gmake install
cd ../
1.1.2 依賴包
yum install ncurses-devel -y
1.2 開始安裝mysql
1.2.1 創建用戶和組
groupadd mysql
useradd mysql -s /sbin/nologin -M -g mysql
1.2.2 解壓編譯MySQL
tar zxf mysql-5.5.32.tar.gz
cd mysql-5.5.32
cmake . -DCMAKE_INSTALL_PREFIX=/application/mysql/mysql-5.5.40 \
-DMYSQL_DATADIR=/application/mysql/mysql-5.5.40/data \
-DMYSQL_UNIX_ADDR=/application/mysql/mysql-5.5.40/tmp/mysql.sock \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DEXTRA_CHARSETS=gbk,gb2312,utf8,ascii \
-DENABLED_LOCAL_INFILE=ON \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_FEDERATED_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DWITHOUT_EXAMPLE_STORAGE_ENGINE=1 \
-DWITHOUT_PARTITION_STORAGE_ENGINE=1 \
-DWITH_FAST_MUTEXES=1 \
-DWITH_ZLIB=bundled \
-DENABLED_LOCAL_INFILE=1 \
-DWITH_READLINE=1 \
-DWITH_EMBEDDED_SERVER=1 \
-DWITH_DEBUG=0
#-- Build files have been written to: /home/oldboy/tools/mysql-5.5.32
提示,編譯時可配置的選項很多,具體可參考結尾附錄或官方文檔:
make
#[100%] Built target my_safe_process
make install
ln -s /application/mysql-5.5.32/ /application/mysql
如果上述操作未出現錯誤,則MySQL5.5.32軟件cmake方式的安裝就算成功了。
1.3安裝數據庫成功后
1.3.1 修改mysql安裝目錄的權限,全部修改為mysql
chown -R mysql:mysql /application/mysql
1.3.2 初始化數據庫
cd /application/mysql/scripts
[root@localhost scripts]# ./mysql_install_db --basedir=/application/mysql --datadir=/data/mysql --user=mysql
1.3.3 替換/etc/下的配置文件和數據庫的啟動文件
/application/mysql/support-files
cp -r my-small.cnf /etc/my.cnf
cp -r mysql.server /etc/init.d/mysql
1.4啟動數據庫
/etc/init.d/mysql start
/etc/init.d/mysql stop
/etc/init.d/mysql restart
二、mysql數據庫分庫分表的同步
2.1master配置文件
log-bin=mysql-bin
binlog_format=row
server-id = 15
binlog-do-db=sales
/etc/init.d/mysql restart(重啟數據庫)
2.2slave配置文件
server-id = 25
relay-log=relay-bin
read-only = 1
replicate-do-db = sales
replicate-do-db =user_info
replicate-ignore-db = information_schema
replicate-ignore-db = mysql
replicate-ignore-db = user_info
replicate-do-table =sales.story // 所要同步的數據庫的單個表
/etc/init.d/mysql restart(重啟數據庫)
2.3在master上創建同步的用戶
grant replication client,replication slave on *.* to rep@'172.27.1.%' identified by 'password';
mysql> show master status\G;
*************************** 1. row ***************************
File: mysql-bin.000003
Position: 150
Binlog_Do_DB: sales,user_info
Binlog_Ignore_DB:
Executed_Gtid_Set:
1 row in set (0.00 sec)
ERROR:
No query specified
2.4在slave上執行如下語句,同步到master
change master to master_host='172.27.1.12'(主庫IP地址),master_user='rep',master_password='financial',master_log_file='mysql-bin.000003',master_log_pos=150;
start slave(啟動從庫)
stop slave(停止從庫)
reset slave(重置從庫)
啟動數據庫后查看slave的狀態如下:
mysql> show slave status\G;
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 172.27.1.12
Master_User: rep
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin.000003
Read_Master_Log_Pos: 150
Relay_Log_File: relay-bin.000002
Relay_Log_Pos: 269
Relay_Master_Log_File: mysql-bin.001603
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
Replicate_Do_DB: sales
Replicate_Ignore_DB: information_schema,mysql,user_info
Replicate_Do_Table: sales.story
Replicate_Ignore_Table:
Replicate_Wild_Do_Table:
Replicate_Wild_Ignore_Table:
Last_Errno: 0
Last_Error:
Skip_Counter: 0
Exec_Master_Log_Pos: 150
Relay_Log_Space: 419
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: 15
1 row in set (0.00 sec)
ERROR:
No query specified
上述表示數據庫master and slave 已配置好,可以進行同庫單個表的配置
測試:
1.分別在master和slave創建數據庫sales(row模式下需要手動創建數據庫)。
2.use sales庫下,在master上創建表
CREATE TABLE user_info (
PersonID int,
LastName varchar(255),
FirstName varchar(255),
Address varchar(255),
City varchar(255)
);
3.在master上創建表
CREATE TABLE story (
PersonID int,
LastName varchar(255),
FirstName varchar(255),
Address varchar(255),
City varchar(255)
);
查看slave同步狀態:
a. story表同步成功
b. user_info表同步不成功
則mysql數據庫單庫,單表同步成功。
如果只是單庫同步,則在slave的配置文件中去掉:
replicate-do-table =sales.story // 所要同步的數據庫的單個表
在安裝過程中發現從低版本往高版本同步沒有問題,從高版本往低版本同步一直出現問題。
三、數據庫5.7二進制版本
下載鏈接:
https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.18-linux-glibc2.5-x86_64.tar.gz
直接解壓使用,授權,初始化命令變為:
bin/mysqld --initialize --user=mysql --basedir=/application/mysql-5.7.18 --datadir=/application/mysql-5.7.18/data
注意:初始化會生成登錄數據庫的初始密碼,要記得保存。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。