mysql5.6二进制安装,主从/主主复制

MySQL5.6 二进制的安装方式


1. 操作系统


redhat5.4


 


2. 创建用户和组


[root@mymaster1 ~]# groupadd mysql


[root@mymaster1 ~]# useradd -r -g mysqlmysql


 


3. 解压安装包(解压到你想存储数据库数据的地方)


[root@mymaster1 ~]# cd /data


[root@mymaster1 data]# tar -xzvf /root/mysql_soft/mysql-5.6.19-linux-glibc2.5-x86_64.tar.gz


[root@mymaster1 data]# ln -s mysql-5.6.19-linux-glibc2.5-x86_64 mysql


 


4. 查看解压情况


[root@mymaster1 data]# ll


总用量 20


lrwxrwxrwx. 1 root root 34 6月 27 15:31 mysql -> mysql-5.6.19-linux-glibc2.5-x86_64


drwxr-xr-x. 13 rootroot 4096 6月 27 15:31 mysql-5.6.19-linux-glibc2.5-x86_64


 


5. 修改文件夹所属用户和组为mysql:


[root@mymaster1 data]# cd mysql


[root@mymaster1 mysql]# chown -R mysql:mysql .


 


6. 安装数据库,数据存放目录为/data/mysql/data


[root@mymaster1 mysql]#scripts/mysql_install_db --user=mysql --basedir=/data/mysql --datadir=/data/mysql/data


WARNING: The host'mymaster1.localdomain' could not be looked up with /data/mysql/bin/resolveip.


This probably means thatyour libc libraries are not 100 % compatible


with this binary MySQLversion. The MySQL daemon, mysqld, should work


normally with the exceptionthat host name resolving will not work.


This means that youshould use IP addresses instead of hostnames


when specifying MySQLprivileges !


 


当出现上面警告时,解决方法是:在/etc/hosts配置文件中增加IP地址和主机名的映射





[root@mymaster1 Packages]# cat /etc/hosts


127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4


::1 localhost localhost.localdomain localhost6 localhost6.localdomain6


IP地址 mymaster1.localdomain


 


正确的提示信息如下:


[root@mymaster1 mysql]#scripts/mysql_install_db --user=mysql --basedir=/data/mysql --datadir=/data/mysql/data


Installing MySQL system tables...2014-06-2716:02:45 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated.Please use --explicit_defaults_for_timestamp server option (see documentationfor more details).


2014-06-27 16:02:45 2134 [Note] InnoDB:Using atomics to ref count buffer pool pages


2014-06-27 16:02:45 2134 [Note] InnoDB: TheInnoDB memory heap is disabled


2014-06-27 16:02:45 2134 [Note] InnoDB:Mutexes and rw_locks use GCC atomic builtins


2014-06-27 16:02:45 2134 [Note] InnoDB:Compressed tables use zlib 1.2.3


2014-06-27 16:02:45 2134 [Note] InnoDB:Using Linux native AIO


2014-06-27 16:02:45 2134 [Note] InnoDB:Using CPU crc32 instructions


2014-06-27 16:02:45 2134 [Note] InnoDB:Initializing buffer pool, size = 128.0M


2014-06-27 16:02:45 2134 [Note] InnoDB:Completed initialization of buffer pool


2014-06-27 16:02:45 2134 [Note] InnoDB: Thefirst specified data file ./ibdata1 did not exist: a new database to becreated!


2014-06-27 16:02:45 2134 [Note] InnoDB:Setting file ./ibdata1 size to 12 MB


2014-06-27 16:02:45 2134 [Note] InnoDB:Database physically writes the file full: wait...


2014-06-27 16:02:45 2134 [Note] InnoDB:Setting log file ./ib_logfile101 size to 48 MB


2014-06-27 16:02:46 2134 [Note] InnoDB:Setting log file ./ib_logfile1 size to 48 MB


2014-06-27 16:02:46 2134 [Note] InnoDB:Renaming log file ./ib_logfile101 to ./ib_logfile0


2014-06-27 16:02:46 2134 [Warning] InnoDB:New log files created, LSN=45781


2014-06-27 16:02:46 2134 [Note] InnoDB:Doublewrite buffer not found: creating new


2014-06-27 16:02:46 2134 [Note] InnoDB:Doublewrite buffer created


2014-06-27 16:02:46 2134 [Note] InnoDB: 128rollback segment(s) are active.


2014-06-27 16:02:46 2134 [Warning] InnoDB:Creating foreign key constraint system tables.


2014-06-27 16:02:46 2134 [Note] InnoDB:Foreign key constraint system tables created


2014-06-27 16:02:46 2134 [Note] InnoDB:Creating tablespace and datafile system tables.


2014-06-27 16:02:46 2134 [Note] InnoDB:Tablespace and datafile system tables created.


2014-06-27 16:02:46 2134 [Note] InnoDB:Waiting for purge to start


2014-06-27 16:02:46 2134 [Note] InnoDB:5.6.19 started; log sequence number 0


2014-06-27 16:02:47 2134 [Note] Binlog end


2014-06-27 16:02:47 2134 [Note] InnoDB: FTSoptimize thread exiting.


2014-06-27 16:02:47 2134 [Note] InnoDB:Starting shutdown...


2014-06-27 16:02:48 2134 [Note] InnoDB:Shutdown completed; log sequence number 1625977


OK


 


Filling help tables...2014-06-27 16:02:48 0[Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use--explicit_defaults_for_timestamp server option (see documentation for moredetails).


2014-06-27 16:02:48 2157 [Note] InnoDB:Using atomics to ref count buffer pool pages


2014-06-27 16:02:48 2157 [Note] InnoDB: TheInnoDB memory heap is disabled


2014-06-27 16:02:48 2157 [Note] InnoDB:Mutexes and rw_locks use GCC atomic builtins


2014-06-27 16:02:48 2157 [Note] InnoDB:Compressed tables use zlib 1.2.3


2014-06-27 16:02:48 2157 [Note] InnoDB:Using Linux native AIO


2014-06-27 16:02:48 2157 [Note] InnoDB:Using CPU crc32 instructions


2014-06-27 16:02:48 2157 [Note] InnoDB:Initializing buffer pool, size = 128.0M


2014-06-27 16:02:48 2157 [Note] InnoDB:Completed initialization of buffer pool


2014-06-27 16:02:48 2157 [Note] InnoDB:Highest supported file format is Barracuda.


2014-06-27 16:02:48 2157 [Note] InnoDB: 128rollback segment(s) are active.


2014-06-27 16:02:48 2157 [Note] InnoDB:Waiting for purge to start


2014-06-27 16:02:48 2157 [Note] InnoDB:5.6.19 started; log sequence number 1625977


2014-06-27 16:02:48 2157 [Note] Binlog end


2014-06-27 16:02:48 2157 [Note] InnoDB: FTSoptimize thread exiting.


2014-06-27 16:02:48 2157 [Note] InnoDB: Startingshutdown...


2014-06-27 16:02:50 2157 [Note] InnoDB:Shutdown completed; log sequence number 1625987


OK


 


To start mysqld at boot time you have tocopy


support-files/mysql.server to the rightplace for your system


 


PLEASE REMEMBER TO SET A PASSWORD FOR THEMySQL root USER !


To do so, start the server, then issue thefollowing commands:


 


/data/mysql/bin/mysqladmin -u root password 'new-password'


/data/mysql/bin/mysqladmin -u root -h mymaster1.localdomain password'new-password'


 


Alternatively you can run:


 


/data/mysql/bin/mysql_secure_installation


 


which will also give you the option ofremoving the test


databases and anonymous user created bydefault. This is


strongly recommended for productionservers.


 


See the manual for more instructions.


 


You can start the MySQL daemon with:


 


cd. ; /data/mysql/bin/mysqld_safe &


 


You can test the MySQL daemon withmysql-test-run.pl


 


cdmysql-test ; perl mysql-test-run.pl


 


Please report any problems athttp://bugs.mysql.com/


 


The latest information about MySQL isavailable on the web at


 


http://www.mysql.com


 


Support MySQL by buying support/licenses athttp://shop.mysql.com


 


New default config file was created as/data/mysql/my.cnf and


will be used by default by the server whenyou start it.


You may edit this file to change serversettings


 


7. 修改相关目录权限,提高安全性:


[root@mymaster1 mysql]# chown -R root .


[root@mymaster1 mysql]# chown -R mysql data


 


8. 配置MySQL服务为主机服务,即能用service mysql start启动服务


[root@mymaster1 mysql]# cpsupport-files/mysql.server /etc/init.d/mysql


[root@mymaster1 mysql]# vi /etc/init.d/mysql


把下面的


basedir=


datadir=


修改为


basedir=/data/mysql


datadir=/data/mysql/data


 


9. 启动数据库


[root@mymaster1 mysql]# service mysql start


Starting MySQL[确定]


 


10. 修改数据库root密码


[root@mymaster1 mysql]#/data/mysql/bin/mysqladmin -u root password 'wengjixi'


[root@mymaster1 mysql]#/data/mysql/bin/mysqladmin -u root -h mymaster1.localdomain password 'wengjixi'


 


11. 修改环境变量,把mysql执行文件路径添加到环境变量中


[root@mymaster1 mysql]# vi /etc/profile


PATH=$PATH:/data/mysql/bin


export PATH


[root@mymaster1 mysql]# source /etc/profile


 


12. 测试登录


[root@mymaster1 mysql]# mysql -u root -p


Enter password:


Welcome to the MySQL monitor. Commands end with ; or g.


Your MySQL connection id is 5


Server version: 5.6.19 MySQL CommunityServer (GPL)


 


Copyright (c) 2000, 2014, Oracle and/or itsaffiliates. All rights reserved.


 


Oracle is a registered trademark of OracleCorporation and/or its


affiliates. Other names may be trademarksof their respective


owners.


 


Type 'help;' or 'h' for help. Type 'c' toclear the current input statement.


 


mysql>


 


mysql> show variables like '%data%';


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


| Variable_name | Value |


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


| character_set_database | latin1 |


| collation_database | latin1_swedish_ci |


| datadir | /data/mysql/data/


=====================================================================================================================


 mysql主从复制(超简单)
2012-02-27 15:31:02
标签:数据库 mysql 主从 休闲 slave
原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 、作者信息和本声明。否则将追究法律责任。http://369369.blog.51cto.com/319630/790921
mysql主从复制
(超简单)
怎么安装mysql数据库,这里不说了,只说它的主从复制,步骤如下:
1、主从服务器分别作以下操作:
  1.1、版本一致
  1.2、初始化表,并在后台启动mysql
  1.3、修改root的密码


2、修改主服务器master:
   #vi /etc/my.cnf
       [mysqld]
       log-bin=mysql-bin   //[必须]启用二进制日志
       server-id=222       //[必须]服务器唯一ID,默认是1,一般取IP最后一段


3、修改从服务器slave:
   #vi /etc/my.cnf
       [mysqld]
       log-bin=mysql-bin   //[必须]启用二进制日志
       server-id=226       //[必须]服务器唯一ID,默认是1,一般取IP最后一段


4、重启两台服务器的mysql
   /etc/init.d/mysql restart


5、在主服务器上建立帐户并授权slave:
   #/usr/local/mysql/bin/mysql -uroot -pmttang   
   mysql>GRANT REPLICATION SLAVE ON *.* to 'mysync'@'%' identified by 'q123456'; //一般不用root帐号,“%”表示所有客户端都可能连,只要帐号,密码正确,此处可用具体客户端IP代替,如192.168.145.226,加强安全。


6、登录主服务器的mysql,查询master的状态
   mysql>show master status;
   +------------------+----------+--------------+------------------+
   | File             | Position | Binlog_Do_DB | Binlog_Ignore_DB |
   +------------------+----------+--------------+------------------+
   | mysql-bin.000004 |      308 |              |                  |
   +------------------+----------+--------------+------------------+
   1 row in set (0.00 sec)
   注:执行完此步骤后不要再操作主服务器MYSQL,防止主服务器状态值变化


7、配置从服务器Slave:
   mysql>change master to aster_host='192.168.145.222',master_user='tb',master_password='q123456',
         master_log_file='mysql-bin.,000004',master_log_pos=308;   //注意不要断开,“308”无单引号。


   Mysql>start slave;    //启动从服务器复制功能


8、检查从服务器复制功能状态:


   mysql> show slave status\G


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


                Slave_IO_State: Waiting for master to send event


                   Master_Host: 192.168.2.222  //主服务器地址


                   Master_User: myrync         //授权帐户名,尽量避免使用root


                   Master_Port: 3306           //数据库端口,部分版本没有此行


                 Connect_Retry: 60


               Master_Log_File: mysql-bin.000004


           Read_Master_Log_Pos: 600        //#同步读取二进制日志的位置,大于等于>=Exec_Master_Log_Pos


                Relay_Log_File: ddte-relay-bin.000003


                 Relay_Log_Pos: 251


         Relay_Master_Log_File: mysql-bin.000004


              Slave_IO_Running: Yes       //此状态必须YES


             Slave_SQL_Running: Yes       //此状态必须YES
                    ......


注:Slave_IO及Slave_SQL进程必须正常运行,即YES状态,否则都是错误的状态(如:其中一个NO均属错误)。


以上操作过程,主从服务器配置完成。
  
9、主从服务器测试:


主服务器Mysql,建立数据库,并在这个库中建表插入一条数据:


  mysql> create database hi_db;
  Query OK, 1 row affected (0.00 sec)


  mysql> use hi_db;
  Database changed


  mysql>  create table hi_tb(id int(3),name char(10));
  Query OK, 0 rows affected (0.00 sec)
 
  mysql> insert into hi_tb values(001,'bobu');
  Query OK, 1 row affected (0.00 sec)


  mysql> show databases;
   +--------------------+
   | Database           |
   +--------------------+
   | information_schema |
   | hi_db              |
   | mysql              |
   | test               |
   +--------------------+
   4 rows in set (0.00 sec)


从服务器Mysql查询:


   mysql> show databases;


   +--------------------+
   | Database           |
   +--------------------+
   | information_schema |
   | hi_db              |          //I'M here,大家看到了吧
   | mysql              |
   | test               |
   +--------------------+
   4 rows in set (0.00 sec)


   mysql> use hi_db
   Database changed
   mysql> select * from hi_tb;    //可以看到在主服务器上新增的具体数据
   +------+------+
   | id   | name |
   +------+------+
   |    1 | bobu |
   +------+------+
   1 row in set (0.00 sec)
 
10、完成:
    编写一shell脚本,用nagios监控slave的两个“yes”,如发现只有一个或零个“yes”,就表明主从有问题了,发短信警报吧。


=======================================================
主从切换:
?1.?在B上执行grant replication slave on *.* to root@'IPOFA' identified by 'replpwd';
  2. 在A上执行 change master to  master_host='ip of B', master_user='repluser', master_password='replpwd', master_log_file='master-bin.000015', master_log_pos=621128950;
  3.?在A上执行 start slave;


=============================================================================
mysql master-master主主复制:


1、master上的/etc/my.cnf上添加:
character_set_server=utf8
skip-external-locking
key_buffer_size=16M
max_allowed_packet=1M
table_open_cache=64
sort_buffer_size=512k
net_buffer_length=8k
read_buffer_size=256k
read_rnd_buffer_size=512k


2、slave上的/etc/my.cnf上添加:
character_set_server=utf8
skip-external-locking
key_buffer_size=16M
max_allowed_packet=1M
table_open_cache=64
sort_buffer_size=512k
net_buffer_length=8k
read_buffer_size=256k
read_rnd_buffer_size=512k


3、然后在slave服务器上创建一个master同步slave的账号 grant replication slave on *.* to hua2@'%' identified by '123456' 
重启服务/etc/init.d/mysqld restart 
4、分别在两台服务器上show master status;  
5、在master上执行  change master to master_host='192.168.1.110', master_user='hua2', master_password='123456', master_log_file='mysql-bin.00000x', master_log_pos=xxx;
6、在slave上  change master to master_host='192.168.1.200', master_user='hua', master_password='123456', master_log_file='mysql-bin.00000x', master_log_pos=xxx; 
7、之后分别在两台服务器上show slave status\G
检查?


Slave_IO_Running:Yes?
Slave_SQL_Running:Yes
是否都为yes 
8、验证方法  分别在master  slave上执行更新 修改操作检查另一的表是否有变化。
===========================================================================================
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值