Linux下Mysql5.6 二进制安装过程
时间:2021-06-28 08:23:54|栏目:Mysql|点击: 次
1.1下载二进制安装包
wget https://dev.mysql.com/get/Downloads/MySQL-5.6/mysql-5.6.40-linux-glibc2.12-x86_64.tar.gz
1.2创建 mysql用户与组
groupadd -r -g 306 mysql useradd -r -g 306 -u 306 -m -s /sbin/nologin mysql
1.3解压
tar xf mysql-5.6.40-linux-glibc2.12-x86_64.tar.gz -C /usr/local
1.4创建mysql软连接
cd /usr/local ln -s mysql-5.6.40-linux-glibc2.12-x86_64 mysql
1.5修改所属主,所属组权限
chown -R mysql.mysql /usr/local/mysql-5.6.40-linux-glibc2.12-x86_64 chown mysql.mysql /usr/local/mysql
1.6创建目录,修改mysql目录的所属主
mkdir -p /data/mysql{,_binlog} chown -R mysql.mysql /data/mysql chown -R mysql.mysql /data/mysql_binlog
1.7创建配置文件目录
mkdir /etc/mysql/ cp /usr/local/mysql/support-files/my-default.cnf /etc/mysql/my.cnf
1.8配置文件 vim /etc/mysql/my.cnf
[client] port = 3306 socket = /data/mysql/mysql.sock [mysqld] port = 3306 user = mysql basedir = /usr/local/mysql datadir = /data/mysql socket = /data/mysql/mysql.sock pid-file = /data/mysql/mysql.pid log-error = /data/mysql/mysql_error.log character-set-server = utf8 init_connect='SET NAMES utf8' innodb_log_file_size = 256M innodb_file_format = barracuda innodb_strict_mode = 0 innodb_file_per_table = on #跳过主机名解析 skip-name-resolve #服务器ID,集群必填配置,区分机器编号,每台机器不同 server_id = 1 #开启二进制日志,行级记录,同步写入磁盘 log_bin = /data/mysql_binlog/mysql-bin binlog_format = row sync_binlog = 1 sql_mode='STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION' symbolic-links=0
1.9修改PATH环境变量
]# vim /etc/profile.d/mysql.sh PATH=/usr/local/mysql/bin:$PATH ]# source /etc/profile.d/mysql.sh
2.0创建数据库文件
cd /usr/local/mysql/ ./scripts/mysql_install_db --datadir=/data/mysql --user=mysql
2.1准备启动脚本
cd /usr/local/mysql/ ./scripts/mysql_install_db --datadir=/data/mysql --user=mysql
2.2安全初始化
ln -s /data/mysql/mysql.sock /tmp/mysql.sock mysql_secure_installation root没有密码 --> 直接回车 --> 是否设置密码 Y 输入密码 --> 是否删除匿名用户 Y --> 是否禁止root远程连接 N --> 是否删除test测试数据库 Y --> 是否重新载入数据库 Y ---> OK
2.3主从复制架构
2.3.1配置文件
master 主数据库
log_bin=/bin_log_PATH/mysql-bin 开启二进制日志 binlog_format = row 二进制日志记录方式,行级记录 server_id = 1
2.3.2创建主从复制专用权限用户
mysql> grant replication salve on *.* to 'repluer'@'172.16.1.%' identified by '123456'
2.3.3刷新二进制日志
mysql> reset master; mysql> show master status;
2.3.3 slave 从数据库配置文件
server_id=2
2.4建立主从关联
mysql> change master to master_host='172.16.1.211', master_user='repluser',master_password='123456', master_log_file='mysql-bin.000001',master_log_pos=120;
2.4.1查看与启用从节点
mysql> start slave; mysql> show slave status\G
说明:主从复制架构,是多从同步一台主的数据,可能造成主节点压力大,可以使用主从级联复制,主节点负责一台从节点,从节点再负责下一台从节点
主要用到配置
从节点 配置 log_bin 二进制日志记录配置
log_slave_updates 将同步过来的数据,写入二进制日志,方便下一台从节点同步
总结