CentOS 7.2 Yum安装MySQL 5.6

前端之家收集整理的这篇文章主要介绍了CentOS 7.2 Yum安装MySQL 5.6前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
@H_404_1@配置CentOS SCLo源
  1. [3] 添加 CentOS SCLo Software collections Repository.
  2. [root@linuxprobe~]# yum -y install centos-release-scl-rh centos-release-scl
  3. # set [priority=10]
  4. [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
  5. # for another way,change to [enabled=0] and use it only when needed
  6. [root@linuxprobe~]# sed -i -e "s/enabled=1/enabled=0/g" /etc/yum.repos.d/CentOS-SCLo-scl.repo
  7. [root@dlp ~]# sed -i -e "s/enabled=1/enabled=0/g" /etc/yum.repos.d/CentOS-SCLo-scl-rh.repo

yum安装MysqL

  1. # 安装MysqL
  2. [root@linuxprobe~]# yum --enablerepo=centos-sclo-rh -y install rh-MysqL56-MysqL-server
  3. # 加载环境变量
  4. [root@linuxprobe ~]# scl enable rh-MysqL56 bash
  5. [root@linuxprobe ~]# MysqL -V
  6. MysqL Ver 14.14 Distrib 5.6.26,for Linux (x86_64) using EditLine wrapper
  7. [root@linuxprobe ~]# which MysqL
  8. /opt/rh/rh-MysqL56/root/usr/bin/MysqL
  9. # 设置MysqL开机自启动
  10. root@linuxprobe ~]# vi /etc/profile.d/rh-MysqL56.sh
  11. #!/bin/bash
  12. source /opt/rh/rh-MysqL56/enable
  13. export X_SCLS="`scl enable rh-MysqL56 'echo $X_SCLS'`"
  1. [4] Enable MysqL 5.6 and Configure initial settings.
  2. [root@linuxprobe ~]# vi /etc/opt/rh/rh-MysqL56/my.cnf.d/MysqL-server.cnf
  3. # add follows within [MysqLd] section
  4. [MysqLd]
  5. character-set-server=utf8
  6. [root@linuxprobe ~]# systemctl start rh-MysqL56-MysqLd
  7. [root@linuxprobe ~]# systemctl enable rh-MysqL56-MysqLd
  8. [root@linuxprobe ~]# MysqL_secure_installation
  9. NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MysqL
  10. SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!
  11. In order to log into MysqL to secure it,we'll need the current
  12. password for the root user. If you've just installed MysqL,and
  13. you haven't set the root password yet,the password will be blank,so you should just press enter here.
  14. Enter current password for root (enter for none):
  15. OK,successfully used password,moving on...
  16. Setting the root password ensures that nobody can log into the MysqL
  17. root user without the proper authorisation.
  18. # set root password
  19. Set root password? [Y/n] y
  20. New password:
  21. Re-enter new password:
  22. Password updated successfully!
  23. Reloading privilege tables..
  24. ... Success!
  25. By default,a MysqL installation has an anonymous user,allowing anyone
  26. to log into MysqL without having to have a user account created for
  27. them. This is intended only for testing,and to make the installation
  28. go a bit smoother. You should remove them before moving into a
  29. production environment.
  30. # remove anonymous users
  31. Remove anonymous users? [Y/n] y
  32. ... Success!
  33. Normally,root should only be allowed to connect from 'localhost'. This
  34. ensures that someone cannot guess at the root password from the network.
  35. # disallow root login remotely
  36. Disallow root login remotely? [Y/n] y
  37. ... Success!
  38. By default,MysqL comes with a database named 'test' that anyone can
  39. access. This is also intended only for testing,and should be removed
  40. before moving into a production environment.
  41. # remove test database
  42. Remove test database and access to it? [Y/n]
  43. - Dropping test database...
  44. ... Success!
  45. - Removing privileges on test database...
  46. ... Success!
  47.  
  48. Reloading the privilege tables will ensure that all changes made so far
  49. will take effect immediately.
  50. # reload privilege tables
  51. Reload privilege tables now? [Y/n] y
  52. ... Success!
  53. Cleaning up...
  54. All done! If you've completed all of the above steps,your MysqL
  55. installation should now be secure.
  56. Thanks for using MysqL!
  1. [root@linuxprobe ~]# MysqL -u root -p
  2. Enter password:
  3. Welcome to the MysqL monitor. Commands end with ; or \g.
  4. Your MysqL connection id is 13
  5. Server version: 5.6.26 MysqL Community Server (GPL)
  6.  
  7. Copyright (c) 2000,2015,Oracle and/or its affiliates. All rights reserved.
  8.  
  9. Oracle is a registered trademark of Oracle Corporation and/or its
  10. affiliates. Other names may be trademarks of their respective
  11. owners.
  12. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
  13. MysqL> select user,host,password from MysqL.user; +------+-----------+-------------------------------------------+
  14. | user | host | password | +------+-----------+-------------------------------------------+
  15. | root | localhost | *E2ACEC2F2DA384EE6753673365DFEF35F0C272C9 | | root | 127.0.0.1 | *E2ACEC2F2DA384EE6753673365DFEF35F0C272C9 |
  16. | root | ::1 | *E2ACEC2F2DA384EE6753673365DFEF35F0C272C9 | +------+-----------+-------------------------------------------+
  17. 3 rows in set (0.00 sec)
  18. MysqL> show databases; +--------------------+
  19. | Database | +--------------------+
  20. | information_schema | | MysqL | | performance_schema |
  21. +--------------------+
  22. 3 rows in set (0.00 sec)
  23. MysqL> exit
  24. Bye

开启防火墙
[root@linuxprobe ~]# firewall-cmd –add-service=MysqL –permanent
success
[root@linuxprobe ~]# firewall-cmd –reload
success

@H_646_301@
  • 同样使用yum在vdevops.org上面安装MysqL,安装步骤参考上面
  • MysqL 主从

    @H_646_301@
  • Master端:linuxprobe
    1. [root@linuxprobe~]# vi /etc/opt/rh/rh-MysqL56/my.cnf.d/MysqL-server.cnf
    2. [MysqLd]
    3. # add follows in [MysqLd] section : get binary logs
    4. log-bin=MysqL-bin
    5. # define uniq server ID
    6. server-id=101
    7. [root@linuxprobe ~]# MysqL -u root -p
    8. Enter password:
    9. Welcome to the MysqL monitor. Commands end with ; or \g.
    10. Your MysqL connection id is 2
    11. Server version: 5.6.26-log MysqL Community Server (GPL)
    12. Copyright (c) 2000,2015,Oracle and/or its affiliates. All rights reserved.
    13. Oracle is a registered trademark of Oracle Corporation and/or its
    14. affiliates. Other names may be trademarks of their respective
    15. owners.
    16. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
    17. MysqL> grant replication slave on *.* to replica@'%' identified by 'password';
    18. Query OK,0 rows affected (0.07 sec)
    19. MysqL> flush privileges;
    20. Query OK,0 rows affected (0.00 sec)
    21. MysqL> exit
    22. Bye

    开启防火墙
    [root@linuxprobe ~]# firewall-cmd –add-service=MysqL –permanent
    success
    [root@linuxprobe ~]# firewall-cmd –reload
    success

    @H_646_301@
  • Slave端:vdevops
    1. [root@vdevops~]# vi /etc/opt/rh/rh-MysqL56/my.cnf.d/MysqL-server.cnf
    2. [MysqLd]
    3. # add follows in [MysqLd] section : get binary logs
    4. log-bin=MysqL-bin
    5. # define server ID (different one from Master Host)
    6. server-id=102
    7. # read only
    8. read_only=1
    9. # define own hostname
    10. report-host=node01.srv.world
    11. [root@vdevops~]# systemctl restart rh-MysqL56-MysqLd
    @H_646_301@
  • Master端:备份数据库
    1. [root@linuxprobe ~]# MysqL -u root -p
    2. Enter password:
    3. Welcome to the MysqL monitor. Commands end with ; or \g.
    4. Your MysqL connection id is 3
    5. Server version: 5.6.26-log MysqL Community Server (GPL)
    6. Copyright (c) 2000,Oracle and/or its affiliates. All rights reserved.
    7. Oracle is a registered trademark of Oracle Corporation and/or its
    8. affiliates. Other names may be trademarks of their respective
    9. owners.
    10. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
    11. MysqL> flush tables with read lock; # 锁表
    12. Query OK,0 rows affected (0.01 sec)
    13. MysqL> show master status; #记住file的数值和position的值
    14. +------------------+----------+--------------+------------------+-------------------+
    15. | File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
    16. +------------------+----------+--------------+------------------+-------------------+
    17. | MysqL-bin.000001 | 400 | | | |
    18. +------------------+----------+--------------+------------------+-------------------+
    19. 1 row in set (0.00 sec)
    20. MysqL> exit
    21. Bye
    22. #
    23. [root@linuxprobe ~]# MysqLdump -u root -p --all-databases --lock-all-tables --events > MysqL_dump.sql # 备份数据库
    24. Enter password:
    25. [root@linuxprobe ~]# MysqL -u root -p
    26. Enter password:
    27. Welcome to the MysqL monitor. Commands end with ; or \g.
    28. Your MysqL connection id is 5
    29. Server version: 5.6.26-log MysqL Community Server (GPL)
    30.  
    31. Copyright (c) 2000,Oracle and/or its affiliates. All rights reserved.
    32.  
    33. Oracle is a registered trademark of Oracle Corporation and/or its
    34. affiliates. Other names may be trademarks of their respective
    35. owners.
    36.  
    37. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
    38.  
    39. MysqL> unlock tables; # 解锁
    40. Query OK,0 rows affected (0.00 sec)
    41.  
    42. MysqL> exit
    43. Bye
    44. [root@linuxprobe ~]# scp MysqL_dump.sql vdevops.org@/tmp/
    45. cp: cannot create regular file vdevops.org@/tmp/’: No such file or directory
    46. [root@linuxprobe ~]# scp MysqL_dump.sql vdevops.org:/tmp/
    47. The authenticity of host 'vdevops.org (10.1.1.56)' can't be established.
    48. ECDSA key fingerprint is f8:d2:55:54:8f:e8:43:e0:ee:aa:d6:8d:53:8c:8e:85.
    49. Are you sure you want to continue connecting (yes/no)? yes
    50. Warning: Permanently added 'vdevops.org' (ECDSA) to the list of known hosts.
    51. MysqL_dump.sql
    @H_646_301@
  • Slave 端:
    1. [root@vdevops ~]# MysqL -u root -p < /tmp/MysqL_dump.sql
    2. Enter password:
    3. [root@vdevops ~]# MysqL -u root -p
    4. Enter password:
    5. Welcome to the MysqL monitor. Commands end with ; or \g.
    6. Your MysqL connection id is 3
    7. Server version: 5.6.26-log MysqL Community Server (GPL)
    8.  
    9. Copyright (c) 2000,Oracle and/or its affiliates. All rights reserved.
    10.  
    11. Oracle is a registered trademark of Oracle Corporation and/or its
    12. affiliates. Other names may be trademarks of their respective
    13. owners.
    14.  
    15. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
    16.  
    17. MysqL> change master to
    18. -> master_host='10.1.1.53',# master ip
    19. -> master_user='replica',# replication ID
    20. -> master_password='password',# replication passwd
    21. -> master_log_file='MysqL-bin.000001',# bin-log number
    22. -> master_log_pos=400; # position
    23. Query OK,0 rows affected,2 warnings (0.03 sec)
    24.  
    25. MysqL> start slave;
    26. Query OK,0 rows affected (0.01 sec)
    27.  
    28. MysqL> show slave status\G
    29. *************************** 1. row ***************************
    30. Slave_IO_State: Waiting for master to send event
    31. Master_Host: 10.1.1.53
    32. Master_User: replica
    33. Master_Port: 3306
    34. Connect_Retry: 60
    35. Master_Log_File: MysqL-bin.000001
    36. Read_Master_Log_Pos: 475
    37. Relay_Log_File: MysqLd-relay-bin.000002
    38. Relay_Log_Pos: 358
    39. Relay_Master_Log_File: MysqL-bin.000001
    40. Slave_IO_Running: Yes
    41. Slave_sql_Running: Yes
    42. Replicate_Do_DB:
    43. Replicate_Ignore_DB:
    44. Replicate_Do_Table:
    45. Replicate_Ignore_Table:
    46. Replicate_Wild_Do_Table:
    47. Replicate_Wild_Ignore_Table:
    48. Last_Errno: 0
    49. Last_Error:
    50. Skip_Counter: 0
    51. Exec_Master_Log_Pos: 475
    52. Relay_Log_Space: 532
    53. Until_Condition: None
    54. Until_Log_File:
    55. Until_Log_Pos: 0
    56. Master_SSL_Allowed: No
    57. Master_SSL_CA_File:
    58. Master_SSL_CA_Path:
    59. Master_SSL_Cert:
    60. Master_SSL_Cipher:
    61. Master_SSL_Key:
    62. Seconds_Behind_Master: 0
    63. Master_SSL_Verify_Server_Cert: No
    64. Last_IO_Errno: 0
    65. Last_IO_Error:
    66. Last_sql_Errno: 0
    67. Last_sql_Error:
    68. Replicate_Ignore_Server_Ids:
    69. Master_Server_Id: 101
    70. Master_UUID: d47dddc3-9c70-11e6-8efb-000c29ffc05a
    71. Master_Info_File: /var/opt/rh/rh-MysqL56/lib/MysqL/master.info
    72. sql_Delay: 0
    73. sql_Remaining_Delay: NULL
    74. Slave_sql_Running_State: Slave has read all relay log; waiting for the slave I/O thread to update it
    75. Master_Retry_Count: 86400
    76. Master_Bind:
    77. Last_IO_Error_Timestamp:
    78. Last_sql_Error_Timestamp:
    79. Master_SSL_Crl:
    80. Master_SSL_Crlpath:
    81. Retrieved_Gtid_Set:
    82. Executed_Gtid_Set:
    83. Auto_Position: 0
    84. 1 row in set (0.00 sec)

    猜你在找的CentOS相关文章