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

9、设置新密码

// 设置本地套接字

ln /data/mysql/data/mysql.sock /tmp/mysql.sock

# mysqladmin -u root password

New password:
Confirm new password:

10、连接到mysql

# mysql -u root -p
Enter password:
mysql>

// 此处设置的密码是本机localhost的root的密码

11、为root用户添加远程连接权限

mysql>use mysql;
mysql>desc user;
mysql> GRANT ALL PRIVILEGES ON *.* TO root@"%" IDENTIFIED BY "123456"; //为root添加远程连接的能力。
mysql>flush privileges;
mysql>exit

// 此处授权的是root % 的密码

posted on 2021-06-19 15:52  耿耿~  阅读(43)  评论(0编辑  收藏  举报

导航