centos 6.9安装mysql的详细教程
1、确认mysql是否已安装,有下面的代码可知
[root@cdh1zjl]#yumlistinstalledmysql* Loadedplugins:fastestmirror,refresh-packagekit,security Loadingmirrorspeedsfromcachedhostfile *base:mirrors.zju.edu.cn *extras:mirrors.aliyun.com *updates:mirrors.aliyun.com InstalledPackages MySQL-python.x86_641.2.3-0.3.c1.1.el6@base mysql-libs.x86_645.1.73-8.el6_8@anaconda-CentOS-201703281317.x86_64/6.9
2、卸载已安装的mysql,建议使用yum命令,因为yum命令可以自动删除与mysql相关的依赖;如果使用rpm命令,则还需要手动去删除和mysql相关的文件,比较麻烦
[root@cdh1zjl]#yumremoveMySQL-python.x86_64mysql-libs.x86_64 Loadedplugins:fastestmirror,refresh-packagekit,security SettingupRemoveProcess ResolvingDependencies -->Runningtransactioncheck --->PackageMySQL-python.x86_640:1.2.3-0.3.c1.1.el6willbeerased -->ProcessingDependency:MySQL-pythonforpackage:cloudera-manager-agent-5.11.1-1.cm5111.p0.9.el6.x86_64 --->Packagemysql-libs.x86_640:5.1.73-8.el6_8willbeerased -->ProcessingDependency:libmysqlclient.so.16()(64bit)forpackage:2:postfix-2.6.6-8.el6.x86_64 -->ProcessingDependency:libmysqlclient.so.16(libmysqlclient_16)(64bit)forpackage:2:postfix-2.6.6-8.el6.x86_64 -->ProcessingDependency:mysql-libsforpackage:2:postfix-2.6.6-8.el6.x86_64 -->Runningtransactioncheck --->Packagecloudera-manager-agent.x86_640:5.11.1-1.cm5111.p0.9.el6willbeerased --->Packagepostfix.x86_642:2.6.6-8.el6willbeerased -->ProcessingDependency:/usr/sbin/sendmailforpackage:redhat-lsb-core-4.0-7.el6.centos.x86_64 -->ProcessingDependency:/usr/sbin/sendmailforpackage:cronie-1.4.4-16.el6_8.2.x86_64 -->Runningtransactioncheck --->Packagecronie.x86_640:1.4.4-16.el6_8.2willbeerased -->ProcessingDependency:cronie=1.4.4-16.el6_8.2forpackage:cronie-anacron-1.4.4-16.el6_8.2.x86_64 --->Packageredhat-lsb-core.x86_640:4.0-7.el6.centoswillbeerased -->ProcessingDependency:redhat-lsb-core(x86-64)=4.0forpackage:redhat-lsb-printing-4.0-7.el6.centos.x86_64 -->ProcessingDependency:redhat-lsb-core(x86-64)=4.0-7.el6.centosforpackage:redhat-lsb-4.0-7.el6.centos.x86_64 -->ProcessingDependency:redhat-lsb-core(x86-64)=4.0forpackage:redhat-lsb-graphics-4.0-7.el6.centos.x86_64 -->Runningtransactioncheck --->Packagecronie-anacron.x86_640:1.4.4-16.el6_8.2willbeerased --->Packageredhat-lsb.x86_640:4.0-7.el6.centoswillbeerased -->ProcessingDependency:redhat-lsb(x86-64)=4.0-7.el6.centosforpackage:redhat-lsb-compat-4.0-7.el6.centos.x86_64 --->Packageredhat-lsb-graphics.x86_640:4.0-7.el6.centoswillbeerased --->Packageredhat-lsb-printing.x86_640:4.0-7.el6.centoswillbeerased -->Runningtransactioncheck --->Packageredhat-lsb-compat.x86_640:4.0-7.el6.centoswillbeerased -->ProcessingDependency:/etc/cron.dforpackage:crontabs-1.10-33.el6.noarch -->ProcessingDependency:/etc/cron.dforpackage:sysstat-9.0.4-33.el6.x86_64 -->RestartingDependencyResolutionwithnewchanges. -->Runningtransactioncheck --->Packagecrontabs.noarch0:1.10-33.el6willbeerased --->Packagesysstat.x86_640:9.0.4-33.el6willbeerased -->FinishedDependencyResolution DependenciesResolved ==================================================================== PackageArchVersionRepository Size ==================================================================== Removing: MySQL-pythonx86_641.2.3-0.3.c1.1.el6@base246k mysql-libsx86_645.1.73-8.el6_8@anaconda-CentOS-201703281317.x86_64/6.9 4.0M Removingfordependencies: cloudera-manager-agentx86_645.11.1-1.cm5111.p0.9.el6@/cloudera-manager-agent-5.11.1-1.cm5111.p0.9.el6.x86_64 71M croniex86_641.4.4-16.el6_8.2@anaconda-CentOS-201703281317.x86_64/6.9 174k cronie-anacronx86_641.4.4-16.el6_8.2@anaconda-CentOS-201703281317.x86_64/6.9 43k crontabsnoarch1.10-33.el6@anaconda-CentOS-201703281317.x86_64/6.9 2.4k postfixx86_642:2.6.6-8.el6@anaconda-CentOS-201703281317.x86_64/6.9 9.7M redhat-lsbx86_644.0-7.el6.centos@anaconda-CentOS-201703281317.x86_64/6.9 0.0 redhat-lsb-compatx86_644.0-7.el6.centos@anaconda-CentOS-201703281317.x86_64/6.9 0.0 redhat-lsb-corex86_644.0-7.el6.centos@anaconda-CentOS-201703281317.x86_64/6.9 22k redhat-lsb-graphicsx86_644.0-7.el6.centos@anaconda-CentOS-201703281317.x86_64/6.9 0.0 redhat-lsb-printingx86_644.0-7.el6.centos@anaconda-CentOS-201703281317.x86_64/6.9 0.0 sysstatx86_649.0.4-33.el6@anaconda-CentOS-201703281317.x86_64/6.9 826k TransactionSummary ==================================================================== Remove13Package(s) Installedsize:86M Isthisok[y/N]:y DownloadingPackages: Runningrpm_check_debug RunningTransactionTest TransactionTestSucceeded RunningTransaction Warning:RPMDBalteredoutsideofyum. Erasing:redhat-lsb-compat-4.0-7.el6.centos.x86_641/13 Erasing:redhat-lsb-4.0-7.el6.centos.x86_642/13 Erasing:cloudera-manager-agent-5.11.1-1.cm5111.p0.9.3/13 warning:/etc/cloudera-scm-agent/config.inisavedas/etc/cloudera-scm-agent/config.ini.rpmsave Erasing:redhat-lsb-graphics-4.0-7.el6.centos.x86_644/13 Erasing:redhat-lsb-printing-4.0-7.el6.centos.x86_645/13 Erasing:redhat-lsb-core-4.0-7.el6.centos.x86_646/13 /var/tmp/rpm-tmp.jLbJUk:line1:lsb_release:commandnotfound Erasing:MySQL-python-1.2.3-0.3.c1.1.el6.x86_647/13 Erasing:sysstat-9.0.4-33.el6.x86_648/13 Erasing:crontabs-1.10-33.el6.noarch9/13 Erasing:cronie-anacron-1.4.4-16.el6_8.2.x86_6410/13 Erasing:cronie-1.4.4-16.el6_8.2.x86_6411/13 Erasing:2:postfix-2.6.6-8.el6.x86_6412/13 Erasing:mysql-libs-5.1.73-8.el6_8.x86_6413/13 Verifying:redhat-lsb-printing-4.0-7.el6.centos.x86_641/13 Verifying:cronie-anacron-1.4.4-16.el6_8.2.x86_642/13 Verifying:cronie-1.4.4-16.el6_8.2.x86_643/13 Verifying:2:postfix-2.6.6-8.el6.x86_644/13 Verifying:redhat-lsb-4.0-7.el6.centos.x86_645/13 Verifying:redhat-lsb-core-4.0-7.el6.centos.x86_646/13 Verifying:cloudera-manager-agent-5.11.1-1.cm5111.p0.9.7/13 Verifying:crontabs-1.10-33.el6.noarch8/13 Verifying:redhat-lsb-compat-4.0-7.el6.centos.x86_649/13 Verifying:MySQL-python-1.2.3-0.3.c1.1.el6.x86_6410/13 Verifying:redhat-lsb-graphics-4.0-7.el6.centos.x86_6411/13 Verifying:sysstat-9.0.4-33.el6.x86_6412/13 Verifying:mysql-libs-5.1.73-8.el6_8.x86_6413/13 Removed: MySQL-python.x86_640:1.2.3-0.3.c1.1.el6 mysql-libs.x86_640:5.1.73-8.el6_8 DependencyRemoved: cloudera-manager-agent.x86_640:5.11.1-1.cm5111.p0.9.el6 cronie.x86_640:1.4.4-16.el6_8.2 cronie-anacron.x86_640:1.4.4-16.el6_8.2 crontabs.noarch0:1.10-33.el6 postfix.x86_642:2.6.6-8.el6 redhat-lsb.x86_640:4.0-7.el6.centos redhat-lsb-compat.x86_640:4.0-7.el6.centos redhat-lsb-core.x86_640:4.0-7.el6.centos redhat-lsb-graphics.x86_640:4.0-7.el6.centos redhat-lsb-printing.x86_640:4.0-7.el6.centos sysstat.x86_640:9.0.4-33.el6 Complete!
3、用whereis命令查找mysql相关的文件,因为步骤2用yum来卸载,所以mysql被清理得很干净;如果使用rpm将会很麻烦,有很多的文件需要手动清除
[root@cdh1zjl]#whereismysql mysql:
4、查看系统中的mysql安装包
[root@cdh1zjl]#yumlistmysql* Loadedplugins:fastestmirror,refresh-packagekit,security Loadingmirrorspeedsfromcachedhostfile *base:mirrors.zju.edu.cn *extras:mirrors.aliyun.com *updates:mirrors.aliyun.com AvailablePackages MySQL-python.x86_641.2.3-0.3.c1.1.el6base mysql.x86_645.1.73-8.el6_8base mysql-bench.x86_645.1.73-8.el6_8base mysql-connector-java.noarch1:5.1.17-6.el6base mysql-connector-odbc.x86_645.1.5r1144-7.el6base mysql-devel.i6865.1.73-8.el6_8base mysql-devel.x86_645.1.73-8.el6_8base mysql-embedded.i6865.1.73-8.el6_8base mysql-embedded.x86_645.1.73-8.el6_8base mysql-embedded-devel.i6865.1.73-8.el6_8base mysql-embedded-devel.x86_645.1.73-8.el6_8base mysql-libs.i6865.1.73-8.el6_8base mysql-libs.x86_645.1.73-8.el6_8base mysql-server.x86_645.1.73-8.el6_8base mysql-test.x86_645.1.73-8.el6_8base
5、选择mysql-server来安装
[root@cdh1zjl]#yuminstallmysql-server Loadedplugins:fastestmirror,refresh-packagekit,security SettingupInstallProcess Loadingmirrorspeedsfromcachedhostfile *base:mirrors.zju.edu.cn *extras:mirrors.aliyun.com *updates:mirrors.aliyun.com ResolvingDependencies -->Runningtransactioncheck --->Packagemysql-server.x86_640:5.1.73-8.el6_8willbeinstalled -->ProcessingDependency:mysql=5.1.73-8.el6_8forpackage:mysql-server-5.1.73-8.el6_8.x86_64 -->ProcessingDependency:perl-DBIforpackage:mysql-server-5.1.73-8.el6_8.x86_64 -->ProcessingDependency:perl-DBD-MySQLforpackage:mysql-server-5.1.73-8.el6_8.x86_64 -->ProcessingDependency:perl(DBI)forpackage:mysql-server-5.1.73-8.el6_8.x86_64 -->ProcessingDependency:libmysqlclient_r.so.16(libmysqlclient_16)(64bit)forpackage:mysql-server-5.1.73-8.el6_8.x86_64 -->ProcessingDependency:libmysqlclient.so.16(libmysqlclient_16)(64bit)forpackage:mysql-server-5.1.73-8.el6_8.x86_64 -->ProcessingDependency:libmysqlclient_r.so.16()(64bit)forpackage:mysql-server-5.1.73-8.el6_8.x86_64 -->ProcessingDependency:libmysqlclient.so.16()(64bit)forpackage:mysql-server-5.1.73-8.el6_8.x86_64 -->Runningtransactioncheck --->Packagemysql.x86_640:5.1.73-8.el6_8willbeinstalled --->Packagemysql-libs.x86_640:5.1.73-8.el6_8willbeinstalled --->Packageperl-DBD-MySQL.x86_640:4.013-3.el6willbeinstalled --->Packageperl-DBI.x86_640:1.609-4.el6willbeinstalled -->FinishedDependencyResolution DependenciesResolved ================================================================================================================================================================================================================= PackageArchVersionRepositorySize ================================================================================================================================================================================================================= Installing: mysql-serverx86_645.1.73-8.el6_8base8.6M Installingfordependencies: mysqlx86_645.1.73-8.el6_8base895k mysql-libsx86_645.1.73-8.el6_8base1.2M perl-DBD-MySQLx86_644.013-3.el6base134k perl-DBIx86_641.609-4.el6base705k TransactionSummary ================================================================================================================================================================================================================= Install5Package(s) Totaldownloadsize:12M Installedsize:33M Isthisok[y/N]: 6、选择y继续安装 Isthisok[y/N]:y DownloadingPackages: (1/5):mysql-5.1.73-8.el6_8.x86_64.rpm|895kB00:00 (2/5):mysql-libs-5.1.73-8.el6_8.x86_64.rpm|1.2MB00:00 (3/5):mysql-server-5.1.73-8.el6_8.x86_64.rpm|8.6MB00:02 (4/5):perl-DBD-MySQL-4.013-3.el6.x86_64.rpm|134kB00:00 (5/5):perl-DBI-1.609-4.el6.x86_64.rpm|705kB00:00 ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Total2.2MB/s|12MB00:05 Runningrpm_check_debug RunningTransactionTest TransactionTestSucceeded RunningTransaction Installing:mysql-libs-5.1.73-8.el6_8.x86_641/5 Installing:perl-DBI-1.609-4.el6.x86_642/5 Installing:perl-DBD-MySQL-4.013-3.el6.x86_643/5 Installing:mysql-5.1.73-8.el6_8.x86_644/5 Installing:mysql-server-5.1.73-8.el6_8.x86_645/5 Verifying:perl-DBD-MySQL-4.013-3.el6.x86_641/5 Verifying:mysql-libs-5.1.73-8.el6_8.x86_642/5 Verifying:mysql-server-5.1.73-8.el6_8.x86_643/5 Verifying:mysql-5.1.73-8.el6_8.x86_644/5 Verifying:perl-DBI-1.609-4.el6.x86_645/5 Installed: mysql-server.x86_640:5.1.73-8.el6_8 DependencyInstalled: mysql.x86_640:5.1.73-8.el6_8mysql-libs.x86_640:5.1.73-8.el6_8perl-DBD-MySQL.x86_640:4.013-3.el6perl-DBI.x86_640:1.609-4.el6 Complete!
7、启动mysql服务
[root@cdh1zjl]#servicemysqldstart InitializingMySQLdatabase:InstallingMySQLsystemtables... OK Fillinghelptables... OK Tostartmysqldatboottimeyouhavetocopy support-files/mysql.servertotherightplaceforyoursystem PLEASEREMEMBERTOSETAPASSWORDFORTHEMySQLrootUSER! Todoso,starttheserver,thenissuethefollowingcommands: /usr/bin/mysqladmin-urootpassword'new-password' /usr/bin/mysqladmin-uroot-hcdh1.zjl.compassword'new-password' Alternativelyyoucanrun: /usr/bin/mysql_secure_installation whichwillalsogiveyoutheoptionofremovingthetest databasesandanonymoususercreatedbydefault.Thisis stronglyrecommendedforproductionservers. Seethemanualformoreinstructions. YoucanstarttheMySQLdaemonwith: cd/usr;/usr/bin/mysqld_safe& YoucantesttheMySQLdaemonwithmysql-test-run.pl cd/usr/mysql-test;perlmysql-test-run.pl Pleasereportanyproblemswiththe/usr/bin/mysqlbugscript! [OK] Startingmysqld:[OK]
8、连接一下试一下,直接mysql然后\q关闭连接
[root@cdh1zjl]#mysql WelcometotheMySQLmonitor.Commandsendwith;or\g. YourMySQLconnectionidis2 Serverversion:5.1.73Sourcedistribution Copyright(c)2000,2013,Oracleand/oritsaffiliates.Allrightsreserved. OracleisaregisteredtrademarkofOracleCorporationand/orits affiliates.Othernamesmaybetrademarksoftheirrespective owners. Type'help;'or'\h'forhelp.Type'\c'toclearthecurrentinputstatement. mysql>\q Bye
9、设置mysql开机启动
[root@cdh1zjl]#chkconfigmysqldon
10、开启3306端口,并保存
[root@cdh1zjl]#/sbin/iptables-IINPUT-ptcp--dport3306-jACCEPT [root@cdh1zjl]#/etc/rc.d/init.d/iptablessave
11、连接mysql设置密码
[root@cdh1zjl]#mysql WelcometotheMySQLmonitor.Commandsendwith;or\g. YourMySQLconnectionidis3 Serverversion:5.1.73Sourcedistribution Copyright(c)2000,2013,Oracleand/oritsaffiliates.Allrightsreserved. OracleisaregisteredtrademarkofOracleCorporationand/orits affiliates.Othernamesmaybetrademarksoftheirrespective owners. Type'help;'or'\h'forhelp.Type'\c'toclearthecurrentinputstatement. mysql>usemysql; Readingtableinformationforcompletionoftableandcolumnnames Youcanturnoffthisfeaturetogetaquickerstartupwith-A Databasechanged mysql>updateusersetpassword=password('123')whereuser='root'; QueryOK,3rowsaffected(0.02sec) Rowsmatched:3Changed:3Warnings:0 mysql>flushprivileges; QueryOK,0rowsaffected(0.02sec) mysql>\q Bye
12、重启mysql服务
[root@cdh1zjl]#servicemysqldrestart Stoppingmysqld:[OK] Startingmysqld:[OK]
以上所述是小编给大家介绍的centos6.9安装mysql的详细教程,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对毛票票网站的支持!