centos 7.4 二进制搭建mysql5.7 主从
2021/6/19 19:28:33
本文主要是介绍centos 7.4 二进制搭建mysql5.7 主从,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
一、mysql 主 安装
1、基础环境准备
1、关闭防火墙、SELINUX
systemctl stop firewalld;
systemctl disable firewalld;
setenforce 0
2、建立mysql用户与相关目录
groupadd mysql;
useradd -r -g mysql -s /sbin/nologin mysql;
mkdir -p /data/mysql/data && mkdir -p /usr/local/mysql && mkdir -p /data/services
3、下载解压安装包
cd /data/services
wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.28-linux-glibc2.12-x86_64.tar.gz
tar -xvf mysql-5.7.28-linux-glibc2.12-x86_64.tar.gz -C /data/services
cp -rp /data/services/mysql-5.7.28-linux-glibc2.12-x86_64/* /usr/local/mysql/
4、初始化
// 递归授权数据库的文件目录和数据目录
chown -R mysql:mysql /data/mysql/
chown -R mysql:mysql /usr/local/mysql/
// 初始化data目录及创建基础表
/usr/local/mysql/bin/mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql/data # 初始时指定mysql的运行用户,基础目录和数据目录,出现空密码表示成功
2021-06-19T07:12:37.007172Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
100 200 300 400 500 600 700 800 900 1000 1100 1200 1300 1400 1500 1600 1700 1800 1900 2000
100 200 300 400 500 600 700 800 900 1000 1100 1200 1300 1400 1500 1600 1700 1800 1900 2000
2021-06-19T07:13:03.320390Z 0 [Warning] InnoDB: New log files created, LSN=45790
2021-06-19T07:13:03.356342Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2021-06-19T07:13:03.418233Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: c99af971-d0cd-11eb-8287-000c29785bce.
2021-06-19T07:13:03.418885Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2021-06-19T07:13:05.139058Z 0 [Warning] CA certificate ca.pem is self signed.
2021-06-19T07:13:05.519129Z 1 [Warning] root@localhost is created with an empty password ! Please consider switching off the --initialize-insecure option.
5、开始配置my.cnf
#vim /etc/my.cnf
复制下方内容到my.cnf,保存退出
[client]
default-character-set=utf8mb4
[mysql]
default-character-set=utf8mb4
socket=/data/mysql/data/mysql.sock
[mysqld]
server-id=1
binlog_format=row
log-bin=/data/mysql/data/mysqlmaster-bin
skip-name-resolve
port=3306
pid-file=/data/mysql/data/mysql.pid
socket=/data/mysql/data/mysql.sock
log-error=/data/mysql/data/log-error.log
basedir=/usr/local/mysql
datadir=/data/mysql/data
max_connections=10000
character-set-server=utf8mb4
init_connect='SET NAMES utf8mb4'
default-storage-engine=INNODB
lower_case_table_names=1
max_allowed_packet=32M
slow-query-log=1
slow-query-log-file=/data/mysql/data/slowquery.log
log_bin_trust_function_creators=1
max_connect_errors=10000
long_query_time=1
interactive_timeout=604800
wait_timeout=604800
innodb_buffer_pool_size=64G
innodb_log_file_size=2G
tmp_table_size=2000M
max_heap_table_size=2000M
max_tmp_tables=300
open_files_limit=65535
max_prepared_stmt_count=1048576
innodb_write_io_threads=8
innodb_read_io_threads=8
innodb_io_capacity=2000
innodb_flush_method=O_DIRECT
innodb_max_dirty_pages_pct=50
innodb_flush_neighbors=0
event_scheduler=1
6、配置环境变量
# vim /etc/profile
添加下面两个值
export MYSQL_HOME="/usr/local/mysql"
export PATH="$PATH:$MYSQL_HOME/bin"
立即生效
# source /etc/profile
7、添加mysql启动服务
cp -rp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
chkconfig --add mysqld
chkconfig mysqld on
sed -i '/^basedir=/cbasedir=\/usr\/local\/mysql' /etc/init.d/mysqld
sed -i '/^datadir=/cdatadir=\/data\/mysql\/data' /etc/init.d/mysqld
8、启动mysql服务
方法一
# service mysqld start
方法二
#systemctl start mysqld
这篇关于centos 7.4 二进制搭建mysql5.7 主从的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-11-16MySQL资料:新手入门教程
- 2024-11-16MySQL资料:新手入门教程
- 2024-11-15MySQL教程:初学者必备的MySQL数据库入门指南
- 2024-11-15MySQL教程:初学者必看的MySQL入门指南
- 2024-11-04部署MySQL集群项目实战:新手入门教程
- 2024-11-04如何部署MySQL集群资料:新手入门指南
- 2024-11-02MySQL集群项目实战:新手入门指南
- 2024-11-02初学者指南:部署MySQL集群资料
- 2024-11-01部署MySQL集群教程:新手入门指南
- 2024-11-01如何部署MySQL集群:新手入门教程