zoukankan      html  css  js  c++  java
  • Linux(CentOS) Mysql 8.0.23 安装(多源安装)

    Linux(CentOS) Mysql 8.0.23 安装(多源安装)


    安装命令根据实际部署情况修改调整,CentOS一般选择通用版本Red Hat Enterprise Linux 7
    本文档使用wget下载,也可以自主下载上传到服务器,非YUM安装方式
    版本地址:全版本 | Red Hat Enterprise Linux 7 / Oracle Linux 7 (x86, 64-bit)版本
    文档更新记录:2021/03/15-MySQL Community Server最新版本号:8.0.23


    1.0 CentOS7配置阿里云yum源 ,根据实际情况判断是否需要配置

    1.1 在安装MySQL之前,需要卸载服务器自带的MySQL包和MySQL数据库分支mariadb的包

    $ rpm -qa|grep mysql
    $ rpm -qa |grep mariadb
    mariadb-libs-5.5.65-1.el7.x86_64
    $ rpm -e mariadb-libs-5.5.65-1.el7.x86_64 --nodeps
    

    1.2 下载(此处下载到/home目录下)

    $ wget -P /home https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-8.0.23-el7-x86_64.tar   
    #备注:该包下面有3个子包,此文档主要介绍mysql-8.0.23-el7-x86_64.tar.gz和mysql-router-8.0.23-el7-x86_64.tar.gz  
        1、mysql-8.0.23-el7-x86_64.tar.gz           # MySQL主包,此文档使用的包  
        2、mysql-router-8.0.23-el7-x86_64.tar.gz    # 用于在应用程序和MySQL服务器之间提供透明路由和负载均衡,从而有效提高MySQL数据库服务的高可用性与可伸缩行,此处不介绍   
        3、mysql-test-8.0.23-el7-x86_64.tar.gz      # 测试包    
    

    1.3 多实例安装举例(此处安装2个实例,从7001~7002)

    $ groupadd mysql
    $ useradd -r -g mysql -s /bin/false mysql
    $ yum install libaio -y
    $ cd /home
    $ tar -xf mysql-8.0.23-el7-x86_64.tar 
    $ tar -zxvf mysql-8.0.23-el7-x86_64.tar.gz  
    $ mv mysql-8.0.23-el7-x86_64 /home/mysql    
    $ mkdir -p /home/mysql/data/{7001,7002}  
    $ chown -R mysql:mysql /home/mysql  
    $ cd /home/mysql    
    

    1.3 多实例安装举例(此处安装2个实例,从7001~7002,已开启binlog,如果不是用来设置主从的话步长和起始位置设置为1就行,配置7003请忽略,用来做2主1从的配置)

    $ vim /etc/my.cnf   
    
    [mysqld]
    user=mysql
    basedir=/home/mysql
    #禁止反解析IP(提高速度)
    skip-name-resolve
    
    [mysqld_multi]
    mysqld=/home/mysql/bin/mysqld_safe
    mysqladmin=/home/mysql/bin/mysqladmin
    log=/home/mysql/data/mysqld_multi.log
    
    [mysqld7001]
    mysqld=mysqld
    mysqladmin=mysqladmin
    datadir=/home/mysql/data/7001
    port=7001
    server_id=7001
    socket=/tmp/mysql_7001.sock
    log_error=/home/mysql/data/error_7001.log
    
    #开启binlog
    log_bin=mysql_bin
    binlog_format=ROW
    lower_case_table_names=1
    log_slave_updates=true
    gtid_mode=on
    enforce_gtid_consistency=1
    #不同步的表(当前_其他)
    binlog_ignore_db=mysql
    binlog_ignore_db=information_schema
    binlog_ignore_db=performance_schema
    #屏蔽同步(其他_>当前)
    replicate_ignore_db=mysql
    replicate_ignore_db=information_schema
    replicate_ignore_db=performance_schema
    
    #自增起始位置
    auto_increment_offset=1
    #自增步长
    auto_increment_increment=1
    
    [mysqld7002]
    mysqld=mysqld
    mysqladmin=mysqladmin
    datadir=/home/mysql/data/7002
    port=7002
    server_id=7002
    socket=/tmp/mysql_7002.sock
    log_error=/home/mysql/data/error_7002.log
    
    #开启binlog
    log_bin=mysql_bin
    binlog_format=ROW
    lower_case_table_names=1
    log_slave_updates=true
    gtid_mode=on
    enforce_gtid_consistency=1
    #不同步的表(当前_其他)
    binlog_ignore_db=mysql
    binlog_ignore_db=information_schema
    binlog_ignore_db=performance_schema
    #屏蔽同步(其他_>当前)
    replicate_ignore_db=mysql
    replicate_ignore_db=information_schema
    replicate_ignore_db=performance_schema
    
    #自增起始位置
    auto_increment_offset=1
    #自增步长
    auto_increment_increment=1
    
    # [mysqld7003]
    # mysqld=mysqld
    # mysqladmin=mysqladmin
    # datadir=/home/mysql/data/7003
    # port=7003
    # server_id=7003
    # socket=/tmp/mysql_7003.sock
    # log_error=/home/mysql/error_7003.log
    
    # #开启binlog
    # log_bin=mysql_bin
    # binlog_format=ROW
    # lower_case_table_names=1
    # log_slave_updates=true
    # gtid_mode=on
    # enforce_gtid_consistency=1
    # #不同步的表(当前_其他)
    # binlog_ignore_db=mysql
    # binlog_ignore_db=information_schema
    # binlog_ignore_db=performance_schema
    # #屏蔽同步(其他_>当前)
    # replicate_ignore_db=mysql
    # replicate_ignore_db=information_schema
    # replicate_ignore_db=performance_schema
    
    # #只读
    # read_only=1
    # innodb_read_only=1
    # #super_read_only=1
    

    1.3 初始化多实例(此处要初始化2个实例,从7001~7002,忽略大小写一定要在初始化就加入,并记录下原始密码!!!记录下原始密码!!!记录下原始密码!!!,后面改密前登录使用)

    /home/mysql/bin/mysqld --defaults-file=/etc/my.cnf --initialize --lower-case-table-names=1 --basedir=/home/mysql/ --datadir=/home/mysql/data/7001
    /home/mysql/bin/mysqld --defaults-file=/etc/my.cnf --initialize --lower-case-table-names=1 --basedir=/home/mysql/ --datadir=/home/mysql/data/7002
    

    1.3 设置环境变量(用于系统识别mysqld_multi、mysqladmin等命令)

    $ vim /etc/profile  
    export PATH=/home/mysql/bin:$PATH   
    $ source /etc/profile   
    

    1.5 使用mysqld_multi启动单个实例举例(7001端口),其他端口类似

    $ mysqld_multi start 7001
    

    1.6 使用mysqld_multi启动全部实例

    $ mysqld_multi start    
    

    1.7 [推荐] 关闭单个数据库实例命令(举例7001)

    $ mysqladmin -S /tmp/mysql_7001.sock -p shutdown    
    #备注:不推荐使用mysqld_multi关闭多实例,因为麻烦,需要在my.cnf文件的[mysqld_multi]模块里面配置用户密码,并且各个数据库的用户密码都需要相同,否则无法关闭 
    

    1.8 推荐使用socket登录MySQL(举例7001)

    $ mysql -S /tmp/mysql_7001.sock -p 
    

    1.9 使用mysqld_multi查看实例状态

    $ mysqld_multi report
    Reporting MySQL servers
    MySQL server from group: mysqld7001 is running  
    MySQL server from group: mysqld7002 is running  
    

    1.10 首次登录(举例7001)必须重新设置密码才能正常使用,此处使用

    $ mysql -S /tmp/mysql_7001.sock -p  
    # 修改默认root本地密码并创建远程连接用户park
    alter user  root@localhost identified by '密码';
    create user 'park'@'%' identified with mysql_native_password by '密码';
    grant all on *.* to 'park'@'%';
    # 创建主从同步的用户backup
    create user 'backup'@'%' identified with mysql_native_password by '密码';
    grant replication slave on *.* to 'backup'@'%';
    
    flush privileges;
    exit;
    

    1.11 如果是想配置2台服务器互为主从(需要从1.3的步骤改为 将7001配置的自增步长设置为2,自增起始位置设置为1;将7002配置的自增步长设置为2,自增起始位置设置为2,执行初始化)

    (7001为从7002为主)
    7002上执行:
    # 登录数据库(获得binlog当前日志位置)
    $ mysql -S /tmp/mysql_7002.sock -p
    show master status;
    得:
    +------------------+----------+--------------+---------------------------------------------+------------------------------------------+
    | File             | Position | Binlog_Do_DB | Binlog_Ignore_DB                            | Executed_Gtid_Set                        |
    +------------------+----------+--------------+---------------------------------------------+------------------------------------------+
    | mysql_bin.000001 |     1650 |              | mysql,information_schema,performance_schema | 4ef1f4e6-7a66-11eb-9cc0-e8611f2b6693:1-6 |
    +------------------+----------+--------------+---------------------------------------------+------------------------------------------+
    其中:mysql_bin.000001为master_log_file,1650为master_log_pos
    
    7001上执行:
    # 登录数据库
    $ mysql -S /tmp/mysql_7001.sock -p
    change master to master_host='127.0.0.1', master_port=主库端口此处为7002, master_user='主库用户此处为backup', master_password='backup的密码', master_log_file='此处为mysql-bin.000001', master_log_pos=此处为1650 for channel "通道名称此处设置为7002-7001";
    flush privileges;
    # 启动同步,使用 show slave statusG; 查看 出现两个IO为YES即可,常用start slave;为停止同步
    start slave;
    
    (7002为从7001为主)
    7001上执行:
    # 登录数据库(获得binlog当前日志位置)
    $ mysql -S /tmp/mysql_7001.sock -p
    show master status;
    得:
    +------------------+----------+--------------+---------------------------------------------+------------------------------------------+
    | File             | Position | Binlog_Do_DB | Binlog_Ignore_DB                            | Executed_Gtid_Set                        |
    +------------------+----------+--------------+---------------------------------------------+------------------------------------------+
    | mysql_bin.000001 |     1888 |              | mysql,information_schema,performance_schema | 4af1d4e6-7a66-11eb-9ca0-e8611g2b6692:1-8 |
    +------------------+----------+--------------+---------------------------------------------+------------------------------------------+
    其中:mysql_bin.000001为master_log_file,1888为master_log_pos
    
    7002上执行:
    # 登录数据库
    $ mysql -S /tmp/mysql_7002.sock -p
    change master to master_host='127.0.0.1', master_port=主库端口此处为7001, master_user='主库用户此处为backup', master_password='backup的密码', master_log_file='此处为mysql-bin.000001', master_log_pos=此处为1888 for channel "通道名称此处设置为7001-7002";
    flush privileges;
    # 启动同步,使用 show slave statusG; 查看 出现两个IO为YES即可,常用start slave;为停止同步
    start slave;
    
    # 备注:可以2台主一台从配合mysql router用,只要channel名称不同就可以同时开2个主同步到一个从
    备份顺序(7001主,7002主,7003从):
    7001-->7002
    7002-->7001
    7001->7003
    7002->7003
    为梦想不止不休!
  • 相关阅读:
    Spring 中出现Element : property Bean definitions can have zero or more properties. Property elements correspond to JavaBean setter methods exposed by the bean classes. Spring supports primitives, refer
    java定时器schedule和scheduleAtFixedRate区别
    hql语句中的select字句和from 字句
    使用maven搭建hibernate的pom文件配置
    Failure to transfer org.apache.maven:maven-archiver:pom:2.5 from http://repo.maven.apache.org/ maven2 was cached in the local repository, resolution will not be reattempted until the update interv
    对于文件File类型中的目录分隔符
    hibernate的事务管理和session对象的详解
    解决mac 中的myeclipse控制台中文乱码问题
    ibatis selectKey用法问题
    Java中getResourceAsStream的用法
  • 原文地址:https://www.cnblogs.com/virtulreal/p/14292704.html
Copyright © 2011-2022 走看看