centos如何离线安装mysql
本篇内容介绍了“centos如何离线安装mysql”的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!
centos离线安装mysql的方法:1、将lib中的所有依赖上传到linux中,并用yum命令进行安装;2、解压MySQL并把文件复制到想要安装的目录;3、修改my.cnf配置文件;4、复制启动脚本到资源目录并修改启动脚本;5、将mysqld服务加入到系统服务里面;6、将mysql客户端配置到环境变量中,并使配置生效即可。
准备环境
1、离线 centOS 7(此处为 centOS 7 最小安装)
2、nginx 安装文件
3、nginx 依赖包
查询之前是否有 mariadb ,有就将其删除,并删除以前的配置文件 /etc/my.cnf
[root@localhost~]#rpm-qa|grepmariadb*mariadb-libs-5.5.56-2.el7.x86_64[root@localhost~]#rpm-emariadb-libs--nodeps[root@localhost~]#rpm-qa|grepmariadb*[root@localhost~]#rm-f/etc/my.cnf[root@localhost~]#
将 lib 中的所有依赖上传到 linux 中,并用命令进行安装
[root@localhostlib]#yum-ylocalinstall*.rpm
1、解压并把文件复制到你想要安装的目录(此处我将 /opt/mysql 作为安装目录)
[root@localhostmysql_install]#tar-xzvfmysql-5.6.51-linux-glibc2.12-x86_64.tar.gz[root@localhostmysql_install]#lslibmysql-5.6.51-linux-glibc2.12-x86_64mysql-5.6.51-linux-glibc2.12-x86_64.tar.gz[root@localhostmysql_install]#cp-Rmysql-5.6.51-linux-glibc2.12-x86_64/opt/mysql[root@localhostmysql_install]#cd/opt/mysql[root@localhostmysql]#lsbindatadocsincludelibLICENSEmanmysql-testREADMEscriptssharesql-benchsupport-files
2、新建 mysql 组和 mysql 用户,并将 mysql 目录更换成 mysql 用户组
[root@localhostmysql]#groupaddmysql[root@localhostmysql]#useradd-gmysqlmysql[root@localhostmysql]#cd..[root@localhostopt]#lsmysql[root@localhostopt]#chown-Rmysql:mysqlmysql[root@localhostopt]#lltotal0drwxr-xr-x.13mysqlmysql191Mar2301:42mysql[root@localhostopt]#cdmysql[root@localhostmysql]#lltotal224drwxr-xr-x.2mysqlmysql4096Mar2301:42bindrwxr-xr-x.3mysqlmysql18Mar2301:42datadrwxr-xr-x.2mysqlmysql55Mar2301:42docsdrwxr-xr-x.3mysqlmysql4096Mar2301:42includedrwxr-xr-x.3mysqlmysql4096Mar2301:42lib-rw-r--r--.1mysqlmysql200256Mar2301:42LICENSEdrwxr-xr-x.4mysqlmysql30Mar2301:42mandrwxr-xr-x.10mysqlmysql4096Mar2301:42mysql-test-rw-r--r--.1mysqlmysql566Mar2301:42READMEdrwxr-xr-x.2mysqlmysql30Mar2301:42scriptsdrwxr-xr-x.28mysqlmysql4096Mar2301:42sharedrwxr-xr-x.4mysqlmysql4096Mar2301:42sql-benchdrwxr-xr-x.2mysqlmysql136Mar2301:42support-files
3、新建 /var/lib/mysql 目录用于存放 mysq.sock(也可以新建其他的目录),并将该目录所属组更改成 myql
[root@localhostmysql]#mkdir/var/lib/mysql[root@localhostmysql]#chown-Rmysql:mysql/var/lib/mysql[root@localhostmysql]#ls-al/var/lib/mysqltotal4drwxr-xr-x.2mysqlmysql6Mar2301:51.drwxr-xr-x.26rootroot4096Mar2301:51..
4、进入 mysql 安装目录,进行初始化 mysql
[root@localhostmysql]#./scripts/mysql_install_db--user=mysql--basedir=/opt/mysql--datadir=/opt/mysql/dataInstallingMySQLsystemtables...2022-03-2301:53:510[Warning]TIMESTAMPwithimplicitDEFAULTvalueisdeprecated.Pleaseuse--explicit_defaults_for_timestampserveroption(seedocumentationformoredetails).2022-03-2301:53:510[Note]Ignoring--secure-file-privvalueasserverisrunningwith--bootstrap.2022-03-2301:53:510[Note]/opt/mysql/bin/mysqld(mysqld5.6.51)startingasprocess13346...2022-03-2301:53:5113346[Note]InnoDB:Usingatomicstorefcountbufferpoolpages2022-03-2301:53:5113346[Note]InnoDB:TheInnoDBmemoryheapisdisabled2022-03-2301:53:5113346[Note]InnoDB:Mutexesandrw_locksuseGCCatomicbuiltins2022-03-2301:53:5113346[Note]InnoDB:Memorybarrierisnotused2022-03-2301:53:5113346[Note]InnoDB:Compressedtablesusezlib1.2.112022-03-2301:53:5113346[Note]InnoDB:UsingLinuxnativeAIO2022-03-2301:53:5113346[Note]InnoDB:UsingCPUcrc32instructions2022-03-2301:53:5113346[Note]InnoDB:Initializingbufferpool,size=128.0M2022-03-2301:53:5113346[Note]InnoDB:Completedinitializationofbufferpool2022-03-2301:53:5113346[Note]InnoDB:Thefirstspecifieddatafile./ibdata1didnotexist:anewdatabasetobecreated!2022-03-2301:53:5113346[Note]InnoDB:Settingfile./ibdata1sizeto12MB2022-03-2301:53:5113346[Note]InnoDB:Databasephysicallywritesthefilefull:wait...2022-03-2301:53:5113346[Note]InnoDB:Settinglogfile./ib_logfile101sizeto48MB2022-03-2301:53:5113346[Note]InnoDB:Settinglogfile./ib_logfile1sizeto48MB2022-03-2301:53:5113346[Note]InnoDB:Renaminglogfile./ib_logfile101to./ib_logfile02022-03-2301:53:5113346[Warning]InnoDB:Newlogfilescreated,LSN=457812022-03-2301:53:5113346[Note]InnoDB:Doublewritebuffernotfound:creatingnew2022-03-2301:53:5113346[Note]InnoDB:Doublewritebuffercreated2022-03-2301:53:5113346[Note]InnoDB:128rollbacksegment(s)areactive.2022-03-2301:53:5113346[Warning]InnoDB:Creatingforeignkeyconstraintsystemtables.2022-03-2301:53:5113346[Note]InnoDB:Foreignkeyconstraintsystemtablescreated2022-03-2301:53:5113346[Note]InnoDB:Creatingtablespaceanddatafilesystemtables.2022-03-2301:53:5113346[Note]InnoDB:Tablespaceanddatafilesystemtablescreated.2022-03-2301:53:5113346[Note]InnoDB:Waitingforpurgetostart2022-03-2301:53:5113346[Note]InnoDB:5.6.51started;logsequencenumber02022-03-2301:53:5113346[Note]RSAprivatekeyfilenotfound:/opt/mysql/data//private_key.pem.Someauthenticationpluginswillnotwork.2022-03-2301:53:5113346[Note]RSApublickeyfilenotfound:/opt/mysql/data//public_key.pem.Someauthenticationpluginswillnotwork.2022-03-2301:53:5113346[Note]Binlogend2022-03-2301:53:5113346[Note]InnoDB:FTSoptimizethreadexiting.2022-03-2301:53:5113346[Note]InnoDB:Startingshutdown...2022-03-2301:53:5313346[Note]InnoDB:Shutdowncompleted;logsequencenumber1625977OKFillinghelptables...2022-03-2301:53:530[Warning]TIMESTAMPwithimplicitDEFAULTvalueisdeprecated.Pleaseuse--explicit_defaults_for_timestampserveroption(seedocumentationformoredetails).2022-03-2301:53:530[Note]Ignoring--secure-file-privvalueasserverisrunningwith--bootstrap.2022-03-2301:53:530[Note]/opt/mysql/bin/mysqld(mysqld5.6.51)startingasprocess13368...2022-03-2301:53:5313368[Note]InnoDB:Usingatomicstorefcountbufferpoolpages2022-03-2301:53:5313368[Note]InnoDB:TheInnoDBmemoryheapisdisabled2022-03-2301:53:5313368[Note]InnoDB:Mutexesandrw_locksuseGCCatomicbuiltins2022-03-2301:53:5313368[Note]InnoDB:Memorybarrierisnotused2022-03-2301:53:5313368[Note]InnoDB:Compressedtablesusezlib1.2.112022-03-2301:53:5313368[Note]InnoDB:UsingLinuxnativeAIO2022-03-2301:53:5313368[Note]InnoDB:UsingCPUcrc32instructions2022-03-2301:53:5313368[Note]InnoDB:Initializingbufferpool,size=128.0M2022-03-2301:53:5313368[Note]InnoDB:Completedinitializationofbufferpool2022-03-2301:53:5313368[Note]InnoDB:HighestsupportedfileformatisBarracuda.2022-03-2301:53:5313368[Note]InnoDB:128rollbacksegment(s)areactive.2022-03-2301:53:5313368[Note]InnoDB:Waitingforpurgetostart2022-03-2301:53:5313368[Note]InnoDB:5.6.51started;logsequencenumber16259772022-03-2301:53:5313368[Note]RSAprivatekeyfilenotfound:/opt/mysql/data//private_key.pem.Someauthenticationpluginswillnotwork.2022-03-2301:53:5313368[Note]RSApublickeyfilenotfound:/opt/mysql/data//public_key.pem.Someauthenticationpluginswillnotwork.2022-03-2301:53:5313368[Note]Binlogend2022-03-2301:53:5313368[Note]InnoDB:FTSoptimizethreadexiting.2022-03-2301:53:5313368[Note]InnoDB:Startingshutdown...2022-03-2301:53:5513368[Note]InnoDB:Shutdowncompleted;logsequencenumber1625987OKTostartmysqldatboottimeyouhavetocopysupport-files/mysql.servertotherightplaceforyoursystemPLEASEREMEMBERTOSETAPASSWORDFORTHEMySQLrootUSER!Todoso,starttheserver,thenissuethefollowingcommands:/opt/mysql/bin/mysqladmin-urootpassword'new-password'/opt/mysql/bin/mysqladmin-uroot-hlocalhost.localdomainpassword'new-password'Alternativelyyoucanrun:/opt/mysql/bin/mysql_secure_installationwhichwillalsogiveyoutheoptionofremovingthetestdatabasesandanonymoususercreatedbydefault.Thisisstronglyrecommendedforproductionservers.Seethemanualformoreinstructions.YoucanstarttheMySQLdaemonwith:cd.;/opt/mysql/bin/mysqld_safe&YoucantesttheMySQLdaemonwithmysql-test-run.plcdmysql-test;perlmysql-test-run.plPleasereportanyproblemsathttp://bugs.mysql.com/ThelatestinformationaboutMySQLisavailableonthewebathttp://www.mysql.comSupportMySQLbybuyingsupport/licensesathttp://shop.mysql.comNewdefaultconfigfilewascreatedas/opt/mysql/my.cnfandwillbeusedbydefaultbytheserverwhenyoustartit.Youmayeditthisfiletochangeserversettings
4、复制和修改配置文件
[root@localhostmysql]#cp./support-files/my-default.cnf/etc/my.cnf[root@localhostmysql]#chownmysql:mysql/etc/my.cnf[root@localhostmysql]#chmod644/etc/my.cnf
my.cnf 配置文件内容如下:(这里根据自己的需求修改其他配置)
注意以下几点:
socket
写上面我们第三步新建的那个目录
basedir
为 mysql 安装目录
datadir
为数据目录(这里是 mysql 安装目录下的 data 目录)
[mysql]#设置mysql客户端默认字符集default-character-set=utf8socket=/var/lib/mysql/mysql.sock[mysqld]skip-name-resolve#设置13306端口port=13306socket=/var/lib/mysql/mysql.sock#设置mysql的安装目录basedir=/opt/mysql#设置mysql数据库的数据的存放目录datadir=/opt/mysql/data#允许最大连接数max_connections=200#服务端使用的字符集默认为8比特编码的latin1字符集character-set-server=utf8#创建新表时将使用的默认存储引擎default-storage-engine=INNODBlower_case_table_name=1max_allowed_packet=16M
5、复制启动脚本到资源目录
[root@localhostmysql]#cp./support-files/mysql.server/etc/rc.d/init.d/mysqld[root@localhostmysql]#chmod+x/etc/rc.d/init.d/mysqld[root@localhostmysql]#chownmysql:mysql/etc/rc.d/init.d/mysqld
6、修改启动脚本
[root@localhostmysql]#vim/etc/rc.d/init.d/mysqld
注:因为,我没有将 mysql 安装在 /usr/local/mysql 目录下,所以在启动文件里需要修改以下两个值
basedir=/opt/mysqldatadir=/opt/mysql/data
7、将 mysqld 服务加入到系统服务里面
[root@localhostmysql]#chkconfig--addmysqld[root@localhostmysql]#chkconfig--listmysqldNote:ThisoutputshowsSysVservicesonlyanddoesnotincludenativesystemdservices.SysVconfigurationdatamightbeoverriddenbynativesystemdconfiguration.Ifyouwanttolistsystemdservicesuse'systemctllist-unit-files'.Toseeservicesenabledonparticulartargetuse'systemctllist-dependencies[target]'.mysqld0:off1:off2:on3:on4:on5:on6:off
8、使用命令 systemctl 启动 mysql 服务(Active 状态为 active (running) 即为启动成功)
[root@localhostmysql]#systemctlstartmysql[root@localhostmysql]#systemctlstatusmysql●mysqld.service-LSB:startandstopMySQLLoaded:loaded(/etc/rc.d/init.d/mysqld;bad;vendorpreset:disabled)Active:active(running)sinceWed2022-03-2302:11:17EDT;5sagoDocs:man:systemd-sysv-generator(8)Process:13452ExecStart=/etc/rc.d/init.d/mysqldstart(code=exited,status=0/SUCCESS)CGroup:/system.slice/mysqld.service├─13463/bin/sh/opt/mysql/bin/mysqld_safe--datadir=/opt/mysql/data--pid-file=/opt/mysql/data/lo...└─13688/opt/mysql/bin/mysqld--basedir=/opt/mysql--datadir=/opt/mysql/data--plugin-dir=/opt/mys...Mar2302:11:16localhost.localdomainsystemd[1]:StartingLSB:startandstopMySQL...Mar2302:11:16localhost.localdomainmysqld[13452]:StartingMySQL.Loggingto'/opt/mysql/data/localhost....r'.Mar2302:11:17localhost.localdomainmysqld[13452]:SUCCESS!Mar2302:11:17localhost.localdomainsystemd[1]:StartedLSB:startandstopMySQL.Hint:Somelineswereellipsized,use-ltoshowinfull.
9、将 mysql 客户端配置到环境变量中,并使配置生效
[root@localhostmysql]#vim/etc/profile#在末尾增加以下两行exportMYSQL_HOME=/opt/mysqlexportPATH=$MYSQL_HOME/bin:$PATH[root@localhostmysql]#source/etc/profile
10、测试是否能连接 mysql
注:第一次登录不需要密码,直接回车就行
[root@localhost~]#mysql-uroot-pEnterpassword:WelcometotheMySQLmonitor.Commandsendwith;or\g.YourMySQLconnectionidis1Serverversion:5.6.51MySQLCommunityServer(GPL)Copyright(c)2000,2021,Oracleand/oritsaffiliates.Allrightsreserved.OracleisaregisteredtrademarkofOracleCorporationand/oritsaffiliates.Othernamesmaybetrademarksoftheirrespectiveowners.Type'help;'or'\h'forhelp.Type'\c'toclearthecurrentinputstatement.mysql>
11、配置 root
账号的密码为 P@ssw0rd
mysql>usemysql;ReadingtableinformationforcompletionoftableandcolumnnamesYoucanturnoffthisfeaturetogetaquickerstartupwith-ADatabasechangedmysql>updateusersetpassword=password('P@ssw0rd')whereuser='root'andhost='localhost';QueryOK,1rowaffected(0.00sec)Rowsmatched:1Changed:1Warnings:0
12、设置远程主机登录
mysql>usemysql;ReadingtableinformationforcompletionoftableandcolumnnamesYoucanturnoffthisfeaturetogetaquickerstartupwith-ADatabasechangedmysql>grantallprivilegeson*.*to'root'@'%'identifiedby'P@ssw0rd'withgrantoption;QueryOK,0rowsaffected(0.00sec)
13、重启 mysqld 服务并测试登录
[root@localhost~]#systemctlrestartmysql[root@localhost~]#mysql-uroot-pEnterpassword:WelcometotheMySQLmonitor.Commandsendwith;or\g.YourMySQLconnectionidis1Serverversion:5.6.51MySQLCommunityServer(GPL)Copyright(c)2000,2021,Oracleand/oritsaffiliates.Allrightsreserved.OracleisaregisteredtrademarkofOracleCorporationand/oritsaffiliates.Othernamesmaybetrademarksoftheirrespectiveowners.Type'help;'or'\h'forhelp.Type'\c'toclearthecurrentinputstatement.mysql>showdatabases;+--------------------+|Database|+--------------------+|information_schema||mysql||performance_schema||test|+--------------------+4rowsinset(0.00sec)mysql>
至此,已完成 mysql 5.6 的安装
“centos如何离线安装mysql”的内容就介绍到这里了,感谢大家的阅读。如果想了解更多行业相关的知识可以关注亿速云网站,小编将为大家输出更多高质量的实用文章!
声明:本站所有文章资源内容,如无特殊说明或标注,均为采集网络资源。如若本站内容侵犯了原著者的合法权益,可联系本站删除。