MySQL8.0安装详解

本文详细介绍了在CentOS7.4系统上安装MySQL8.0的过程,包括系统配置、磁盘分区设置、依赖包安装、参数配置及半同步复制的实现。涵盖了从环境准备到数据库初始化、用户权限设定、主从复制搭建等关键步骤。
摘要由CSDN通过智能技术生成

一、安装系统配置

到公有云上申请一个ECS,测试使用,规格可以随意,磁盘空间100G。

操作系统镜像:CentOS7.4

内核版本: 3.10.0-327.36.3.el7.x86_64

MySQL8.0各个安装包的用途。

Package name

用途

mysql-community-client

MySQL client applications and tools

mysql-community-common

common files for server and client libraries

mysql-community-devel

development header files and libraries for mysql   database client applications

mysql-community-embedded-compat

mysql server as an embedded library with compatibility   for applications using version 18 of the library

mysql-community-libs

shared libraries for mysql database client applications

mysql-community-libs-compat

shared compatibility libraries for previous mysql   installations

mysql-community-server

database server and related tools

mysql-community-test

test suite for the mysql server

 

需要到官网下载  https://dev.mysql.com/downloads/mysql/

 

mysql-8.0.14-1.el7.x86_64.rpm-bundle.tar

 

 

二、安装MySQL8.0

1. 准备工作

                a. 先创建分区

                                fdisk /dev/vdb

                                创建出两个分区,一个70G用于存在mysql数据,一个30G,用于放软件等资料。

                b. 格式化文件系统:

                                mkfs.ext4 /dev/vdb1

                                mkfs.ext4 /dev/vdb2

 

                c. 创建挂载点

                                mkdir -p /var/lib/mysql

                                mkdir -p /var/software

                                echo '/dev/vdb1 /var/lib/mysql ext4 rw,nosuid,nodev,exec,auto,nouser,async 0 0' >> /etc/fstab

                                echo '/dev/vdb2 /var/software ext4 rw,nosuid,nodev,exec,auto,nouser,async 0 0' >> /etc/fstab

                                mount -a

 

2. 上传Mysql安装包

                mysql-8.0.14-1.el7.x86_64.rpm-bundle.tar

               

3. 解压安装包和卸载冲突的安装包

                tar -xvf mysql-8.0.14-1.el7.x86_64.rpm-bundle.tar

 

4. 安装

                a. rpm -ivh mysql-community-common-8.0.14-1.el7.x86_64.rpm

b.卸载冲突包      

rpm -e mariadb-libs-5.5.56-2.el7.x86_64 --nodeps

                c. rpm -ivh mysql-community-libs-8.0.14-1.el7.x86_64.rpm

                d. rpm -ivh mysql-community-client-8.0.14-1.el7.x86_64.rpm

                e. rpm -ivh mysql-community-devel-8.0.14-1.el7.x86_64.rpm --nodeps

               

5. 创建用户和组

                groupadd mysql

useradd mysql -g mysql

 

6. 创建目录

                mkdir -p /var/lib/mysql/tmp

                chown mysql:mysql /var/lib/mysql/tmp

 

                mkdir -p /var/lib/mysql/data

                chown mysql:mysql /var/lib/mysql/data

                               

7. 配置参数文件

                vi /etc/my.cnf

                # The following options will be passed to all MySQL clients

[client]

#password = your_password

port = 3306

socket = /var/lib/mysql/data/mysql.sock

 

# The MySQL server

[mysqld]

port = 3306

socket = /var/lib/mysql/data/mysql.sock

datadir = /var/lib/mysql/data

skip-external-locking

default-storage-engine = INNODB

key_buffer_size = 256M

max_allowed_packet = 1G

table_open_cache = 4096

sort_buffer_size = 8M

read_buffer_size = 8M

read_rnd_buffer_size =32M

myisam_sort_buffer_size = 64M

thread_cache_size = 32

#query_cache_size= 16M  #unknown variable

#query_cache_type=0     #unknown variable

event_scheduler=1

skip-name-resolve

skip-slave-start

max_connections=2000

character_set_server=utf8

user=mysql

log-error = /var/lib/mysql/data/error.log

# Try number of CPU's*2 for thread_concurrency

#thread_concurrency = 8

lower_case_table_names = 1

join_buffer_size =2M

transaction_isolation=READ-COMMITTED

innodb_flush_method=O_DIRECT

#sql_mode=ANSI,TRADITIONAL,STRICT_ALL_TABLES

explicit_defaults_for_timestamp=false

local-infile=1

#skip-networking

#secure_auth = ON   # unknown variable

skip-symbolic-links

#sql_mode = NO_AUTO_CREATE_USER

log_bin_trust_function_creators =1

 

# Replication Master Server (default)

# binary logging is required for replication

log-bin=mysql-bin

log-bin-index=mysql-bin.index

slave_parallel_type=LOGICAL_CLOCK                             #for MTS

slave_parallel_workers=32

#open log_slow_queries sync_binlog 2011-9-24 xzlox

long_query_time = 10

slow-query-log = 1

log_output = file

sync_binlog=0

# binary logging format - row recommended

binlog_format=mixed

slave-skip-errors=all

relay-log=relay-bin

relay-log-index=relay-bin.index

 

expire_logs_days=1

 

# required unique id between 1 and 2^32 - 1

# defaults to 1 if master-host is not set

# but will not function as a master if omitted

server-id = 611

 

 

# Uncomment the following if you are using InnoDB tables

innodb_data_file_path = ibdata1:10M:autoextend

innodb_log_group_home_dir = /var/lib/mysql/data/

innodb_log_files_in_group = 5

# You can set .._buffer_pool_size up to 50 - 80 %

# of RAM but beware of setting memory usage too high

innodb_buffer_pool_size = 1000M

# Set .._log_file_size to 25 % of buffer pool size

innodb_log_file_size = 256M

innodb_log_buffer_size = 16M

innodb_flush_log_at_trx_commit = 1

innodb_lock_wait_timeout = 50

#replicate-do-db = ym

innodb_file_per_table

 

# GTID

log_slave_updates=1

gtid-mode=on

enforce-gtid-consistency=true

 

[mysqldump]

quick

max_allowed_packet = 16M

 

[mysql]

no-auto-rehash

# Remove the next comment character if you are not familiar with SQL

#safe-updates

 

[myisamchk]

key_buffer_size = 256M

sort_buffer_size = 128M

read_buffer = 2M

write_buffer = 2M

 

[mysqlhotcopy]

interactive-timeout

 

8. 安装server端

            安装依赖包:

            yum install perl

                rpm -ivh mysql-community-server-8.0.14-1.el7.x86_64.rpm

               

9. 关闭seLinux和防火墙 (有些操作系统需要这一步)

                setenforce 0

                并且/etc/selinux/config将enforcing设为disabled

 

                iptables -X

    iptables -F

 

10. 初始化数据并启动mysql

                mysqld --initialize --basedir=/usr/ --datadir=/var/lib/mysql/data --user=mysql

 

                /bin/systemctl start  mysqld.service

               

11. 找到临时密码

                cat /var/lib/mysql/data/error.log 

    ([Note] A temporary password is generated for root@localhost: iZ6BTu+&AXbh)

 

12. 修改密码

            set sql_log_bin=0;

 ALTER USER 'root'@'localhost' IDENTIFIED BY '******';

 flush privileges;

               

13. 停止mysql

                /bin/systemctl stop  mysqld.service

 

14. 连接数据库

                mysql -uroot -p -A

               

二、配置半同步

1. 查看是否支持动态加载,需要下面的变量设为YES

                mysql> show variables like 'have_dynamic_loading';

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

                | Variable_name        | Value |

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

                | have_dynamic_loading | YES   |

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

                1 row in set (0.01 sec)

               

2. 在主从库分别按照插件, 考虑到后面主从倒换,需要两边都安装

                主库:

                INSTALL PLUGIN rpl_semi_sync_master SONAME 'semisync_master.so';

 

                从库:

                INSTALL PLUGIN rpl_semi_sync_slave SONAME 'semisync_slave.so';

 

3. 查看是否正常

             mysql> SELECT PLUGIN_NAME, PLUGIN_STATUS FROM INFORMATION_SCHEMA.PLUGINS WHERE PLUGIN_NAME LIKE '%semi%';

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

                | PLUGIN_NAME          | PLUGIN_STATUS |

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

                | rpl_semi_sync_master | ACTIVE        |

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

                1 row in set (0.00 sec)

               

               

4. 建立主从同步

                a.  创建root账号和复制账号repl并赋权,主从库都执行

                                set sql_log_bin=0;

                                CREATE USER 'repl'@'%' IDENTIFIED BY '******';

                                GRANT REPLICATION SLAVE ON *.* TO 'repl'@'%';

 

                                create user root@'%' identified by '******';

                                grant all on *.* to root@'%';

                                flush privileges;

                               

                b. 获取主库的binlog

                                mysql> show master status\G

                                *************************** 1. row ***************************

                                                                                 File: mysql-bin.000008

                                                                 Position: 611

                                                 Binlog_Do_DB:

                                 Binlog_Ignore_DB:

                                Executed_Gtid_Set:

                                1 row in set (0.00 sec)

                               

                c. 建立主从关系

                                CHANGE MASTER TO

                                                MASTER_HOST='10.**.**.50',

                                                MASTER_PORT=3306,

                                                MASTER_USER='repl',

                                                MASTER_PASSWORD='******',

                                                MASTER_LOG_FILE='mysql-bin.000008',

                                                MASTER_LOG_POS=611,

                                                MASTER_AUTO_POSITION=0;

                                               

                                开通了gtid的话,用下面的方法:

                                CHANGE MASTER TO

                                                MASTER_HOST='10.**.**.50',

                                                MASTER_PORT=3306,

                                                MASTER_USER='repl',

                                                MASTER_PASSWORD='Gauss_234',

                                                MASTER_AUTO_POSITION=1;                                          

这个时候不要忘记在主库上将防火墙关闭;如果没有telnet可以用nc -v $IP 3306命令进行端口探测

                               

                d. 在主从库上添加相关变量

                                主库:

                                set global rpl_semi_sync_master_enabled=1;

                                set global rpl_semi_sync_master_timeout=1000;

                               

                               

                                从库:

                                set global rpl_semi_sync_slave_enabled=1;

                               

                                为了保证这些变量启动实例后生效,需要将他们放到配置文件中:

                                主库:

                                rpl_semi_sync_master_enabled=1

                                rpl_semi_sync_master_timeout=1000

                               

                                从库:

                                rpl_semi_sync_slave_enabled=1

rpl_semi_sync_master_timeout=1000

 

                               

                                另外:rpl_semi_sync_master_wait_point这个变量可以取值AFTER_SYNC(默认) 和 AFTER_COMMIT:这个值是采用老式的MySQL5.5/5.6半同步复制工作

                               

                                一个重点需要监控的状态变量为:Rpl_semi_sync_master_status, Rpl_semi_sync_slave_status

                                show status like 'Rpl_semi_sync_master_status';

                                show status like 'Rpl_semi_sync_slave_status';

 

5. 启动同步

start slave;

show slave status\G

购买华为云请点击立即购买

PL/SQL Developer 是一款集成开发环境,专门面向 Oracle 数据库存储程序单元的开发。 如今,有越来越多的业务逻辑和应用逻辑转向了Oracle Server,因此,PL/SQL编程也成了整个开发过程的一个重要组成部分。 PL/SQL Developer侧重于易用性、代码品质和生产率,以及 Oracle 应用程序开发过程中的重大优势。 报告 ——PL/SQL Developer提供内置的报告功能,您可以根据程序数据或Oracle字典运行报告。PL/SQL Developer本身提供了大量标准报告,而且您还可以方便的创建自定义报告。自定义报告将被保存在报告文件中,进而包含在报告菜单内。这样,运行您自己经常使用的自定义报告就非常方便。您可以使用Query Reporter免费软件工具来运行您的报告,不需要PL/SQL Developer,直接从命令行运行即可。 工程 ——PL/SQL Developer内置的工程概念可以用来组织您的工作。一个工程包括源文件集合、数据库对象、notes和选项。PL/SQL Developer允许您在某些特定的条目集合范围之内进行工作,而不是在完全的数据库或架构之内。这样,如果需要编译所有工程条目或者将工程从某个位置或数据库移动到其他位置时,所需工程条目的查找就变得比较简单, To-Do条目 ——您可以在任何SQL或PL/SQL源文件中使用To-Do条目快速记录该文件中那些需要进行的事项。以后能够从To-Do列表中访问这些信息,访问操作可以在对象层或工程层进行。 对象浏览器 ——可配置的树形浏览能够显示同PL/SQL开发相关的全部信息,使用该浏览器可以获取对象描述、浏览对象定义、创建测试脚本以便调试、使能或禁止触发器或约束条件、重新编译不合法对象、查询或编辑表格、浏览数据、在对象源中进行文本查找、拖放对象名到编辑器等。此外,该对象浏览器还可以显示对象之间的依存关系,您可以递归的扩展这些依存对象(如包参考检查、浏览参考表格、图表类型等)。 性能优化 ——使用PL/SQL Profiler,可以浏览每一执行的PL/SQL代码行的时序信息(Oracle8i或更高),从而优化您SQL和PL/SQL的代码性能。更进一步,您还可以自动获取所执行的SQL语句和PL/SQL程序统计信息。该统计信息包括CPU使用情况、块I/O、记录I/O、表格扫描、分类等。 HTML指南 ——Oracle目前支持HTML格式的在线指南。您可以将其集成到PL/SQL Developer工作环境中,以便在编辑、编译出错或运行时出错时提供内容敏感帮助。 非PL/SQL对象 ——不使用任何SQL,您就可以对表格、序列、符号、库、目录、工作、队列、用户和角色进行浏览、创建和修改行为。PL/SQL Developer提供了一个简单易用的窗体,只要将信息输入其中,PL/SQL Developer就将生成相应的SQL,从而创建或转换对象。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值