生产环境下_MySQL企业版5.7.30如何进行单实例部署

文档说明:

本文将详细描述MySQL企业版5.7.30的二进制TAR包安装步骤;此文档对生产环境的单库部署有借鉴意义;

MySQL8.0版本安装步骤,等同于此步骤。

 

测试服务器IP为:

192.168.0.42

操作系统:

[root@MySQL-test03 MySQL]# cat /etc/redhat-release

Red Hat Enterprise Linux Server release 7.3 (Maipo)

 

MySQL服务器安装版本

5.7.30-enterprise-commercial

 

注意:

我这里是安装的企业版,没有MySQL的CSI号的亲可以下载社区版,官网发布的MySQL Server的企业版和社区版没有区别,区别主要在于一些企业版工具和技术支持,

 

社区版MySQL server下载安装二进制安装包:

https://dev.mysql.com/downloads/mysql/

 

MySQL软件位置:

/MySQL/mysqlsoft

MySQL数据、日志位置:

/MySQL/mysqlsoft

 

一、 操作系统设置:

1. vi /etc/default/grub

GRUB_CMDLINE_LINUX="crashkernel=auto rd.lvm.lv=rhel/root rd.lvm.lv=rhel/swap rhgb quiet numa=off"

 

2. vi /etc/security/limits.conf

mysql   soft    nproc   65535

mysql   hard    nproc   65535

mysql   soft    nofile  65536

mysql   hard    nofile  65536

 

二、 MySQL安装过程:

[root@MySQL-test03 mysqlsoft]# date

Sat Jun 20 00:48:22 CST 2020

[root@MySQL-test03 mysqlsoft]# ll

total 1509184

-rw-r--r-- 1 root  root  772691699 Mar 23 18:46 mysql-advanced-5.7.30-el7-x86_64.tar.gz

-rw-rw-r-- 1 mysql mysql 772701798 May  6 11:18 V995946-01MySQL Database 5.7.30 TAR for Oracle Linux _ RHEL 7 x86 (64bit).zip

 

1. 创建用户

[root@calt-db01 mysqlsoft]# groupadd mysql[root@calt-db01 mysqlsoft]# useradd -g mysql  -s  /sbin/nologin -d /usr/local/mysql/  -M mysql

2. 创建必须的目录

[root@calt-db01 mysqlsoft]#mkdir -p /MySQL/mysqldata/3306/{data,tmp,log}

[root@calt-db01 mysqlsoft]#chown -R mysql:mysql data tmp log

 

3. 解压tar安装文件

[root@MySQL-test03 mysqlsoft]# tar xvf mysql-advanced-5.7.30-el7-x86_64.tar.gz

[root@MySQL-test03 mysqlsoft]# rm -rf V995946-01MySQL\ Database\ 5.7.30\ TAR\ for\ Oracle\ Linux\ _\ RHEL\ 7\ x86\ \(64bit\).zip

[root@MySQL-test03 MySQL]# chown -R mysql:mysql /MySQL/mysqldata

[root@MySQL-test03 MySQL]# chown -R mysql:mysql /MySQL/mysqlsoft

 

4. 设置软连接

[root@MySQL-test03 mysqlsoft]# ln -s /MySQL/mysqlsoft/mysql-advanced-5.7.30-el7-x86_64 /usr/local/mysql

 

5. 环境变量

[root@calt-db01 mysqlsoft]# echo PATH=$PATH:/usr/local/mysql/bin >>/etc/profile

[root@calt-db01 mysqlsoft]# source /etc/profile

 

6. my.cnf配置文件(部署从库需要修改server_id,rpl开头参数为半同步设置,从库不需要添加)

[client]
socket=/MySQL/mysqldata/3306/tmp/mysql.sock

[mysql]
prompt="\u@db1 \R:\m:\s [\d]> "
no-auto-rehash

[mysqld]
basedir=/usr/local/mysql
socket=/MySQL/mysqldata/3306/tmp/mysql.sock
user=mysql
port=3306

log_timestamps=SYSTEM

datadir=/MySQL/mysqldata/3306/data/
default-storage-engine=innodb
character_set_server = utf8mb4
pid-file=/MySQL/mysqldata/3306/tmp/mysql.pid
log-error=/MySQL/mysqldata/3306/log/mysql-error.log
log-bin=/MySQL/mysqldata/3306/mysql-bin
long_query_time=2
slow_query_log =1
slow_query_log_file=/MySQL/mysqldata/3306/log/slow.log
federated
server-id=423306
binlog_format=row
binlog_cache_size=64M
max_binlog_cache_size=4048M
expire_logs_days=15
sync_binlog=1
lower_case_table_names=1
key_buffer_size=1024M
sort_buffer_size=2M
read_buffer_size=2M
join_buffer_size=2M
read_rnd_buffer_size=4M
thread_cache_size=128
query_cache_size=0
query_cache_type=0
master_info_repository=table
relay_log_info_repository=table
sync_master_info = 1
sync_relay_log_info  = 1
#read_only = 1
relay_log_recovery = 1
log_slave_updates = 1 

table_open_cache=512
open_files_limit=10240
back_log=256
max_connections=1000
max_connect_errors=10000

max_allowed_packet=1G
thread_stack=192k
tmp_table_size=512M
max_heap_table_size=512M

skip-name-resolve
skip_external_locking
innodb_buffer_pool_size=10240M
innodb_data_file_path=ibdata1:128M:autoextend
innodb_read_io_threads=16
innodb_write_io_threads=16
innodb_io_capacity = 600
innodb_thread_concurrency=32

innodb_flush_log_at_trx_commit=1
innodb_log_buffer_size=32M
innodb_log_file_size=1024M
innodb_log_files_in_group=3
innodb_max_dirty_pages_pct=80
innodb_lock_wait_timeout=60
innodb_file_per_table=1

#gtid_mode = on
#enforce_gtid_consistency = 1

#########SEMI SYNC#####################
#rpl_semi_sync_master_enabled = on
#rpl_semi_sync_slave_enabled=on
#rpl_semi_sync_master_timeout = 3000

symbolic-links=0

[mysqld_safe]
log-error=/MySQL/mysqldata/3306/log/mysql-error.log
pid-file=/MySQL/mysqldata/3306/tmp/mysql.pid

#for master_standby_trigger
log_bin_trust_function_creators=1

 

7. mysql初始化

[root@MySQL-test03 3306]# /usr/local/mysql/bin/mysqld --defaults-file=/etc/my.cnf --initialize --user=mysql

[1] 24752

 

8. 启动MySQL进程

[root@MySQL-test03 3306]# /etc/init.d/mysqld start

[root@MySQL-test03 3306]# /usr/local/mysql/bin/mysqld_safe --defaults-file=/etc/my.cnf --user=mysql &

 

推荐:第二种方式启动MySQL进程。

 

9. 修改密码

[root2@MySQL-test03 3306]# mysqladmin -uroot -p password 'MySQL_root_869#'

Enter password:       --此处查看error.log,初始数据库时会默认生成一个临时密码

mysqladmin: [Warning] Using a password on the command line interface can be insecure.

Warning: Since password will be sent to server in plain text, use ssl connection to ensure password safety.

 

10. 设置开机自启动

[root@MySQL-test03 init.d]# chkconfig --add mysqld

[root@MySQL-test03 init.d]# chkconfig --list

 

Note: This output shows SysV services only and does not include native

      systemd services. SysV configuration data might be overridden by native

      systemd configuration.

 

      If you want to list systemd services use 'systemctl list-unit-files'.

      To see services enabled on particular target use

      'systemctl list-dependencies [target]'.

 

mysqld          0:off   1:off   2:on    3:on    4:on    5:on    6:off

netconsole      0:off   1:off   2:off   3:off   4:off   5:off   6:off

network         0:off   1:off   2:on    3:on    4:on    5:on    6:off

rhnsd           0:off   1:off   2:on    3:on    4:on    5:on    6:off

vmware-tools    0:off   1:off   2:on    3:on    4:on    5:on    6:off

 

11. 创建应用账号

[root@MySQL-test03 init.d]# mysql -uroot -pMySQL_root_869#

mysql: [Warning] Using a password on the command line interface can be insecure.

Welcome to the MySQL monitor.  Commands end with ; or \g.

Your MySQL connection id is 4

Server version: 5.7.30-enterprise-commercial-advanced-log MySQL Enterprise Server - Advanced Edition (Commercial)

 

Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.

 

Oracle is a registered trademark of Oracle Corporation and/or its

affiliates. Other names may be trademarks of their respective

owners.

 

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

 

12. 创建应用账号(使用此账号进行库访问,避免使用root字样)

1)创建业务数据库

root@db1 17:53:  [(none)]> create database MySQLdb;

Query OK, 1 row affected (0.00 sec)

 

root@db1 18:01:  [(none)]> show create database MySQLdb;

+----------+-------------------------------------------------------------------+

| Database | Create Database                                                   |

+----------+-------------------------------------------------------------------+

| MySQLdb    | CREATE DATABASE `MySQLdb` /*!40100 DEFAULT CHARACTER SET utf8mb4 */ |

+----------+-------------------------------------------------------------------+

1 row in set (0.00 sec)

 

2)创建应用账号:

root@db1 00:30:  [(none)]> grant all privileges on MySQLdb.* to 'MySQL_admin'@'%' identified by 'MySQL_admin_869#';

Query OK, 0 rows affected, 1 warning (0.00 sec)

 

root@db1 00:30:  [(none)]> flush privileges;

Query OK, 0 rows affected (0.00 sec)

 

【总结】

  1. 本文详细讲述了MySQL的每一步安装步骤;对生产环境的单库安装有借鉴意义;
  2. 尤其是/etc/my.cnf初始参数部分有生产借鉴意义;
  3. MySQL的本地管理账号为root@localhost,如果想通过navicate远程管控MySQL,请建立root@%账号;
  4. 应用账号app_user@%请先使用create database app_DB建里专属database,再将all privileges on app_DB.*的权限赋予app_user@%。

 

以下为个人公众号“一森咖记”,欢迎关注。

猜你喜欢

转载自blog.csdn.net/db_murphy/article/details/106924177