linux mysql 5.7 双机热备_2017年5月5日 星红桉liunx动手实践mysql 主主双机热备
第一步:安裝mysql
可參考http://www.runoob.com/mysql/mysql-install.html
心得:
rpm -ivh mysql-community-common-5.7.10-1.el6.x86_64.rpm --force --nodeps
rpm -ivh mysql-community-libs-5.7.10-1.el6.x86_64.rpm --force --nodeps
rpm -ivh mysql-community-client-5.7.10-1.el6.x86_64.rpm --force --nodeps
rpm -ivh mysql-community-server-5.7.10-1.el6.x86_64.rpm --force --nodeps
啟動
service mysqld start
/etc/init.d/mysqld/etc/init.d/mysqld start
5.7裝好mysql
mysql -u用戶名 -p密碼
默認安裝后是登錄不進去的,需要跳過登錄,直接進入
mysqld_safe --user=mysql --skip-grant-tables --skip-networking&mysql ?/**進入mysql交互窗口*/
mysql>UPDATE mysql.user SET authentication_string=PASSWORD('root') where USER='root'; /*5.7之后的版本user表中沒有password字段*/
否則:mysql> UPDATE user SET Password=PASSWORD('newpassword') where USER='root';
切記:
只要修改mysql 系統文件就要 刷新權限 ? ?mysql>?flush privileges;
mysql> exit;
第二步:
修改mysql編碼,同時修改密碼安全級別:
vi /etc/my.cnf
# reset pass level
validate_password_policy = 0
validate_password_length = 1
validate_password_mixed_case_count = 0
validate_password_number_count = 0
validate_password_special_char_count = 0
character_set_server=utf8
default-storage-engine=INNODB
collation-server=utf8_general_ci
[client]
default-character-set=utf8
授權
mysql>?grant all privileges on *.* TO 'root'@'localhost' identified by 'root' with grant option;本地
mysql>GRANT ALL PRIVILEGES ON *.* TO ' root'@'%' IDENTIFIED BY 'root' WITH GRANT OPTION;遠程
刷新權限
flush privileges;
第三步:
兩臺服務器 A服務器(10.69.37.75)
B服務器(10.69.37.122)
service mysqld stop
A服務器(10.69.37.75)
在A服務器的mysql配置文件中添加 server_id=1 ? log_bin=mysql-bin ? ? binlog_ignore_db=information_schema,performance_schema,mysql
vi /etc/my.cnf
# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html
[mysqld]
# binlog_format=mixed
# log-bin=mysql-bin
# server-id=1
# binlog-do-db=starv_hlw,starv_boss
# binlog-ignore-db=mysql
# replicate-do-db=starv_hlw,starv_boss
# replicate-ignore-db=mysql
# log-slave-updates
# sync_binlog=1
# auto_increment_increment=2
# auto_increment_offset=1
#雙機熱備主要是下面三行
server_id=1
log_bin=mysql-bin
binlog_ignore_db=information_schema,performance_schema,mysql ##排除的數據庫,也就是不需要同步的數據庫
#
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
#
# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin
#
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M
#datadir=/var/lib/mysql
datadir=/data1/mysqldata/mysql
socket=/var/lib/mysql/mysql.sock
#socket=/data1/mysqldata/mysql/mysql.sock
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
# reset pass level
validate_password_policy = 0
validate_password_length = 1
validate_password_mixed_case_count = 0
validate_password_number_count = 0
validate_password_special_char_count = 0
character_set_server=utf8
default-storage-engine=INNODB
collation-server=utf8_general_ci
[client]
default-character-set=utf8
退出my.cnf
啟動 service mysqld start
mysql -root ?-proot
mysql>
mysql>?change master to master_host='10.69.37.75',master_port=3306,master_user='root',master_password='root';
如果不成功
首先在A服務器上連接B服務器數據庫看是否能夠連接進去
mysql -h10.69.37.122 -uroot -proot
如果不能進入就需要查看B服務的 servie mysqld status
如果成功
首先1.mysql> stop slave
2.mysql> start slave
3.mysql> show slave status \G
上面的紅色框,前兩者必須是yes,后面是兩邊數據庫同步延遲時間,數值越小越好,大了說明雙機熱備有問題
連接B服務器(10.69.37.122)
通A服務器(10.69.37.75)一樣 master_host='10.69.37.122' 就是修改一下master_host='10.69.37.75' 整個語句如下:
mysql> change master to master_host='10.69.37.75',master_port=3306,master_user='root',master_password='root';
我們在B服務器(10.69.37.122)上創建一個數據庫名為lq_122;
后面不演示了,兩邊相互創建數據庫、數據庫表、添加表信息、修改表信息、刪除信息都成功
可參考 http://blog.csdn.net/huaweitman/article/details/50853075
還可參考網站:http://blog.csdn.net/zwz1984/article/details/45362471
總結
以上是生活随笔為你收集整理的linux mysql 5.7 双机热备_2017年5月5日 星红桉liunx动手实践mysql 主主双机热备的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: java序列化异常_Java|序列化异常
- 下一篇: java多播_Java多播发送数据,未接