随着mysql被oracle公司收购之后,越来越多的公司都把自己的数据库转移到了mariadb数据库上面,其实mysql数据库和mariadb数据库的区别只是换个名字而已,内在的东西一模一样,下面我们就来说一下在centos6和centos7上如何正确的安装mariadb吧
centos7上:
centos7上的yum源里是自带mariadb数据库的,所以我们就给自己的虚拟机装上mariadb的服务器端和客户端,再设置一下密码就可以使用啦。
[root@J-7~]#yum-ygroupinstallmariadbmariadb-client#安装mariadb的服务器端和客户端 Loadedplugins:fastestmirror Thereisnoinstalledgroupsfile. Mayberun:yumgroupsmarkconvert(seemanyum) base|3.6kB00:00:00 elpl|4.3kB00:00:00 Loadingmirrorspeedsfromcachedhostfile ResolvingDependencies -->Runningtransactioncheck …… Verifying:perl-IO-Compress-2.061-2.el7.noarch14/14 Installed: MySQL-python.x86_640:1.2.5-1.el7mariadb.x86_641:5.5.52-1.el7 mariadb-server.x86_641:5.5.52-1.el7mysql-connector-odbc.x86_640:5.2.5-6.el7 DependencyInstalled: libtool-ltdl.x86_640:2.4.2-21.el7_2perl-Compress-Raw-Bzip2.x86_640:2.061-3.el7 perl-Compress-Raw-Zlib.x86_641:2.061-4.el7perl-DBD-MySQL.x86_640:4.023-5.el7 perl-DBI.x86_640:1.627-4.el7perl-Data-Dumper.x86_640:2.145-3.el7 perl-IO-Compress.noarch0:2.061-2.el7perl-Net-Daemon.noarch0:0.48-5.el7 perl-PlRPC.noarch0:0.2020-14.el7unixODBC.x86_640:2.3.1-11.el7 Complete! [root@J-7~]#systemctlstartmariadb.service#开启服务 [root@J-7~]#systemctlenablemariadb.service#设置为开机启动 Createdsymlinkfrom/etc/systemd/system/multi-user.target.wants/mariadb.serviceto/usr/lib/systemd/system/mariadb.service. [root@J-7~]#ss-nutl#查看一下Mariadb的3306端口开启了没有 NetidStateRecv-QSend-QLocalAddress:PortPeerAddress:Port udpUNCONN00*:12518*:* udpUNCONN00*:29118*:* udpUNCONN00*:68*:* udpUNCONN00*:68*:* udpUNCONN00:::12518:::* udpUNCONN00:::24061:::* tcpLISTEN050*:3306*:* tcpLISTEN0128*:22*:* tcpLISTEN0100127.0.0.1:25*:* tcpLISTEN0128:::22:::* tcpLISTEN0100::1:25:::* [root@J-7~]#mysql_secure_installation#用它自带的这个命令设置一些最基础的东西 NOTE:RUNNINGALLPARTSOFTHISSCRIPTISRECOMMENDEDFORALLMariaDB SERVERSINPRODUCTIONUSE!PLEASEREADEACHSTEPCAREFULLY! InordertologintoMariaDBtosecureit,we'llneedthecurrent passwordfortherootuser.Ifyou'vejustinstalledMariaDB,and youhaven'tsettherootpasswordyet,thepasswordwillbeblank,soyoushouldjustpressenterhere. Entercurrentpasswordforroot(enterfornone):#没有密码要创建,按回车即可 ERROR1045(28000):Accessdeniedforuser'root'@'localhost'(usingpassword:YES) Entercurrentpasswordforroot(enterfornone): ERROR1045(28000):Accessdeniedforuser'root'@'localhost'(usingpassword:YES) Entercurrentpasswordforroot(enterfornone): OK,successfullyusedpassword,movingon... SettingtherootpasswordensuresthatnobodycanlogintotheMariaDB rootuserwithouttheproperauthorisation. Setrootpassword?[Y/n]y#是否设置密码 Newpassword:#输入密码 Re-enternewpassword:#确认密码 Passwordupdatedsuccessfully! Reloadingprivilegetables.. ...Success! Bydefault,aMariaDBinstallationhasananonymoususer,allowinganyone tologintoMariaDBwithouthavingtohaveauseraccountcreatedfor them.Thisisintendedonlyfortesting,andtomaketheinstallation goabitsmoother.Youshouldremovethembeforemovingintoa productionenvironment. Removeanonymoususers?[Y/n]y#移除匿名登录? ...Success! Normally,rootshouldonlybeallowedtoconnectfrom'localhost'.This ensuresthatsomeonecannotguessattherootpasswordfromthenetwork. Disallowrootloginremotely?[Y/n]no#关闭远程登录? ...Success! Bydefault,MariaDBcomeswithadatabasenamed'test'thatanyonecan access.Thisisalsointendedonlyfortesting,andshouldberemoved beforemovingintoaproductionenvironment. Removetestdatabaseandaccesstoit?[Y/n]y#移除测试数据? -Droppingtestdatabase... ...Success! -Removingprivilegesontestdatabase... ...Success! Reloadingtheprivilegetableswillensurethatallchangesmadesofar willtakeeffectimmediately. Reloadprivilegetablesnow?[Y/n]y#确定你的配置? ...Success! Cleaningup... Alldone!Ifyou'vecompletedalloftheabovesteps,yourMariaDB installationshouldnowbesecure. ThanksforusingMariaDB! [root@J-7~]#mysql-uroot-p#登录 Enterpassword:#输入密码 WelcometotheMariaDBmonitor.Commandsendwith;or\g. YourMariaDBconnectionidis12 Serverversion:5.5.52-MariaDBMariaDBServer Copyright(c)2000,2016,Oracle,MariaDBCorporationAbandothers. Type'help;'or'\h'forhelp.Type'\c'toclearthecurrentinputstatement. MariaDB[(none)]>#正常使用
centos6:
centos6上默认的数据库是mysql5.5的,这里我们要安装mariadb10.0的就得自己去Mariadb数据库的官方网站http://mariadb.org 下一个,来进行安装,如果你已经安装了自己卸载干净就行,我这里环境是最小安装的,这里我以二进制编译安装为例:
[root@localhost~]#rz#把自己下载的包传上来 [root@localhost~]#ls anaconda-ks.cfginstall.loginstall.log.syslogmariadb-5.5.57-linux-x86_64.tar.gz [root@localhost~]#getentpasswdmysql#检查系统是否已经有了mysql用户的信息 [root@localhost~]#useradd-r-d/app/data-s/sbin/nologin-u36mysql#创建mysql用户,指定家目录和默认shell [root@localhost~]#idmysql#查看一下用户信息 uid=36(mysql)gid=36(mysql)groups=36(mysql) [root@localhost~]#ll/app/data-d#看一下我们计划存放数据库的目录信息 drwxr-xr-x2rootroot4096Jul2800:34/app/data [root@localhost~]#chownmysql:mysql/app/data/#修改目录的属组和属主 [root@localhost~]#tarxfmariadb-5.5.57-linux-x86_64.tar.gz-C/usr/local/#将二进制包解压放到指定位置 [root@localhost~]#cd/usr/local/ [root@localhostlocal]#ll total44 drwxr-xr-x.2rootroot4096Sep232011bin drwxr-xr-x.2rootroot4096Sep232011etc drwxr-xr-x.2rootroot4096Sep232011games drwxr-xr-x.2rootroot4096Sep232011include drwxr-xr-x.2rootroot4096Sep232011lib drwxr-xr-x.2rootroot4096Sep232011lib64 drwxr-xr-x.2rootroot4096Sep232011libexec drwxr-xr-x12rootroot4096Jul2800:38mariadb-5.5.57-linux-x86_64 drwxr-xr-x.2rootroot4096Sep232011sbin drwxr-xr-x.5rootroot4096Jul2720:51share drwxr-xr-x.2rootroot4096Sep232011src [root@localhostlocal]#ln-smariadb-5.5.57-linux-x86_64/mysql/#给mariadb写一个软连接,切记不要后面的/ ln:target`mysql/'isnotadirectory:Nosuchfileordirectory [root@localhostlocal]#ln-smariadb-5.5.57-linux-x86_64/mysql [root@localhostlocal]#ll#查看一下 total44 drwxr-xr-x.2rootroot4096Sep232011bin drwxr-xr-x.2rootroot4096Sep232011etc drwxr-xr-x.2rootroot4096Sep232011games drwxr-xr-x.2rootroot4096Sep232011include drwxr-xr-x.2rootroot4096Sep232011lib drwxr-xr-x.2rootroot4096Sep232011lib64 drwxr-xr-x.2rootroot4096Sep232011libexec drwxr-xr-x12rootroot4096Jul2800:38mariadb-5.5.57-linux-x86_64 lrwxrwxrwx1rootroot28Jul2800:39mysql->mariadb-5.5.57-linux-x86_64/ drwxr-xr-x.2rootroot4096Sep232011sbin drwxr-xr-x.5rootroot4096Jul2720:51share drwxr-xr-x.2rootroot4096Sep232011src [root@localhostlocal]#llmysql/#看一下mysql文件夹的属组和属主 total192 drwxr-xr-x2rootroot4096Jul2800:38bin -rw-r--r--1wangwang17987Jul1904:33COPYING drwxr-xr-x3rootroot4096Jul2800:38data -rw-r--r--1wangwang8245Jul1904:33EXCEPTIONS-CLIENT drwxr-xr-x3rootroot4096Jul2800:38include -rw-r--r--1wangwang8694Jul1904:33INSTALL-BINARY drwxr-xr-x3rootroot4096Jul2800:38lib drwxr-xr-x4rootroot4096Jul2800:38man drwxr-xr-x11rootroot4096Jul2800:37mysql-test -rw-r--r--1wangwang108813Jul1904:33README drwxr-xr-x2rootroot4096Jul2800:38scripts drwxr-xr-x27rootroot4096Jul2800:38share drwxr-xr-x4rootroot4096Jul2800:38sql-bench drwxr-xr-x3rootroot4096Jul2800:38support-files [root@localhostlocal]#chgrp-Rmysqlmysql/#修改mysql的属组 [root@localhostlocal]#llmysql/ total192 drwxr-xr-x2rootmysql4096Jul2800:38bin -rw-r--r--1wangmysql17987Jul1904:33COPYING drwxr-xr-x3rootmysql4096Jul2800:38data -rw-r--r--1wangmysql8245Jul1904:33EXCEPTIONS-CLIENT drwxr-xr-x3rootmysql4096Jul2800:38include -rw-r--r--1wangmysql8694Jul1904:33INSTALL-BINARY drwxr-xr-x3rootmysql4096Jul2800:38lib drwxr-xr-x4rootmysql4096Jul2800:38man drwxr-xr-x11rootmysql4096Jul2800:37mysql-test -rw-r--r--1wangmysql108813Jul1904:33README drwxr-xr-x2rootmysql4096Jul2800:38scripts drwxr-xr-x27rootmysql4096Jul2800:38share drwxr-xr-x4rootmysql4096Jul2800:38sql-bench drwxr-xr-x3rootmysql4096Jul2800:38support-files [root@localhostlocal]#ll/etc/my.cnf#这个是系统自带的配置文件 -rw-r--r--.1rootroot251Jan2706:25/etc/my.cnf [root@localhostlocal]#rpm-qf/etc/my.cnf#这个配置文件来自mysql的包 mysql-libs-5.1.73-8.el6_8.x86_64 [root@localhostlocal]#cat/etc/my.cnf#看一下这个配置的内容 [mysqld] datadir=/var/lib/mysql socket=/var/lib/mysql/mysql.sock user=mysql #Disablingsymbolic-linksisrecommendedtopreventassortedsecurityrisks symbolic-links=0 [mysqld_safe] log-error=/var/log/mysqld.log pid-file=/var/run/mysqld/mysqld.pid [root@localhostlocal]#cdmysql#进入到mysql文件夹 [root@localhostmysql]#ls bindataincludelibmysql-testscriptssql-bench COPYINGEXCEPTIONS-CLIENTINSTALL-BINARYmanREADMEsharesupport-files [root@localhostmysql]#cdsupport-files/#查看一下support-files文件夹,里面全部都是模板文件 [root@localhostsupport-files]#ls binary-configuremy-innodb-heavy-4G.cnfmy-small.cnfmysql.server magicmy-large.cnfmysqld_multi.serverSELinux my-huge.cnfmy-medium.cnfmysql-log-rotate [root@localhostsupport-files]#mkdir/etc/mysql#创建一个存放我们自己配置的文件夹 [root@localhostsupport-files]#cpmy-huge.cnf/etc/mysql/my.cnf#复制一个模板配置修改成适合自己用的 [root@localhostsupport-files]#vim/etc/mysql/my.cnf …… [mysqld] datadir=/app/data#存放目录 innodb_file_per_table=on#使用引擎(可不写) skip_name_resolve=on#禁止解析(可不写) port=3306 socket=/tmp/mysql.sock skip-external-locking key_buffer_size=384M max_allowed_packet=1M table_open_cache=512 sort_buffer_size=2M read_buffer_size=2M …… [root@localhostsupport-files]#cd/usr/local/mysql/#进入到mysql文件夹 [root@localhostmysql]#scripts/mysql_install_db--user=mysql--datadir=/app/data/#执行包带的脚本并指定存放地址和执行用户 InstallingMariaDB/MySQLsystemtablesin'/app/data/'...#一些关键说明 1707284:33:26[Warning]'THREAD_CONCURRENCY'isdeprecatedandwillberemovedinafuturerelease. 1707284:33:26[Note]./bin/mysqld(mysqld5.5.57-MariaDB)startingasprocess1872... OK Fillinghelptables... 1707284:33:27[Warning]'THREAD_CONCURRENCY'isdeprecatedandwillberemovedinafuturerelease. 1707284:33:27[Note]./bin/mysqld(mysqld5.5.57-MariaDB)startingasprocess1881... OK Tostartmysqldatboottimeyouhavetocopy support-files/mysql.servertotherightplaceforyoursystem PLEASEREMEMBERTOSETAPASSWORDFORTHEMariaDBrootUSER! Todoso,starttheserver,thenissuethefollowingcommands: './bin/mysqladmin'-urootpassword'new-password' './bin/mysqladmin'-uroot-hlocalhost.localdomainpassword'new-password' Alternativelyyoucanrun: './bin/mysql_secure_installation' whichwillalsogiveyoutheoptionofremovingthetest databasesandanonymoususercreatedbydefault.Thisis stronglyrecommendedforproductionservers. SeetheMariaDBKnowledgebaseathttp://mariadb.com/kborthe MySQLmanualformoreinstructions. YoucanstarttheMariaDBdaemonwith: cd'.';./bin/mysqld_safe--datadir='/app/data/' YoucantesttheMariaDBdaemonwithmysql-test-run.pl cd'./mysql-test';perlmysql-test-run.pl ………… https://mariadb.org/get-involved/ [root@localhostmysql]#ls/app/data/#查看一下我们存放数据库的文件夹 aria_log.00000001mysqlmysql-bin.000002performance_schema aria_log_controlmysql-bin.000001mysql-bin.indextest [root@localhostmysql]#cdsupport-files/ [root@localhostmysql]#pwd /usr/local/mysql [root@localhostmysql]#ll/app/data/ total1084 -rw-rw----1mysqlmysql16384Jul2804:33aria_log.00000001 -rw-rw----1mysqlmysql52Jul2804:33aria_log_control drwx------2mysqlroot4096Jul2804:33mysql -rw-rw----1mysqlmysql30379Jul2804:33mysql-bin.000001 -rw-rw----1mysqlmysql1038814Jul2804:33mysql-bin.000002 -rw-rw----1mysqlmysql38Jul2804:33mysql-bin.index drwx------2mysqlmysql4096Jul2804:33performance_schema drwx------2mysqlroot4096Jul2804:33test [root@localhostmysql]#ls bindataincludelibmysql-testscriptssql-bench COPYINGEXCEPTIONS-CLIENTINSTALL-BINARYmanREADMEsharesupport-files [root@localhostmysql]#cpsupport-files/mysql.server/etc/init.d/mysqld#复制一个启动服务脚本 [root@localhostmysql]#chkconfig--listmysqld#查看服务 servicemysqldsupportschkconfig,butisnotreferencedinanyrunlevel(run'chkconfig--addmysqld') [root@localhostmysql]#chkconfig--addmysqld#把mysqld服务加进去 [root@localhostmysql]#chkconfigmysqldon#开机自启 [root@localhostmysql]#chkconfig--listmysqld#看一下服务 mysqld 0:off 1:off 2:on 3:on 4:on 5:on 6:off [root@localhostmysql]#servicemysqldstart#启动服务 StartingMySQL.17072804:40:26mysqld_safeLoggingto'/var/log/mysqld.log'.#因没有日志文件夹报错 17072804:40:26mysqld_safeStartingmysqlddaemonwithdatabasesfrom/app/data /usr/local/mysql/bin/mysqld_safe_helper:Can'tcreate/writetofile'/var/log/mysqld.log'(Errcode:13) ERROR! [root@localhostmysql]#cat/etc/my.cnf#看一下系统自带的mysql配置 [mysqld] datadir=/var/lib/mysql socket=/var/lib/mysql/mysql.sock user=mysql #Disablingsymbolic-linksisrecommendedtopreventassortedsecurityrisks symbolic-links=0 [mysqld_safe] log-error=/var/log/mysqld.log#日志正确存放地址 pid-file=/var/run/mysqld/mysqld.pid [root@localhostmysql]#touch/var/log/mysqld.log#创建一个日志文件 [root@localhostmysql]#chownmysql/var/log/mysqld.log#修改属主,给它个写的权限 [root@localhostmysql]#servermysqldstart -bash:server:commandnotfound [root@localhostmysql]#servicemysqldstart#启动服务 StartingMySQL.17072804:45:01mysqld_safeLoggingto'/var/log/mysqld.log'. 17072804:45:01mysqld_safeStartingmysqlddaemonwithdatabasesfrom/app/data .SUCCESS! [root@localhostmysql]#ss-ntl#查看一下端口,3306开启了 StateRecv-QSend-QLocalAddress:PortPeerAddress:Port LISTEN050*:3306*:* LISTEN0128:::22:::* LISTEN0128*:22*:* LISTEN0100::1:25:::* LISTEN0100127.0.0.1:25*:* [root@localhostmysql]#mysql#直接登录使用,报错命令没找到 -bash:mysql:commandnotfound [root@localhostmysql]#pwd /usr/local/mysql [root@localhostmysql]#ls bindataincludelibmysql-testscriptssql-bench COPYINGEXCEPTIONS-CLIENTINSTALL-BINARYmanREADMEsharesupport-files [root@localhostmysql]#cdbin/ [root@localhostbin]#vim/etc/profile.d/mysql.sh#写一个配置文件,把mysql放到bin下 exportPATH=/usr/local/mysql/bin:$PATH [root@localhostbin]#./etc/profile.d/mysql.sh#执行一下 [root@localhostbin]#mysql#登录一下,可以匿名登录肯定不行啊,出去设置一下 WelcometotheMariaDBmonitor.Commandsendwith;or\g. YourMariaDBconnectionidis2 Serverversion:5.5.57-MariaDBMariaDBServer Copyright(c)2000,2017,MariaDBCorporationAbandothers. Type'help;'or'\h'forhelp.Type'\c'toclearthecurrentinputstatement. MariaDB[(none)]>exit Bye [root@localhostbin]#mysql_se mysql_secure_installationmysql_setpermission [root@localhostbin]#mysql_secure_installation#执行脚本,完成基本的安全设置 /usr/local/mysql/bin/mysql_secure_installation:line393:find_mysql_client:commandnotfound NOTE:RUNNINGALLPARTSOFTHISSCRIPTISRECOMMENDEDFORALLMariaDB SERVERSINPRODUCTIONUSE!PLEASEREADEACHSTEPCAREFULLY! InordertologintoMariaDBtosecureit,soyoushouldjustpressenterhere. Entercurrentpasswordforroot(enterfornone): OK,movingon... SettingtherootpasswordensuresthatnobodycanlogintotheMariaDB rootuserwithouttheproperauthorisation. Setrootpassword?[Y/n]y#设置密码? Newpassword:#第一次输入密码 Re-enternewpassword:#确认密码 Passwordupdatedsuccessfully! Reloadingprivilegetables.. ...Success! Bydefault,andtomaketheinstallation goabitsmoother.Youshouldremovethembeforemovingintoa productionenvironment. Removeanonymoususers?[Y/n]y#禁止匿名用户? ...Success! Normally,rootshouldonlybeallowedtoconnectfrom'localhost'.This ensuresthatsomeonecannotguessattherootpasswordfromthenetwork. Disallowrootloginremotely?[Y/n]n#禁止root远程登录? ...skipping. Bydefault,andshouldberemoved beforemovingintoaproductionenvironment. Removetestdatabaseandaccesstoit?[Y/n]y#移除系统的测试数据? -Droppingtestdatabase... ...Success! -Removingprivilegesontestdatabase... ...Success! Reloadingtheprivilegetableswillensurethatallchangesmadesofar willtakeeffectimmediately. Reloadprivilegetablesnow?[Y/n]y#确认加载配置? ...Success! Cleaningup... Alldone!Ifyou'vecompletedalloftheabovesteps,yourMariaDB installationshouldnowbesecure. ThanksforusingMariaDB! [root@localhostbin]#mysql-uroot-p#登录 Enterpassword:#输入密码 WelcometotheMariaDBmonitor.Commandsendwith;or\g. YourMariaDBconnectionidis10 Serverversion:5.5.57-MariaDBMariaDBServer Copyright(c)2000,MariaDBCorporationAbandothers. Type'help;'or'\h'forhelp.Type'\c'toclearthecurrentinputstatement. MariaDB[(none)]>#安装完成
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。