CentOS   发布时间:2022-04-02  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了CentOS 7.2 Yum安装MySQL 5.6大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

概述

配置CentOS SCLo源 [3] 添加 CentOS SCLo Software collections Repository. [root@linuxprobe~]# yum -y install centos-release-scl-rh centos-release-scl # set [priority=10] [root@linuxprobe~]# sed -i -e "s/\]$/

配置CentOS SCLo源

[3] 添加 CentOS SCLo Software collections Repository.
[root@linuxprobe~]# yum -y install centos-release-scl-rh centos-release-scl
# set [priority=10]
[root@linuxprobe~]# sed -i -e "s/\]$/\]\npriority=10/g" /etc/yum.repos.d/CentOS-SCLo-scl.repo [root@linuxprobe~]# sed -i -e "s/\]$/\]\npriority=10/g" /etc/yum.repos.d/CentOS-SCLo-scl-rh.repo
# for another way,change to [enabled=0] and use it only when needed
[root@linuxprobe~]# sed -i -e "s/enabled=1/enabled=0/g" /etc/yum.repos.d/CentOS-SCLo-scl.repo
[root@dlp ~]# sed -i -e "s/enabled=1/enabled=0/g" /etc/yum.repos.d/CentOS-SCLo-scl-rh.repo

yum安装MysqL

# 安装MysqL
[root@linuxprobe~]# yum --enablerepo=centos-sclo-rh -y install rh-MysqL56-MysqL-server
# 加载环境变量
[root@linuxprobe ~]# scl enable rh-MysqL56 bash
[root@linuxprobe ~]# MysqL -V 
MysqL  Ver 14.14 DiStrib 5.6.26,for Linux (x86_64) using  EditLine wrapper
[root@linuxprobe ~]# which MysqL 
/opt/rh/rh-MysqL56/root/usr/bin/MysqL
# 设置MysqL开机自启动
root@linuxprobe ~]# vi /etc/profile.d/rh-MysqL56.sh
#!/bin/bash
source /opt/rh/rh-MysqL56/enable
export X_SCLS="`scl enable rh-MysqL56 'echo $X_SCLS'`"
[4] Enable MysqL 5.6 and Configure initial setTings.
[root@linuxprobe ~]# vi /etc/opt/rh/rh-MysqL56/my.cnf.d/MysqL-server.cnf
# add follows within [MysqLd] section
[MysqLd]
character-set-server=utf8
[root@linuxprobe ~]# systemctl start rh-MysqL56-MysqLd
[root@linuxprobe ~]# systemctl enable rh-MysqL56-MysqLd
[root@linuxprobe ~]# MysqL_secure_installation
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MysqL
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!
In order to log into MysqL to secure it,we'll need the current
password for the root user.  If you've just installed MysqL,and
you haven't set the root password yet,the password will be blank,so you should just press enter here.
Enter current password for root (enter for nonE):
OK,successfully used password,moving on...
SetTing the root password ensures that nobody can log into the MysqL
root user without the proper authorisation.
# set root password
Set root password? [Y/n] y
New password:
Re-enter new password:
password updated successfully!
Reloading privilege tables..
 ... success!
By default,a MysqL installation has an anonymous user,allowing anyone
to log into MysqL without having to have a user account created for
them.  This is intended only for tesTing,and to make the installation
go a bit smoother.  You should remove them before moving into a
production environment.
# remove anonymous users
Remove anonymous users? [Y/n] y
 ... success!
Normally,root should only be allowed to connect from 'localhost'.  This
ensures that someone cAnnot guess at the root password from the network.
# disallow root login remotely
Disallow root login remotely? [Y/n] y
 ... success!
By default,MysqL comes with a database named 'test' that anyone can
access.  This is also intended only for tesTing,and should be removed
before moving into a production environment.
# remove test database
Remove test database and access to it? [Y/n] 
 - Dropping test database...
 ... success!
 - Removing privileges on test database...
 ... success!

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.
# reload privilege tables
Reload privilege tables Now? [Y/n] y
 ... success!
Cleaning up...
All done!  If you've completed all of the above steps,your MysqL
installation should Now be secure.
Thanks for using MysqL!
[root@linuxprobe ~]# MysqL -u root -p
Enter password: 
Welcome to the MysqL monitor.  Commands end with ; or \g.
Your MysqL connection id is 13
Server version: 5.6.26 MysqL Community Server (GPL)

Copyright (C) 2000,2015,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.
MysqL> SELEct user,host,password from MysqL.user; +------+-----------+-------------------------------------------+
| user | host | password | +------+-----------+-------------------------------------------+
| root | localhost | @H_403_280@*E2ACEC2F2DA384EE6753673365DFEF35F0C272C9 | | root | 127.0.0.1 | *E2ACEC2F2DA384EE6753673365DFEF35F0C272C9 |
| root | ::1 | *E2ACEC2F2DA384EE6753673365DFEF35F0C272C9 | +------+-----------+-------------------------------------------+
3 rows in set (0.00 seC)
MysqL> show databases; +--------------------+
| Database | +--------------------+
| information_scheR_99_11845@a | | MysqL | | perfoRMANce_scheR_99_11845@a |
+--------------------+
3 rows in set (0.00 seC)
MysqL> exit
Bye
@H_287_301@
  • 同样使用yum在vdevops.org上面安装MysqL,安装步骤参上面
  • MysqL 主从

    @H_287_301@ @H_578_305@master端:linuxprobe
    [root@linuxprobe~]# vi /etc/opt/rh/rh-MysqL56/my.cnf.d/MysqL-server.cnf
    [MysqLd]
    # add follows in [MysqLd] section : get binary logs
    log-bin=MysqL-bin
    # define uniq server ID
    server-id=101
    [root@linuxprobe ~]# MysqL -u root -p 
    Enter password: 
    Welcome to the MysqL monitor.  Commands end with ; or \g.
    Your MysqL connection id is 2
    Server version: 5.6.26-log MysqL Community Server (GPL)
    Copyright (C) 2000,2015,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.
    MysqL> grant Replication slave on *.* to replica@'%' identified by 'password';
    Query OK,0 rows affected (0.07 seC)
    MysqL> flush privileges; 
    Query OK,0 rows affected (0.00 seC)
    MysqL> exit
    Bye
    @H_287_301@
  • Slave端:vdevops
  • [root@vdevops~]# vi /etc/opt/rh/rh-MysqL56/my.cnf.d/MysqL-server.cnf
    [MysqLd]
    # add follows in [MysqLd] section : get binary logs
    log-bin=MysqL-bin
    # define server ID (different one from Master Host)
    server-id=102
    # read only
    read_only=1
    # define own hostname
    report-host=node01.srv.world
    [root@vdevops~]# systemctl restart rh-MysqL56-MysqLd
    @H_287_301@ @H_578_305@master端:备份数据库
    [root@linuxprobe ~]# MysqL -u root -p
    Enter password: 
    Welcome to the MysqL monitor.  Commands end with ; or \g.
    Your MysqL connection id is 3
    Server version: 5.6.26-log MysqL Community Server (GPL)
    Copyright (C) 2000,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.
    MysqL> flush tables with read lock;   # 锁表
    Query OK,0 rows affected (0.01 seC)
    MysqL> show master status;    #记住file的数值和position的值
    +------------------+----------+--------------+------------------+-------------------+
    | File             | Position | binlog_Do_DB | binlog_Ignore_DB | Executed_Gtid_Set |
    +------------------+----------+--------------+------------------+-------------------+
    | MysqL-bin.000001 |      400 |              |                  |                   |
    +------------------+----------+--------------+------------------+-------------------+
    1 row in set (0.00 seC)
    MysqL> exit
    Bye
    #
    [root@linuxprobe ~]# MysqLdump -u root -p --all-databases --lock-all-tables --events > MysqL_dump.sql # 备份数据库
    Enter password: 
    [root@linuxprobe ~]# MysqL -u root -p
    Enter password: 
    Welcome to the MysqL monitor.  Commands end with ; or \g.
    Your MysqL connection id is 5
    Server version: 5.6.26-log MysqL Community Server (GPL)
    
    Copyright (C) 2000,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.
    
    MysqL> unlock tables;  # 解锁
    Query OK,0 rows affected (0.00 seC)
    
    MysqL> exit
    Bye
    [root@linuxprobe ~]# scp MysqL_dump.sql vdevops.org@/tmp/
    cp: cAnnot create regular file ‘vdevops.org@/tmp/’: No such file or directory
    [root@linuxprobe ~]# scp MysqL_dump.sql vdevops.org:/tmp/
    The authenticity of host 'vdevops.org (10.1.1.56)' can't be established.
    ECDSA key fingerprint is f8:d2:55:54:8f:e8:43:e0:ee:aa:d6:8d:53:8c:8e:85.
    Are you sure you want to conTinue connecTing (yes/no)? yes
    Warning: PeRMANently added 'vdevops.org' (ECDSA) to the list of kNown hosts.
    MysqL_dump.sql
    @H_287_301@
  • Slave 端:
  • [root@vdevops ~]# MysqL -u root -p < /tmp/MysqL_dump.sql
    Enter password: 
    [root@vdevops ~]# MysqL -u root -p 
    Enter password: 
    Welcome to the MysqL monitor.  Commands end with ; or \g.
    Your MysqL connection id is 3
    Server version: 5.6.26-log MysqL Community Server (GPL)
    
    Copyright (C) 2000,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.
    
    MysqL> change master to
        -> master_host='10.1.1.53',# master ip
        -> master_user='replica',# Replication ID
        -> master_password='password',# Replication passwd
        -> master_log_file='MysqL-bin.000001',# bin-log number
        -> master_log_pos=400;          # position
    Query OK,0 rows affected,2 warnings (0.03 seC)
    
    MysqL> start slave;
    Query OK,0 rows affected (0.01 seC)
    
    MysqL> show slave status\G
    *************************** 1. row ***************************
                   Slave_IO_State: WaiTing for master to send event
                      Master_Host: 10.1.1.53
                      Master_User: replica
                      Master_Port: 3306
                    Connect_Retry: 60
                  Master_Log_File: MysqL-bin.000001
              Read_Master_Log_Pos: 475
                   Relay_Log_File: MysqLd-relay-bin.000002
                    Relay_Log_Pos: 358
            Relay_Master_Log_File: MysqL-bin.000001
                 Slave_IO_Running: Yes
                Slave_sql_Running: Yes
                  Replicate_Do_DB: 
              Replicate_Ignore_DB: 
               Replicate_Do_Table: 
           Replicate_Ignore_Table: 
          Replicate_Wild_Do_Table: 
      Replicate_Wild_Ignore_Table: 
                       Last_Errno: 0
                       Last_Error: 
                     Skip_Counter: 0
              Exec_Master_Log_Pos: 475
                  Relay_Log_Space: 532
                  Until_Condition: None
                   Until_Log_File: 
                    Until_Log_Pos: 0
               Master_SSL_Allowed: No
               Master_SSL_CA_File: 
               Master_SSL_CA_Path: 
                  Master_SSL_Cert: 
                Master_SSL_Cipher: 
                   Master_SSL_Key: 
            Seconds_Behind_Master: 0
    Master_SSL_Verify_Server_Cert: No
                    Last_IO_Errno: 0
                    Last_IO_Error: 
                   Last_sql_Errno: 0
                   Last_sql_Error: 
      Replicate_Ignore_Server_Ids: 
                 Master_Server_Id: 101
                      Master_UUID: d47dddc3-9c70-11e6-8efb-000c29ffc05a
                 Master_Info_File: /var/opt/rh/rh-MysqL56/lib/MysqL/master.info
                        sql_Delay: 0
              sql_Remaining_Delay: NULL
          Slave_sql_Running_State: Slave has read all relay log; waiTing for the slave I/O thread to update it
               Master_Retry_Count: 86400
                      Master_Bind: 
          Last_IO_Error_timestamp: 
         Last_sql_Error_timestamp: 
                   Master_SSL_Crl: 
               Master_SSL_Crlpath: 
               Retrieved_Gtid_Set: 
                Executed_Gtid_Set: 
                    Auto_Position: 0
    1 row in set (0.00 seC)

    大佬总结

    以上是大佬教程为你收集整理的CentOS 7.2 Yum安装MySQL 5.6全部内容,希望文章能够帮你解决CentOS 7.2 Yum安装MySQL 5.6所遇到的程序开发问题。

    如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

    本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
    如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。