侯体宗的博客
  • 首页
  • Hyperf版
  • beego仿版
  • 人生(杂谈)
  • 技术
  • 关于我
  • 更多分类
    • 文件下载
    • 文字修仙
    • 中国象棋ai
    • 群聊
    • 九宫格抽奖
    • 拼图
    • 消消乐
    • 相册

CentOS 7.2 Yum编译安装MySQL 5.6

linux  /  管理员 发布于 7年前   197

本文实例为大家分享CentOS 7.2 Yum安装mysql5.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/\]$/\]\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/bashsource /opt/rh/rh-mysql56/enableexport 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_installationNOTE: 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 currentpassword for the root user. If you've just installed MySQL, andyou 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 MySQLroot user without the proper authorisation.# set root passwordSet root password? [Y/n] yNew password:Re-enter new password:Password updated successfully!Reloading privilege tables.. ... Success!By default, a MySQL installation has an anonymous user, allowing anyoneto log into MySQL without having to have a user account created forthem. This is intended only for testing, and to make the installationgo a bit smoother. You should remove them before moving into aproduction environment.# remove anonymous usersRemove anonymous users? [Y/n] y ... Success!Normally, root should only be allowed to connect from 'localhost'. Thisensures that someone cannot guess at the root password from the network.# disallow root login remotelyDisallow root login remotely? [Y/n] y ... Success!By default, MySQL comes with a database named 'test' that anyone canaccess. This is also intended only for testing, and should be removedbefore moving into a production environment.# remove test databaseRemove 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 farwill take effect immediately.# reload privilege tablesReload privilege tables now? [Y/n] y ... Success!Cleaning up...All done! If you've completed all of the above steps, your MySQLinstallation should now be secure.Thanks for using MySQL!
[root@linuxprobe ~]# mysql -u root -pEnter password: Welcome to the MySQL monitor. Commands end with ; or \g.Your MySQL connection id is 13Server 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 itsaffiliates. Other names may be trademarks of their respectiveowners.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 | *E2ACEC2F2DA384EE6753673365DFEF35F0C272C9 || root | 127.0.0.1 | *E2ACEC2F2DA384EE6753673365DFEF35F0C272C9 || root | ::1 | *E2ACEC2F2DA384EE6753673365DFEF35F0C272C9 |+------+-----------+-------------------------------------------+3 rows in set (0.00 sec)mysql> show databases; +--------------------+| Database  |+--------------------+| information_schema || mysql  || performance_schema |+--------------------+3 rows in set (0.00 sec)mysql> exitBye

开启防火墙

[root@linuxprobe ~]# firewall-cmd Cadd-service=MySQL Cpermanent success [root@linuxprobe ~]# firewall-cmd Creload success

同样使用yum在vdevops.org上面安装mysql,安装步骤参考上面

MySQL 主从

Master端:linuxprobe

[root@linuxprobe~]# vi /etc/opt/rh/rh-mysql56/my.cnf.d/mysql-server.cnf[mysqld]# add follows in [mysqld] section : get binary logslog-bin=mysql-bin# define uniq server IDserver-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 2Server 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 itsaffiliates. Other names may be trademarks of their respectiveowners.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> exitBye

开启防火墙

[root@linuxprobe ~]# firewall-cmd Cadd-service=mysql Cpermanent success [root@linuxprobe ~]# firewall-cmd Creload success

Slave端:vdevops

[root@vdevops~]# vi /etc/opt/rh/rh-mysql56/my.cnf.d/mysql-server.cnf[mysqld]# add follows in [mysqld] section : get binary logslog-bin=mysql-bin# define server ID (different one from Master Host)server-id=102# read onlyread_only=1# define own hostnamereport-host=node01.srv.world[root@vdevops~]# systemctl restart rh-mysql56-mysqld

Master端:备份数据库

[root@linuxprobe ~]# mysql -u root -pEnter password: Welcome to the MySQL monitor. Commands end with ; or \g.Your MySQL connection id is 3Server 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 itsaffiliates. Other names may be trademarks of their respectiveowners.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> exitBye#[root@linuxprobe ~]# mysqldump -u root -p --all-databases --lock-all-tables --events > mysql_dump.sql # 备份数据库Enter password: [root@linuxprobe ~]# mysql -u root -pEnter password: Welcome to the MySQL monitor. Commands end with ; or \g.Your MySQL connection id is 5Server 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 itsaffiliates. Other names may be trademarks of their respectiveowners.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> exitBye[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)? yesWarning: Permanently added 'vdevops.org' (ECDSA) to the list of known hosts.mysql_dump.sql 

Slave 端:

[root@vdevops ~]# mysql -u root -p < /tmp/mysql_dump.sqlEnter password: [root@vdevops ~]# mysql -u root -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g.Your MySQL connection id is 3Server 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 itsaffiliates. Other names may be trademarks of their respectiveowners.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;  # positionQuery 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: 0Master_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: 01 row in set (0.00 sec)

精彩专题分享:mysql不同版本安装教程 mysql5.7各版本安装教程 mysql5.6各版本安装教程

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。


  • 上一条:
    Linux下彻底卸载mysql详解
    下一条:
    CentOS 7.2下MySQL的安装与相关配置
  • 昵称:

    邮箱:

    0条评论 (评论内容有缓存机制,请悉知!)
    最新最热
    • 分类目录
    • 人生(杂谈)
    • 技术
    • linux
    • Java
    • php
    • 框架(架构)
    • 前端
    • ThinkPHP
    • 数据库
    • 微信(小程序)
    • Laravel
    • Redis
    • Docker
    • Go
    • swoole
    • Windows
    • Python
    • 苹果(mac/ios)
    • 相关文章
    • 在Linux系统中使用Iptables实现流量转发功能流程步骤(0个评论)
    • vim学习笔记-入门级需要了解的一些快捷键(0个评论)
    • 在centos7系统中实现分区并格式化挂载一块硬盘到/data目录流程步骤(0个评论)
    • 在Linux系统种查看某一个进程所占用的内存命令(0个评论)
    • Linux中grep命令中的10种高级用法浅析(0个评论)
    • 近期文章
    • 智能合约Solidity学习CryptoZombie第三课:组建僵尸军队(高级Solidity理论)(0个评论)
    • 智能合约Solidity学习CryptoZombie第二课:让你的僵尸猎食(0个评论)
    • 智能合约Solidity学习CryptoZombie第一课:生成一只你的僵尸(0个评论)
    • 在go中实现一个常用的先进先出的缓存淘汰算法示例代码(0个评论)
    • 在go+gin中使用"github.com/skip2/go-qrcode"实现url转二维码功能(0个评论)
    • 在go语言中使用api.geonames.org接口实现根据国际邮政编码获取地址信息功能(1个评论)
    • 在go语言中使用github.com/signintech/gopdf实现生成pdf分页文件功能(0个评论)
    • gmail发邮件报错:534 5.7.9 Application-specific password required...解决方案(0个评论)
    • 欧盟关于强迫劳动的规定的官方举报渠道及官方举报网站(0个评论)
    • 在go语言中使用github.com/signintech/gopdf实现生成pdf文件功能(0个评论)
    • 近期评论
    • 122 在

      学历:一种延缓就业设计,生活需求下的权衡之选中评论 工作几年后,报名考研了,到现在还没认真学习备考,迷茫中。作为一名北漂互联网打工人..
    • 123 在

      Clash for Windows作者删库跑路了,github已404中评论 按理说只要你在国内,所有的流量进出都在监控范围内,不管你怎么隐藏也没用,想搞你分..
    • 原梓番博客 在

      在Laravel框架中使用模型Model分表最简单的方法中评论 好久好久都没看友情链接申请了,今天刚看,已经添加。..
    • 博主 在

      佛跳墙vpn软件不会用?上不了网?佛跳墙vpn常见问题以及解决办法中评论 @1111老铁这个不行了,可以看看近期评论的其他文章..
    • 1111 在

      佛跳墙vpn软件不会用?上不了网?佛跳墙vpn常见问题以及解决办法中评论 网站不能打开,博主百忙中能否发个APP下载链接,佛跳墙或极光..
    • 2016-11
    • 2017-07
    • 2017-10
    • 2017-11
    • 2018-01
    • 2018-02
    • 2020-03
    • 2020-04
    • 2020-05
    • 2020-06
    • 2021-02
    • 2021-03
    • 2021-04
    • 2021-06
    • 2021-07
    • 2021-08
    • 2021-09
    • 2021-10
    • 2021-11
    • 2021-12
    • 2022-01
    • 2022-03
    • 2022-04
    • 2022-08
    • 2022-11
    • 2022-12
    • 2023-01
    • 2023-02
    • 2023-03
    • 2023-06
    • 2023-07
    • 2023-10
    • 2023-12
    • 2024-01
    • 2024-04
    Top

    Copyright·© 2019 侯体宗版权所有· 粤ICP备20027696号 PHP交流群

    侯体宗的博客