rpm包安装mysql6.5配置主从实战

本文详细介绍了如何在CentOS 6.5环境下,通过两台主机部署MySQL主从复制系统。首先,需要在两台主机上进行环境准备,包括关闭防火墙和SELinux。接着,通过YUM源安装MySQL,并配置数据目录和用户权限。随后,设置了开机启动并完成了初始化启动。此外,还演示了如何设置和修改root密码,以及创建用于复制的slave用户。最后,分别展示了master端和slave端的配置细节。

环境:centos6.5

两台主机:

一台master,

一台node

 

环境部署:关闭iptable 关闭selinux

关闭seliunx

[root@xie2 ~]# setenforce 0

[root@xie2 ~]# cat /etc/sysconfig/selinux

 

# This file controls the state of SELinux on the system.

# SELINUX= can take one of these three values:

# enforcing - SELinux security policy is enforced.

# permissive - SELinux prints warnings instead of enforcing.

# disabled - No SELinux policy is loaded.

SELINUX=disable

# SELINUXTYPE= can take one of these two values:

# targeted - Targeted processes are protected,

# mls - Multi Level Security protection.

SELINUXTYPE=targeted

 

一、检查系统是否安装其他版本的MYSQL数据

yum list installed | grep mysql

yum -y remove mysql-libs.x86_64

二、安装及配置

wget http://repo.mysql.com/mysql-community-release-el6-5.noarch.rpm

rpm -ivh mysql-community-release-el6-5.noarch.rpm

yum repolist all | grep mysql

1、安装MYSQL数据库

yum install mysql-community-server -y

 

设置用户,用户组

vim /etc/my.cnf

datadir=/usr/local/mysql

socket=/var/lib/mysql/mysql.sock

 

[root@xie1 ~]# chown -R mysql /usr/local/mysql/

[root@xie1 ~]# chgrp -R mysql /usr/local/mysql/

 

 

2、设置为开机启动

chkconfig --list | grep mysqld

chkconfig mysqld on

初始化启动:

/etc/init.d/mysqld start

 

3、设置密码

/usr/bin/mysqladmin -u root password '123456'

4、修改root密码

mysql -uroot -p123456

mysql> select Host,User,Password from user where User='root';

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

| Host                  | User | Password                                  |

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

| localhost             | root | *4A82FDF1D80BA7470BA2E17FEEFD5A53D5D3B762 |

| localhost.localdomain | root |                                           |

| 127.0.0.1             | root |                                           |

| ::1                   | root |                                           |

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

4 rows in set (0.00 sec)

mysql> update user set Password = password('123456') where User='root';

Query OK, 4 rows affected (0.03 sec)

Rows matched: 4  Changed: 4  Warnings: 0

mysql> select Host,User,Password from user where User='root';

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

| Host                  | User | Password                                  |

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

| localhost             | root | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |

| localhost.localdomain | root | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |

| 127.0.0.1             | root | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |

| ::1                   | root | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |

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

4 rows in set (0.00 sec)

mysql> flush privileges;

Query OK, 0 rows affected (0.00 sec)

 

1、使用空的初始密码登录mysql账号:

mysql-uroot -p

2、修改root密码:

mysql> update user set Password=password("123456") where User='root';

Query OK, 4 rows affected (0.01 sec)

Rows matched: 4 Changed: 4 Warnings: 0

mysql> flush privileges;

Query OK, 0 rows affected (0.04 sec)

mysql> select Host,User,password from user where user='root';

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

| Host | User | password |

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

| localhost | root | *5626ED34B75C6C508BA2A3D0A4F6E4C58823138C |

| localhost.localdomain | root | *5626ED34B75C6C508BA2A3D0A4F6E4C58823138C |

| 127.0.0.1 | root | *5626ED34B75C6C508BA2A3D0A4F6E4C58823138C |

| ::1 | root | *5626ED34B75C6C508BA2A3D0A4F6E4C58823138C |

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

4 rows in set (0.00 sec)

 

 

 

grant replication slave on *.* to 'tongbu'@'%' identified by '123456';

Query OK, 0 rows affected (0.00 sec)

 

master端配置:

[root@xie1 ~]# cat /etc/my.cnf
# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.6/en/server-configuration-defaults.html

[mysqld]
#
# 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=/usr/local/mysql
socket=/var/lib/mysql/mysql.sock
user=mysql
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
log-bin=mysql-bin  
server-id = 1 
innodb-file-per-table=ON
skip_name_resolve=ON
auto_increment_offset=1    
auto_increment_increment=2

# Recommended in standard MySQL setup
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES 

[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
 

Slave端配置:

[root@xie2 ~]# cat /etc/my.cnf
# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.6/en/server-configuration-defaults.html

[mysqld]
#
# 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=/usr/local/mysql
socket=/var/lib/mysql/mysql.sock

# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
user=mysql
server-id=2
log-bin=mysql-bin
innodb_file_per_table=ON
skip_name_resolve=ON
auto_increment_offset=2    
auto_increment_increment=2
# Recommended in standard MySQL setup
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES 

[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
 

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值