MysqL多实例的配置
通过上文 CentOS 6.8 编译安装MysqL5.5.32 ,我们完成了编译安装,接下配置多实例
5,添加多实例目录
[root@db01application]#mkdir-p/data/{3306,3307}/data [root@db01application]#tree/data/ /data/ ├──3306 │└──data └──3307 └──data,
[root@db01/]#cd/ [root@db01/]#rz-ydata.zip [root@db01/]#unzipdata.zip [root@db01/]#treedata data ├──3306##3306实例目录 │├──data │├──my.cnf │└──MysqL └──3307 ├──data ├──my.cnf └──MysqL
##多实例 文件对比 配置文件中 只有字符串 3306与3307,与serverID 的不同
find/data-typef-name"MysqL"|xargschmod+x chown-RMysqL.MysqL/data
cd/application/MysqL/scripts ./MysqL_install_db--basedir=/application/MysqL--datadir=/data/3306/data--user=MysqL ./MysqL_install_db--basedir=/application/MysqL/--datadir=/data/3307/data--user=MysqL ##提示:--basedir=/application/MysqL/为MysqL的安装路径,--datadir为数据文件目录。 另,注意MysqL_install_db和MysqL5.1的路径不同,MysqL5.1不在MysqLbin路径下了。
编译过程,注意要有2个OK 才算成功
[root@db02scripts]#./MysqL_install_db--basedir=/application/MysqL--datadir=/data/3306/data--user=MysqL WARNING:Thehost'db02'couldnotbelookedupwithresolveip. Thisprobablymeansthatyourlibclibrariesarenot100%compatible withthisbinaryMysqLversion.TheMysqLdaemon,MysqLd,shouldwork normallywiththeexceptionthathostnameresolvingwillnotwork. ThismeansthatyoushoulduseIPaddressesinsteadofhostnames whenspecifyingMysqLprivileges! InstallingMysqLsystemtables... OK#<==两个OK是初始化成功的标志。 Fillinghelptables... OK#<==两个OK是初始化成功的标志。 TostartMysqLdatboottimeyouhavetocopy support-files/MysqL.servertotherightplaceforyoursystem PLEASEREMEMBERTOSETAPASSWORDFORTHEMysqLrootUSER! Todoso,starttheserver,thenissuethefollowingcommands: /application/MysqL/bin/MysqLadmin-urootpassword'new-password' /application/MysqL/bin/MysqLadmin-uroot-hdb02password'new-password' Alternativelyyoucanrun: /application/MysqL/bin/MysqL_secure_installation whichwillalsogiveyoutheoptionofremovingthetest databasesandanonymoususercreatedbydefault.Thisis stronglyrecommendedforproductionservers. Seethemanualformoreinstructions. YoucanstarttheMysqLdaemonwith: cd/application/MysqL;/application/MysqL/bin/MysqLd_safe& YoucantesttheMysqLdaemonwithMysqL-test-run.pl cd/application/MysqL/MysqL-test;perlMysqL-test-run.pl Pleasereportanyproblemswiththe/application/MysqL/scripts/MysqLbugscript! ###请注意如下几行英文的说明及报错 Newdefaultconfigfilewascreatedas/application/MysqL//my.cnfand willbeusedbydefaultbytheserverwhenyoustartit. Youmayeditthisfiletochangeserversettings #从上文说明中可以指导MysqL的默认配置文件已经变到了/application/MysqL//my.cnf WARNING:Defaultconfigfile/etc/my.cnfexistsonthesystem ThisfilewillbereadbydefaultbytheMysqLserver Ifyoudonotwanttousethis,eitherremoveit,orusethe --defaults-fileargumenttoMysqLd_safewhenstartingtheserver #从上文说明中可以看到数据库启动时会读取/etc/my.cnf,因此有可能会导致无法启动,避免的方法就是使用MysqLd_safe启动服务时采用--defaults-file参数指定配置文件,前文已将/etc/my.cnf改名了,所以,就不需要指定参数了,这里是一个坑,读者要注意。 此步骤必须要初始化成功,否则,后面会出现登录不了数据库等各种问题。 [root@oldboy~]#MysqL ERROR1045(28000):Accessdeniedforuser'root'@'localhost'(usingpassword:NO) 解决办法:重新初始化数据库即可,此问题一般都是数据库初始化问题,或者数据库文件损坏,以及目录权限问题
9,MysqL 初始化原理
初始化数据库的就是加载MysqL自带的库与表 例如:生成的test及MysqL库表等。
[root@db02scripts]#ls-l/data/3306/data/ total143372 -rw-rw----1MysqLMysqL134217728Apr2903:32ibdata1 -rw-rw----1MysqLMysqL4194304Apr2903:32ib_logfile0 -rw-rw----1MysqLMysqL4194304Apr2903:32ib_logfile1 -rw-rw----1MysqLMysqL4194304Apr2903:32ib_logfile2 drwx------2MysqLroot4096Apr2903:31MysqL##用于存放管理MysqL数据 drwx------2MysqLMysqL4096Apr2903:31performance_schema#内部性能库 drwx------2MysqLroot4096Apr2903:31test##测试库
10,启动MysqL 命令 多实例(3306/3307)
[root@db02scripts]#/data/3306/MysqLstart##启动脚本见百度云连接 StartingMysqL... [root@db02scripts]#/data/3307/MysqLstart StartingMysqL... [root@db02scripts]#ps-ef|grep330 root134261011:32pts/100:00:00/bin/sh/application/MysqL/bin/MysqLd_safe--defaults-file=/data/3306/my.cnf MysqL1415013426011:32pts/100:00:05/application/MysqL-5.5.32/bin/MysqLd--defaults-file=/data/3306/my.cnf--basedir=/application/MysqL--datadir=/data/3306/data--plugin-dir=/application/MysqL/lib/plugin--user=MysqL--log-error=/data/3306/MysqL_oldboy3306.err--open-files-limit=1024--pid-file=/data/3306/MysqLd.pid--socket=/data/3306/MysqL.sock--port=3306 root178401012:57pts/100:00:00/bin/sh/application/MysqL/bin/MysqLd_safe--defaults-file=/data/3307/my.cnf MysqL18540178401512:57pts/100:00:01/application/MysqL-5.5.32/bin/MysqLd--defaults-file=/data/3307/my.cnf--basedir=/application/MysqL--datadir=/data/3307/data--plugin-dir=/application/MysqL/lib/plugin--user=MysqL--log-error=/data/3307/MysqL_oldboy3307.err--open-files-limit=1024--pid-file=/data/3307/MysqLd.pid--socket=/data/3307/MysqL.sock--port=3307 root185581286012:57pts/100:00:00grep--color=auto330 ##如果启动失败,请检查日志,路径是在每个实例下都有个err文件,例如下面的3306 [root@db02scripts]#vi/data/3306/MysqL_oldboy3306.err
[root@db02scripts]#MysqL-uroot-p-S/data/3306/MysqL.sock#-S指定要启动实例的socket-bash:MysqL:commandnotfound#报错是因为没有设定环境变量 解决方法的两种思路:(建议使用第二种) 1)将MysqL路径添加到环境变量 echo"PATH=$PATH:/application/MysqL/bin/">>/etc/profile source/etc/profilep 2)将MysqL需要执行的文件或脚本,拷贝到第一个已经有环境变量权限的目录下,去执行。 cp/application/MysqL/bin/*/usr/local/sbin/ 再次连接,登录3306 [root@db02~]#MysqL-uroot-p-S/data/3306/MysqL.sock [root@db02~]#MysqL-uroot-p-S/data/3307/MysqL.sock Enterpassword:WelcometotheMysqLmonitor.Commandsendwith;or\g.YourMysqLconnectionidis2Serverversion:5.5.32-logSourcedistributionCopyright(c)2000,2013,Oracleand/oritsaffiliates.Allrightsreserved.OracleisaregisteredtrademarkofOracleCorporationand/oritsaffiliates.Othernamesmaybetrademarksoftheirrespectiveowners.Type'help;'or'\h'forhelp.Type'\c'toclearthecurrentinputstatement.MysqL>
12,添加开机自启动 (多实例 multi instances)
[root@db02~]#echo"#MysqLmultiinstances">>/etc/rc.local#添加注释,及实例启动项 [root@db02~]#echo"/data/3306/MysqLstart">>/etc/rc.local [root@db02~]#echo"/data/3307/MysqLstart">>/etc/rc.loca
l
13,排错总结
MysqL多实例启动故障排错说明
原文链接:https://www.f2er.com/centos/377766.html