环境: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