• Linux CentOS 7 部署MySQL 5.7 并实现主从


    一、部署步骤

    1.检查centos自带MySQL,如果存在进行卸载

    # rpm -qa | grep mariadb

     # rpm -e mariadb-libs-5.5.60-1.el7_5.x86_64 --nodeps

     2.下载安装

    # wget http://dev.mysql.com/get/mysql57-community-release-el7-9.noarch.rpm
    # rpm -ivh mysql57-community-release-el7-9.noarch.rpm
    # yum install mysql-server

    3.重启MySQL

    # service mysqld restart

    4.修改密码

    # mysql -u root
    # use mysql
    mysql> update user set password=password("XXXX") where user="root";
    mysql> flush privileges;
    mysql> exit;
    # service mysqld restart

    5.远程链接设置

    # mysql -u root -p
    mysql>GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'mscyd@2019' WITH GRANT OPTION;
    mysql> exit;
    # service mysqld restart

    6.启动、停止MySQL服务

    # systemctl start mysqld
    # systemctl stop mysqld

    7.检查MySQL运行状态

    # systemctl status mysqld

    8.防火墙设置

    # firewall-cmd --zone=public --add-port=3306/tcp --permanent
    # firewall-cmd --reload
    # firewall-cmd --zone=public --query-port=3306/tcp

    二、主从配置

    1.主数据库配置

    编辑配置文件

    # vi /etc/my.cnf

    在[mysqld]添加如下配置:

    log-bin=mysql-bin
    server-id=1
    binlog-ignore-db=information_schema
    binlog-ignore-db=performance_schema
    binlog-ignore-db=mysql
    binlog-do-db=mydb

     注:mydb为配置的主从同步数据库

    重启MySQL

    # systemctl restart mysqld

    查看配置

    # mysql -u root -p
    mysql> show master status;

    mysql> exit;

    2.从数据库配置

    编辑配置文件

    # vi /etc/my.cnf

    在[mysqld]添加如下配置:

    log-bin=mysql-bin
    server-id=2
    binlog-ignore-db=information_schema
    binlog-ignore-db=performance_schema
    binlog-ignore-db=mysql
    replicate-do-db=mydb
    replicate-ignore-db=mysql
    log-slave-updates
    slave-skip-errors=all
    slave-net-timeout=60

     

    重启MySQL

    # systemctl restart mysqld

    修改配置

    # mysql -u root -p
    mysql> show master status;
    mysql> stop slave;  
    mysql>change master to master_host='192.168.18.70',master_user='root',master_password='XXXX',master_log_file='mysql-bin.000001', master_log_pos=120;
    mysql> start slave;

    注:在这里指定Master的信息,master_log_file是在配置Master的时候的File选项, master_log_pos是在配置Master的Position 选项,这里要进行对应。

    查看配置

    mysql> show slave status G;

     三、新建数据库测试

    在主库上新建新建表和数据进行测试

  • 相关阅读:
    JS垃圾回收机制
    Flex布局
    HTTP请求
    css基本布局方式
    阮一峰《ECMAScript 6 入门》读书笔记——模版标签
    阮一峰《ECMAScript 6 入门》读书笔记——变量解构赋值
    阮一峰《ECMAScript 6 入门》读书笔记——let与const
    闭包(Closure)
    CSS浮动布局带来的高度塌陷以及其解决办法
    CSS网页的布局
  • 原文地址:https://www.cnblogs.com/donaldtdz/p/14774920.html
Copyright © 2020-2023  润新知