CentOS 7.2 Yum编译安装MySQL 5.6
本文实例为大家分享CentOS7.2Yum安装mysql5.6的方法,供大家参考,具体内容如下
配置CentOSSCLo源
[3]添加CentOSSCLoSoftwarecollectionsRepository. [root@linuxprobe~]#yum-yinstallcentos-release-scl-rhcentos-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 #foranotherway,changeto[enabled=0]anduseitonlywhenneeded [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-yinstallrh-mysql56-mysql-server #加载环境变量 [root@linuxprobe~]#sclenablerh-mysql56bash [root@linuxprobe~]#mysql-V mysqlVer14.14Distrib5.6.26,forLinux(x86_64)usingEditLinewrapper [root@linuxprobe~]#whichmysql /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 exportX_SCLS="`sclenablerh-mysql56'echo$X_SCLS'`"
[4]EnableMySQL5.6andConfigureinitialsettings. [root@linuxprobe~]#vi/etc/opt/rh/rh-mysql56/my.cnf.d/mysql-server.cnf #addfollowswithin[mysqld]section [mysqld] character-set-server=utf8 [root@linuxprobe~]#systemctlstartrh-mysql56-mysqld [root@linuxprobe~]#systemctlenablerh-mysql56-mysqld [root@linuxprobe~]#mysql_secure_installation NOTE:RUNNINGALLPARTSOFTHISSCRIPTISRECOMMENDEDFORALLMySQL SERVERSINPRODUCTIONUSE!PLEASEREADEACHSTEPCAREFULLY! InordertologintoMySQLtosecureit,we'llneedthecurrent passwordfortherootuser.Ifyou'vejustinstalledMySQL,and youhaven'tsettherootpasswordyet,thepasswordwillbeblank, soyoushouldjustpressenterhere. Entercurrentpasswordforroot(enterfornone): OK,successfullyusedpassword,movingon... SettingtherootpasswordensuresthatnobodycanlogintotheMySQL rootuserwithouttheproperauthorisation. #setrootpassword Setrootpassword?[Y/n]y Newpassword: Re-enternewpassword: Passwordupdatedsuccessfully! Reloadingprivilegetables.. ...Success! Bydefault,aMySQLinstallationhasananonymoususer,allowinganyone tologintoMySQLwithouthavingtohaveauseraccountcreatedfor them.Thisisintendedonlyfortesting,andtomaketheinstallation goabitsmoother.Youshouldremovethembeforemovingintoa productionenvironment. #removeanonymoususers Removeanonymoususers?[Y/n]y ...Success! Normally,rootshouldonlybeallowedtoconnectfrom'localhost'.This ensuresthatsomeonecannotguessattherootpasswordfromthenetwork. #disallowrootloginremotely Disallowrootloginremotely?[Y/n]y ...Success! Bydefault,MySQLcomeswithadatabasenamed'test'thatanyonecan access.Thisisalsointendedonlyfortesting,andshouldberemoved beforemovingintoaproductionenvironment. #removetestdatabase Removetestdatabaseandaccesstoit?[Y/n] -Droppingtestdatabase... ...Success! -Removingprivilegesontestdatabase... ...Success! Reloadingtheprivilegetableswillensurethatallchangesmadesofar willtakeeffectimmediately. #reloadprivilegetables Reloadprivilegetablesnow?[Y/n]y ...Success! Cleaningup... Alldone!Ifyou'vecompletedalloftheabovesteps,yourMySQL installationshouldnowbesecure. ThanksforusingMySQL!
[root@linuxprobe~]#mysql-uroot-p Enterpassword: WelcometotheMySQLmonitor.Commandsendwith;or\g. YourMySQLconnectionidis13 Serverversion:5.6.26MySQLCommunityServer(GPL) Copyright(c)2000,2015,Oracleand/oritsaffiliates.Allrightsreserved. OracleisaregisteredtrademarkofOracleCorporationand/orits affiliates.Othernamesmaybetrademarksoftheirrespective owners. Type'help;'or'\h'forhelp.Type'\c'toclearthecurrentinputstatement. mysql>selectuser,host,passwordfrommysql.user; +------+-----------+-------------------------------------------+ |user|host|password| +------+-----------+-------------------------------------------+ |root|localhost|*E2ACEC2F2DA384EE6753673365DFEF35F0C272C9| |root|127.0.0.1|*E2ACEC2F2DA384EE6753673365DFEF35F0C272C9| |root|::1|*E2ACEC2F2DA384EE6753673365DFEF35F0C272C9| +------+-----------+-------------------------------------------+ 3rowsinset(0.00sec) mysql>showdatabases; +--------------------+ |Database| +--------------------+ |information_schema| |mysql| |performance_schema| +--------------------+ 3rowsinset(0.00sec) mysql>exit Bye
开启防火墙
[root@linuxprobe~]#firewall-cmd–add-service=MySQL–permanent success [root@linuxprobe~]#firewall-cmd–reload success
同样使用yum在vdevops.org上面安装mysql,安装步骤参考上面
MySQL主从
Master端:linuxprobe
[root@linuxprobe~]#vi/etc/opt/rh/rh-mysql56/my.cnf.d/mysql-server.cnf [mysqld] #addfollowsin[mysqld]section:getbinarylogs log-bin=mysql-bin #defineuniqserverID server-id=101 [root@linuxprobe~]#mysql-uroot-p Enterpassword: WelcometotheMySQLmonitor.Commandsendwith;or\g. YourMySQLconnectionidis2 Serverversion:5.6.26-logMySQLCommunityServer(GPL) Copyright(c)2000,2015,Oracleand/oritsaffiliates.Allrightsreserved. OracleisaregisteredtrademarkofOracleCorporationand/orits affiliates.Othernamesmaybetrademarksoftheirrespective owners. Type'help;'or'\h'forhelp.Type'\c'toclearthecurrentinputstatement. mysql>grantreplicationslaveon*.*toreplica@'%'identifiedby'password'; QueryOK,0rowsaffected(0.07sec) mysql>flushprivileges; QueryOK,0rowsaffected(0.00sec) mysql>exit Bye
开启防火墙
[root@linuxprobe~]#firewall-cmd–add-service=mysql–permanent success [root@linuxprobe~]#firewall-cmd–reload success
Slave端:vdevops
[root@vdevops~]#vi/etc/opt/rh/rh-mysql56/my.cnf.d/mysql-server.cnf [mysqld] #addfollowsin[mysqld]section:getbinarylogs log-bin=mysql-bin #defineserverID(differentonefromMasterHost) server-id=102 #readonly read_only=1 #defineownhostname report-host=node01.srv.world [root@vdevops~]#systemctlrestartrh-mysql56-mysqld
Master端:备份数据库
[root@linuxprobe~]#mysql-uroot-p Enterpassword: WelcometotheMySQLmonitor.Commandsendwith;or\g. YourMySQLconnectionidis3 Serverversion:5.6.26-logMySQLCommunityServer(GPL) Copyright(c)2000,2015,Oracleand/oritsaffiliates.Allrightsreserved. OracleisaregisteredtrademarkofOracleCorporationand/orits affiliates.Othernamesmaybetrademarksoftheirrespective owners. Type'help;'or'\h'forhelp.Type'\c'toclearthecurrentinputstatement. mysql>flushtableswithreadlock;#锁表 QueryOK,0rowsaffected(0.01sec) mysql>showmasterstatus;#记住file的数值和position的值 +------------------+----------+--------------+------------------+-------------------+ |File|Position|Binlog_Do_DB|Binlog_Ignore_DB|Executed_Gtid_Set| +------------------+----------+--------------+------------------+-------------------+ |mysql-bin.000001|400|||| +------------------+----------+--------------+------------------+-------------------+ 1rowinset(0.00sec) mysql>exit Bye # [root@linuxprobe~]#mysqldump-uroot-p--all-databases--lock-all-tables--events>mysql_dump.sql#备份数据库 Enterpassword: [root@linuxprobe~]#mysql-uroot-p Enterpassword: WelcometotheMySQLmonitor.Commandsendwith;or\g. YourMySQLconnectionidis5 Serverversion:5.6.26-logMySQLCommunityServer(GPL) Copyright(c)2000,2015,Oracleand/oritsaffiliates.Allrightsreserved. OracleisaregisteredtrademarkofOracleCorporationand/orits affiliates.Othernamesmaybetrademarksoftheirrespective owners. Type'help;'or'\h'forhelp.Type'\c'toclearthecurrentinputstatement. mysql>unlocktables;#解锁 QueryOK,0rowsaffected(0.00sec) mysql>exit Bye [root@linuxprobe~]#scpmysql_dump.sqlvdevops.org@/tmp/ cp:cannotcreateregularfile‘vdevops.org@/tmp/':Nosuchfileordirectory [root@linuxprobe~]#scpmysql_dump.sqlvdevops.org:/tmp/ Theauthenticityofhost'vdevops.org(10.1.1.56)'can'tbeestablished. ECDSAkeyfingerprintisf8:d2:55:54:8f:e8:43:e0:ee:aa:d6:8d:53:8c:8e:85. Areyousureyouwanttocontinueconnecting(yes/no)?yes Warning:Permanentlyadded'vdevops.org'(ECDSA)tothelistofknownhosts. mysql_dump.sql
Slave端:
[root@vdevops~]#mysql-uroot-p</tmp/mysql_dump.sql Enterpassword: [root@vdevops~]#mysql-uroot-p Enterpassword: WelcometotheMySQLmonitor.Commandsendwith;or\g. YourMySQLconnectionidis3 Serverversion:5.6.26-logMySQLCommunityServer(GPL) Copyright(c)2000,2015,Oracleand/oritsaffiliates.Allrightsreserved. OracleisaregisteredtrademarkofOracleCorporationand/orits affiliates.Othernamesmaybetrademarksoftheirrespective owners. Type'help;'or'\h'forhelp.Type'\c'toclearthecurrentinputstatement. mysql>changemasterto ->master_host='10.1.1.53',#masterip ->master_user='replica',#replicationID ->master_password='password',#replicationpasswd ->master_log_file='mysql-bin.000001',#bin-lognumber ->master_log_pos=400;#position QueryOK,0rowsaffected,2warnings(0.03sec) mysql>startslave; QueryOK,0rowsaffected(0.01sec) mysql>showslavestatus\G ***************************1.row*************************** Slave_IO_State:Waitingformastertosendevent 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:Slavehasreadallrelaylog;waitingfortheslaveI/Othreadtoupdateit 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 1rowinset(0.00sec)
精彩专题分享:mysql不同版本安装教程mysql5.7各版本安装教程mysql5.6各版本安装教程
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持毛票票。