安装环境:centos6.9
1、安装MySQL
yum在线安装
1、 查看是否安装了mysql数据库:
rpm -qa | grep mysql
2、 强制卸载mysql数据库:
rpm -e nodeps mysql
3、 通过命令查看yum上提供的数据库可下载版本:
yum list | grep mysql
4、安装数据库:
yum -y install mysql-server mysql-devel
5、启动数据库: service mysqld start
6、停止数据库
service mysqld stop
8、查看是否是开机启动(若2~5都是on则表明是开机启动):
chkconfig --list | grep mysqld
9、若2~5都是off则用以下命令设置:
chkconfig mysqld on
10、 chkconfig --list | grep mysqld
11、启动mysql: service mysqld start
12、设置用户及密码(输入以下命令后两次回车,及第一次密码直接回车即可):
mysqladmin -u root -p password 'root'
13、测试登录mysql: mysql -u root -p
14、如若远程需要进行授权操作:
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456' WITH GRANT OPTION;
FLUSH PRIVILEGES;
grant all privileges on *.* to root@"hadoop01" identified by "123456" with grant option;
FLUSH PRIVILEGES;
15、查看数据库的配置文件: cat /etc/my.cnf
(其中的datadir是MySQL数据库的存放路径,表示数据在CentOS里的/var/lib/mysql目录下)
16、进入mysql安装路径查看: cd /var/lib/mysql
17、停止mysql服务: service mysqld stop
2、配置防火墙
service iptables stop
iptables -A INPUT -p tcp -m state --state NEW -m tcp --dport 3306 -j ACCEPT
service iptables save
service iptables start
3、配置MySQL 主-主同步
主主同步事实上就是在主从的基础上,将原先的从机当主机,主机当从机再配置一遍主从同步
1. 在数据库1的my.cnf的mysqld节点添加以下配置
[root@localhost ~]# cat /etc/my.cnf
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
user=mysql
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
wait_timeout = 343232
max_connections=2000
default-character-set=utf8
default-storage-engine=INNODB
sql_mode='STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION'
############################################
######Active-Active Redundancy
server_id=1
log-bin=mysql-bin
auto_increment_increment=2
auto_increment_offset=1
binlog-ignore=mysql
binlog-ignore=information_schema
binlog-ignore=performance_schema
character_set_server=utf8
log-bin-trust-function-creators=1
###########################################
skip_ssl
# disable_ssl
[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
2 、在数据库2的my.cnf的mysqld节点添加以下配置
[root@localhost ~]# cat /etc/my.cnf
[mysql]
default-character-set=utf8
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
user=mysql
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
wait_timeout = 343232
max_connections=2000
default-character-set=utf8
default-storage-engine=INNODB
sql_mode='STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION'
############################################
######Active-Active Redundancy
server_id=2
log-bin=mysql-bin
auto_increment_increment=2