linux環(huán)境,mysql安裝,主從同步,備份還原,增量同步

下載mysql地址5.6版本:

Download MySQL Community Server?dev.mysql.com

下載地址:

https://dev.mysql.com/get/Downloads/MySQL-5.6/mysql-5.6.43-linux-glibc2.12-x86_64.tar.gz?dev.mysql.com

解壓文件:tar -zxvf mysql-5.6.42-linux-glibc2.12-x86_64.tar-1.gz

增加用戶組:groupadd mysql

用戶組增加用戶:useradd -r -g mysql mysql

修改數(shù)據(jù)庫文件夾名稱:mv mysql-5.6.42-linux-glibc2.12-x86_64 mysql

將數(shù)據(jù)庫文件夾移動(dòng)到/usr/local目錄:mv mysql /usr/local

cd /usr/local/mysql

mkdir log

touch /usr/local/mysql/log/mysql.err

chown -R mysql:mysql ./



[client]

port = 3556

socket = /tmp/mysql.sock

default-character-set=utf8

[mysqld]

port = 3556

socket = /tmp/mysql.sock

character_set_server = utf8

skip-external-locking

default-storage-engine=INNODB

key_buffer_size = 384M

max_allowed_packet = 1M

table_open_cache = 512

sort_buffer_size = 2M

read_buffer_size = 2M

read_rnd_buffer_size = 8M

myisam_sort_buffer_size = 64M

thread_cache_size = 8

query_cache_size = 32M

# Try number of CPU's*2 for thread_concurrency

thread_concurrency = 8

skip-name-resolve

skip-symbolic-links

log-slave-updates = 1

#skip-networking

max_allowed_packet = 256M

tmp_table_size=128M

max_heap_table_size=128M

sort_buffer_size = 16M

query_cache_type = 0

query_cache_size = 256M

query_cache_limit = 2M

lower_case_table_names = 1

max_connections=1000

#about myisam

key_buffer_size=128M

log-error = /usr/local/mysql/log/mysql.err

long-query-time = 0.5

slow-query-log = 1

slow-query-log-file = /usr/local/mysql/log/mysql-slow.log

general-log=0

general-log-file = /tmp/mysql.log

server-id = 5

log-bin = mysql-bin

max_binlog_size = 1000M

binlog_format = ROW

expire_logs_days = 10

sync_binlog = 0

#skip-slave-start

#relay-log=mysql-relay

#relay-log-info-file=mysql-relay.info

innodb_data_home_dir = /usr/local/mysql/data

innodb_data_file_path = ibdata1:2000M;ibdata2:10M:autoextend

innodb_log_group_home_dir = /usr/local/mysql/data

innodb_buffer_pool_size = 384M

innodb_file_io_threads = 4

innodb_thread_concurrency = 16

innodb_additional_mem_pool_size = 20M

innodb_log_file_size = 512M

innodb_log_buffer_size = 8M

innodb_flush_log_at_trx_commit = 1

innodb_lock_wait_timeout = 50

[mysqldump]

quick

max_allowed_packet = 16M

[mysql]

no-auto-rehash

# Remove the next comment character if you are not familiar with SQL

#safe-updates

[myisamchk]

key_buffer_size = 256M

sort_buffer_size = 256M

read_buffer = 2M

write_buffer = 2M

[mysqlhotcopy]

interactive-timeout



創(chuàng)建文件my.cnf,并拷貝到/etc目錄下

chown -R mysql:mysql /tmp

安裝mysql需要的軟件

yum install? libaio-devel.x86_64

yum -y install numactl.x86_64

yum install perl-Data-Dumper.x86_64

初始化數(shù)據(jù)庫

./scripts/mysql_install_db --user=mysql --defaults-file=/etc/my.cnf

建立軟鏈

ln -s /usr/local/mysql/bin/mysql /usr/bin

cp support-files/mysql.server /etc/rc.d/init.d/mysqld

拷貝之后才可以通過service mysqld restart 重啟mysql

修改密碼: ./bin/mysqladmin -u root password 'root,123'

如果不能修改成功,通過下面的方式啟動(dòng)來修改密碼

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

mysql -u mysql mysql -P 3556

mysql > use mysql;

mysql > UPDATE user SET Password=PASSWORD('root,123') where USER='root';

mysql > FLUSH PRIVILEGES;

mysql > quit;

重啟數(shù)據(jù)庫:

service mysqld restart

#給客戶端授權(quán)(通過執(zhí)行下面命令,可以通過本地遠(yuǎn)程連接數(shù)據(jù)庫)

GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'root,123' WITH GRANT OPTION;

#關(guān)閉主數(shù)據(jù)庫防火墻

systemctl stop firewalld.service

配置主從:

mysql

> CHANGE MASTER TO MASTER_HOST='主數(shù)據(jù)庫的ip地址',MASTER_PORT=3556,MASTER_USER='root',MASTER_PASSWORD='root,123',MASTER_LOG_FILE='mysql-bin.000008',MASTER_LOG_POS=440;

mysql > start slave;

mysql > show slave status\G;

#都是Yes才算成功

Slave_IO_Running: Yes

Slave_SQL_Running: Yes



數(shù)據(jù)庫備份和還原:(這是全量同步)

./mysqldump -h 數(shù)據(jù)庫ip? -P 3556 -u root -p? cobra > /usr/local/cobra.dump

全量還原:

mysql -uroot -P 3556 -p

mysql > use cobra;

mysql > source /usr/local/cobra.dump



增量同步需要通過工具:otter

https://github.com/alibaba/otter/wiki/QuickStart?github.comalibaba/otteralibaba/otter?github.com

要安裝node和manage,具體安裝過程參考以上連接內(nèi)容。

第一步配置數(shù)據(jù)庫數(shù)據(jù)源:

配置表:

配置canel:

配置channel:

配置pipeline:

配置映射關(guān)系:

最后運(yùn)行channel,就可以完成增量同步。

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容