CentOS 7.2 Yum compile and install MySQL 5.6, centosyum
The following example shows how to install mysql5.6 on CentOS 7.2 Yum.
Configure the CentOS SCLo Source
[3] add 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
Install MySQL in yum
# Install mysql [root @ linuxprobe ~] # Yum -- enablerepo = centos-sclo-rh-y install rh-mysql56-mysql-server # Load environment variable [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 # Set mysql boot from 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
Enable Firewall
[root@linuxprobe ~]# firewall-cmd –add-service=MySQL –permanent success [root@linuxprobe ~]# firewall-cmd –reload success
Use yum to install mysql on vdevops.org. For installation steps, refer to the above
MySQL Master/Slave
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
Enable Firewall
[root@linuxprobe ~]# firewall-cmd –add-service=mysql –permanent success [root@linuxprobe ~]# firewall-cmd –reload success
Slave end: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:Back up database
[Root @ linuxprobe ~] # Mysql-u root-pEnter 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,201 5, 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; # lock Table Query OK, 0 rows affected (0.01 sec) mysql> show master status; # Remember the value of file and position + ------------------ + ---------- + -------------- + bytes + | File | Position | Binlog_Do_DB | bytes | + bytes + ---------- + -------------- + ------------ ------ + ------------------- + | 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 # backup database Enter password: [root @ linuxprobe ~] # Mysql-u root-pEnter 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,201 5, 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; # unlock 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 end:
[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)
The above is all the content of this article. I hope it will be helpful for your learning and support for helping customers.