centos 6.9安装mysql的详细教程
程序员文章站
2023-09-08 16:29:04
1、确认mysql是否已安装,有下面的代码可知
[root@cdh1 zjl]# yum list installed mysql*
loaded plugin...
1、确认mysql是否已安装,有下面的代码可知
[root@cdh1 zjl]# yum list installed mysql* loaded plugins: fastestmirror, refresh-packagekit, security loading mirror speeds from cached hostfile * base: mirrors.zju.edu.cn * extras: mirrors.aliyun.com * updates: mirrors.aliyun.com installed packages mysql-python.x86_64 1.2.3-0.3.c1.1.el6 @base mysql-libs.x86_64 5.1.73-8.el6_8 @anaconda-centos-201703281317.x86_64/6.9
2、卸载已安装的mysql,建议使用yum命令,因为yum命令可以自动删除与mysql相关的依赖;如果使用rpm命令,则还需要手动去删除和mysql相关的文件,比较麻烦
[root@cdh1 zjl]# yum remove mysql-python.x86_64 mysql-libs.x86_64 loaded plugins: fastestmirror, refresh-packagekit, security setting up remove process resolving dependencies --> running transaction check ---> package mysql-python.x86_64 0:1.2.3-0.3.c1.1.el6 will be erased --> processing dependency: mysql-python for package: cloudera-manager-agent-5.11.1-1.cm5111.p0.9.el6.x86_64 ---> package mysql-libs.x86_64 0:5.1.73-8.el6_8 will be erased --> processing dependency: libmysqlclient.so.16()(64bit) for package: 2:postfix-2.6.6-8.el6.x86_64 --> processing dependency: libmysqlclient.so.16(libmysqlclient_16)(64bit) for package: 2:postfix-2.6.6-8.el6.x86_64 --> processing dependency: mysql-libs for package: 2:postfix-2.6.6-8.el6.x86_64 --> running transaction check ---> package cloudera-manager-agent.x86_64 0:5.11.1-1.cm5111.p0.9.el6 will be erased ---> package postfix.x86_64 2:2.6.6-8.el6 will be erased --> processing dependency: /usr/sbin/sendmail for package: redhat-lsb-core-4.0-7.el6.centos.x86_64 --> processing dependency: /usr/sbin/sendmail for package: cronie-1.4.4-16.el6_8.2.x86_64 --> running transaction check ---> package cronie.x86_64 0:1.4.4-16.el6_8.2 will be erased --> processing dependency: cronie = 1.4.4-16.el6_8.2 for package: cronie-anacron-1.4.4-16.el6_8.2.x86_64 ---> package redhat-lsb-core.x86_64 0:4.0-7.el6.centos will be erased --> processing dependency: redhat-lsb-core(x86-64) = 4.0 for package: redhat-lsb-printing-4.0-7.el6.centos.x86_64 --> processing dependency: redhat-lsb-core(x86-64) = 4.0-7.el6.centos for package: redhat-lsb-4.0-7.el6.centos.x86_64 --> processing dependency: redhat-lsb-core(x86-64) = 4.0 for package: redhat-lsb-graphics-4.0-7.el6.centos.x86_64 --> running transaction check ---> package cronie-anacron.x86_64 0:1.4.4-16.el6_8.2 will be erased ---> package redhat-lsb.x86_64 0:4.0-7.el6.centos will be erased --> processing dependency: redhat-lsb(x86-64) = 4.0-7.el6.centos for package: redhat-lsb-compat-4.0-7.el6.centos.x86_64 ---> package redhat-lsb-graphics.x86_64 0:4.0-7.el6.centos will be erased ---> package redhat-lsb-printing.x86_64 0:4.0-7.el6.centos will be erased --> running transaction check ---> package redhat-lsb-compat.x86_64 0:4.0-7.el6.centos will be erased --> processing dependency: /etc/cron.d for package: crontabs-1.10-33.el6.noarch --> processing dependency: /etc/cron.d for package: sysstat-9.0.4-33.el6.x86_64 --> restarting dependency resolution with new changes. --> running transaction check ---> package crontabs.noarch 0:1.10-33.el6 will be erased ---> package sysstat.x86_64 0:9.0.4-33.el6 will be erased --> finished dependency resolution dependencies resolved ==================================================================== package arch version repository size ==================================================================== removing: mysql-python x86_64 1.2.3-0.3.c1.1.el6 @base 246 k mysql-libs x86_64 5.1.73-8.el6_8 @anaconda-centos-201703281317.x86_64/6.9 4.0 m removing for dependencies: cloudera-manager-agent x86_64 5.11.1-1.cm5111.p0.9.el6 @/cloudera-manager-agent-5.11.1-1.cm5111.p0.9.el6.x86_64 71 m cronie x86_64 1.4.4-16.el6_8.2 @anaconda-centos-201703281317.x86_64/6.9 174 k cronie-anacron x86_64 1.4.4-16.el6_8.2 @anaconda-centos-201703281317.x86_64/6.9 43 k crontabs noarch 1.10-33.el6 @anaconda-centos-201703281317.x86_64/6.9 2.4 k postfix x86_64 2:2.6.6-8.el6 @anaconda-centos-201703281317.x86_64/6.9 9.7 m redhat-lsb x86_64 4.0-7.el6.centos @anaconda-centos-201703281317.x86_64/6.9 0.0 redhat-lsb-compat x86_64 4.0-7.el6.centos @anaconda-centos-201703281317.x86_64/6.9 0.0 redhat-lsb-core x86_64 4.0-7.el6.centos @anaconda-centos-201703281317.x86_64/6.9 22 k redhat-lsb-graphics x86_64 4.0-7.el6.centos @anaconda-centos-201703281317.x86_64/6.9 0.0 redhat-lsb-printing x86_64 4.0-7.el6.centos @anaconda-centos-201703281317.x86_64/6.9 0.0 sysstat x86_64 9.0.4-33.el6 @anaconda-centos-201703281317.x86_64/6.9 826 k transaction summary ==================================================================== remove 13 package(s) installed size: 86 m is this ok [y/n]: y downloading packages: running rpm_check_debug running transaction test transaction test succeeded running transaction warning: rpmdb altered outside of yum. erasing : redhat-lsb-compat-4.0-7.el6.centos.x86_64 1/13 erasing : redhat-lsb-4.0-7.el6.centos.x86_64 2/13 erasing : cloudera-manager-agent-5.11.1-1.cm5111.p0.9. 3/13 warning: /etc/cloudera-scm-agent/config.ini saved as /etc/cloudera-scm-agent/config.ini.rpmsave erasing : redhat-lsb-graphics-4.0-7.el6.centos.x86_64 4/13 erasing : redhat-lsb-printing-4.0-7.el6.centos.x86_64 5/13 erasing : redhat-lsb-core-4.0-7.el6.centos.x86_64 6/13 /var/tmp/rpm-tmp.jlbjuk: line 1: lsb_release: command not found erasing : mysql-python-1.2.3-0.3.c1.1.el6.x86_64 7/13 erasing : sysstat-9.0.4-33.el6.x86_64 8/13 erasing : crontabs-1.10-33.el6.noarch 9/13 erasing : cronie-anacron-1.4.4-16.el6_8.2.x86_64 10/13 erasing : cronie-1.4.4-16.el6_8.2.x86_64 11/13 erasing : 2:postfix-2.6.6-8.el6.x86_64 12/13 erasing : mysql-libs-5.1.73-8.el6_8.x86_64 13/13 verifying : redhat-lsb-printing-4.0-7.el6.centos.x86_64 1/13 verifying : cronie-anacron-1.4.4-16.el6_8.2.x86_64 2/13 verifying : cronie-1.4.4-16.el6_8.2.x86_64 3/13 verifying : 2:postfix-2.6.6-8.el6.x86_64 4/13 verifying : redhat-lsb-4.0-7.el6.centos.x86_64 5/13 verifying : redhat-lsb-core-4.0-7.el6.centos.x86_64 6/13 verifying : cloudera-manager-agent-5.11.1-1.cm5111.p0.9. 7/13 verifying : crontabs-1.10-33.el6.noarch 8/13 verifying : redhat-lsb-compat-4.0-7.el6.centos.x86_64 9/13 verifying : mysql-python-1.2.3-0.3.c1.1.el6.x86_64 10/13 verifying : redhat-lsb-graphics-4.0-7.el6.centos.x86_64 11/13 verifying : sysstat-9.0.4-33.el6.x86_64 12/13 verifying : mysql-libs-5.1.73-8.el6_8.x86_64 13/13 removed: mysql-python.x86_64 0:1.2.3-0.3.c1.1.el6 mysql-libs.x86_64 0:5.1.73-8.el6_8 dependency removed: cloudera-manager-agent.x86_64 0:5.11.1-1.cm5111.p0.9.el6 cronie.x86_64 0:1.4.4-16.el6_8.2 cronie-anacron.x86_64 0:1.4.4-16.el6_8.2 crontabs.noarch 0:1.10-33.el6 postfix.x86_64 2:2.6.6-8.el6 redhat-lsb.x86_64 0:4.0-7.el6.centos redhat-lsb-compat.x86_64 0:4.0-7.el6.centos redhat-lsb-core.x86_64 0:4.0-7.el6.centos redhat-lsb-graphics.x86_64 0:4.0-7.el6.centos redhat-lsb-printing.x86_64 0:4.0-7.el6.centos sysstat.x86_64 0:9.0.4-33.el6 complete!
3、用whereis命令查找mysql相关的文件,因为步骤2用yum来卸载,所以mysql被清理得很干净;如果使用rpm将会很麻烦,有很多的文件需要手动清除
[root@cdh1 zjl]# whereis mysql mysql:
4、查看系统中的mysql安装包
[root@cdh1 zjl]# yum list mysql* loaded plugins: fastestmirror, refresh-packagekit, security loading mirror speeds from cached hostfile * base: mirrors.zju.edu.cn * extras: mirrors.aliyun.com * updates: mirrors.aliyun.com available packages mysql-python.x86_64 1.2.3-0.3.c1.1.el6 base mysql.x86_64 5.1.73-8.el6_8 base mysql-bench.x86_64 5.1.73-8.el6_8 base mysql-connector-java.noarch 1:5.1.17-6.el6 base mysql-connector-odbc.x86_64 5.1.5r1144-7.el6 base mysql-devel.i686 5.1.73-8.el6_8 base mysql-devel.x86_64 5.1.73-8.el6_8 base mysql-embedded.i686 5.1.73-8.el6_8 base mysql-embedded.x86_64 5.1.73-8.el6_8 base mysql-embedded-devel.i686 5.1.73-8.el6_8 base mysql-embedded-devel.x86_64 5.1.73-8.el6_8 base mysql-libs.i686 5.1.73-8.el6_8 base mysql-libs.x86_64 5.1.73-8.el6_8 base mysql-server.x86_64 5.1.73-8.el6_8 base mysql-test.x86_64 5.1.73-8.el6_8 base
5、选择mysql-server来安装
[root@cdh1 zjl]# yum install mysql-server loaded plugins: fastestmirror, refresh-packagekit, security setting up install process loading mirror speeds from cached hostfile * base: mirrors.zju.edu.cn * extras: mirrors.aliyun.com * updates: mirrors.aliyun.com resolving dependencies --> running transaction check ---> package mysql-server.x86_64 0:5.1.73-8.el6_8 will be installed --> processing dependency: mysql = 5.1.73-8.el6_8 for package: mysql-server-5.1.73-8.el6_8.x86_64 --> processing dependency: perl-dbi for package: mysql-server-5.1.73-8.el6_8.x86_64 --> processing dependency: perl-dbd-mysql for package: mysql-server-5.1.73-8.el6_8.x86_64 --> processing dependency: perl(dbi) for package: mysql-server-5.1.73-8.el6_8.x86_64 --> processing dependency: libmysqlclient_r.so.16(libmysqlclient_16)(64bit) for package: mysql-server-5.1.73-8.el6_8.x86_64 --> processing dependency: libmysqlclient.so.16(libmysqlclient_16)(64bit) for package: mysql-server-5.1.73-8.el6_8.x86_64 --> processing dependency: libmysqlclient_r.so.16()(64bit) for package: mysql-server-5.1.73-8.el6_8.x86_64 --> processing dependency: libmysqlclient.so.16()(64bit) for package: mysql-server-5.1.73-8.el6_8.x86_64 --> running transaction check ---> package mysql.x86_64 0:5.1.73-8.el6_8 will be installed ---> package mysql-libs.x86_64 0:5.1.73-8.el6_8 will be installed ---> package perl-dbd-mysql.x86_64 0:4.013-3.el6 will be installed ---> package perl-dbi.x86_64 0:1.609-4.el6 will be installed --> finished dependency resolution dependencies resolved ================================================================================================================================================================================================================= package arch version repository size ================================================================================================================================================================================================================= installing: mysql-server x86_64 5.1.73-8.el6_8 base 8.6 m installing for dependencies: mysql x86_64 5.1.73-8.el6_8 base 895 k mysql-libs x86_64 5.1.73-8.el6_8 base 1.2 m perl-dbd-mysql x86_64 4.013-3.el6 base 134 k perl-dbi x86_64 1.609-4.el6 base 705 k transaction summary ================================================================================================================================================================================================================= install 5 package(s) total download size: 12 m installed size: 33 m is this ok [y/n]: 6、选择y继续安装 is this ok [y/n]: y downloading packages: (1/5): mysql-5.1.73-8.el6_8.x86_64.rpm | 895 kb 00:00 (2/5): mysql-libs-5.1.73-8.el6_8.x86_64.rpm | 1.2 mb 00:00 (3/5): mysql-server-5.1.73-8.el6_8.x86_64.rpm | 8.6 mb 00:02 (4/5): perl-dbd-mysql-4.013-3.el6.x86_64.rpm | 134 kb 00:00 (5/5): perl-dbi-1.609-4.el6.x86_64.rpm | 705 kb 00:00 ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- total 2.2 mb/s | 12 mb 00:05 running rpm_check_debug running transaction test transaction test succeeded running transaction installing : mysql-libs-5.1.73-8.el6_8.x86_64 1/5 installing : perl-dbi-1.609-4.el6.x86_64 2/5 installing : perl-dbd-mysql-4.013-3.el6.x86_64 3/5 installing : mysql-5.1.73-8.el6_8.x86_64 4/5 installing : mysql-server-5.1.73-8.el6_8.x86_64 5/5 verifying : perl-dbd-mysql-4.013-3.el6.x86_64 1/5 verifying : mysql-libs-5.1.73-8.el6_8.x86_64 2/5 verifying : mysql-server-5.1.73-8.el6_8.x86_64 3/5 verifying : mysql-5.1.73-8.el6_8.x86_64 4/5 verifying : perl-dbi-1.609-4.el6.x86_64 5/5 installed: mysql-server.x86_64 0:5.1.73-8.el6_8 dependency installed: mysql.x86_64 0:5.1.73-8.el6_8 mysql-libs.x86_64 0:5.1.73-8.el6_8 perl-dbd-mysql.x86_64 0:4.013-3.el6 perl-dbi.x86_64 0:1.609-4.el6 complete!
7、启动mysql服务
[root@cdh1 zjl]# service mysqld start initializing mysql database: installing mysql system tables... ok filling help tables... ok to start mysqld at boot time you have to copy support-files/mysql.server to the right place for your system please remember to set a password for the mysql root user ! to do so, start the server, then issue the following commands: /usr/bin/mysqladmin -u root password 'new-password' /usr/bin/mysqladmin -u root -h cdh1.zjl.com password 'new-password' alternatively you can run: /usr/bin/mysql_secure_installation which will also give you the option of removing the test databases and anonymous user created by default. this is strongly recommended for production servers. see the manual for more instructions. you can start the mysql daemon with: cd /usr ; /usr/bin/mysqld_safe & you can test the mysql daemon with mysql-test-run.pl cd /usr/mysql-test ; perl mysql-test-run.pl please report any problems with the /usr/bin/mysqlbug script! [ ok ] starting mysqld: [ ok ]
8、连接一下试一下,直接mysql然后\q关闭连接
[root@cdh1 zjl]# mysql welcome to the mysql monitor. commands end with ; or \g. your mysql connection id is 2 server version: 5.1.73 source distribution copyright (c) 2000, 2013, oracle and/or its affiliates. all rights reserved. oracle is a registered trademark of oracle corporation and/or its affiliates. other names may be trademarks of their respective owners. type 'help;' or '\h' for help. type '\c' to clear the current input statement. mysql> \q bye
9、设置mysql开机启动
[root@cdh1 zjl]# chkconfig mysqld on
10、开启3306端口,并保存
[root@cdh1 zjl]# /sbin/iptables -i input -p tcp --dport 3306 -j accept [root@cdh1 zjl]# /etc/rc.d/init.d/iptables save
11、连接mysql设置密码
[root@cdh1 zjl]# mysql welcome to the mysql monitor. commands end with ; or \g. your mysql connection id is 3 server version: 5.1.73 source distribution copyright (c) 2000, 2013, oracle and/or its affiliates. all rights reserved. oracle is a registered trademark of oracle corporation and/or its affiliates. other names may be trademarks of their respective owners. type 'help;' or '\h' for help. type '\c' to clear the current input statement. mysql> use mysql; reading table information for completion of table and column names you can turn off this feature to get a quicker startup with -a database changed mysql> update user set password=password('123') where user='root'; query ok, 3 rows affected (0.02 sec) rows matched: 3 changed: 3 warnings: 0 mysql> flush privileges; query ok, 0 rows affected (0.02 sec) mysql> \q bye
12、重启mysql服务
[root@cdh1 zjl]# service mysqld restart stopping mysqld: [ ok ] starting mysqld: [ ok ]
以上所述是小编给大家介绍的centos 6.9安装mysql的详细教程,希望对大家有所帮助
推荐阅读
-
CentOS 7 中以命令行方式安装 MySQL 5.7.11 for Linux Generic 二进制版本教程详解
-
64位 win10系统安装绿色版mysql-5.7.16-winx64的教程
-
详解CentOS6.5 安装 MySQL5.1.71的方法
-
在centOS 7安装mysql 5.7的详细教程
-
MySQL(win7x64 5.7.16版本)下载、安装、配置与使用的详细图文教程
-
mysql 5.7.17 安装配置方法图文教程(CentOS7)
-
centos7安装mysql并jdbc测试教程
-
CentOS下安装mysql时忘记设置root密码致无法登录的解决方法
-
mysql安装图解 mysql图文安装教程(详细说明)
-
CentOs7.x安装Mysql的详细教程