欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  科技

Centos 下 mysql 安装过程

程序员文章站 2022-04-02 11:17:38
1. 检查系统自带的Mysql,并卸载自带的版本 2. 卸载系统自带的mysql及其依赖 3. 给CentOS添加rpm源,并且选择较新的源 1)下载rpm包 2)安装本地mysql源 3)验证是否安装成功 4)修改默认版本为5.7 注:如下是截取的老徐之前文章 -》原文 http://istest ......


1. 检查系统自带的mysql,并卸载自带的版本

 

 

[root@iz2366ycl7sz config]# yum list installed |grep mysql
mysql.x86_64            5.1.73-5.el6_6  @base                                   
mysql-libs.x86_64       5.1.73-5.el6_6  @base                                   
php56w-mysql.x86_64     5.6.40-1.w6     @webtatic     

 

 

 

2. 卸载系统自带的mysql及其依赖 

 

[root@iz2366ycl7sz config]# yum -y remove mysql-libs.x86_64
loaded plugins: security
setting up remove process
resolving dependencies
--> running transaction check
---> package mysql-libs.x86_64 0:5.1.73-5.el6_6 will be erased
--> processing dependency: libmysqlclient.so.16()(64bit) for package: php56w-mysql-5.6.40-1.w6.x86_64
--> processing dependency: libmysqlclient.so.16()(64bit) for package: 2:postfix-2.6.6-6.el6_5.x86_64
--> processing dependency: libmysqlclient.so.16()(64bit) for package: mysql-5.1.73-5.el6_6.x86_64
--> processing dependency: libmysqlclient.so.16(libmysqlclient_16)(64bit) for package: php56w-mysql-5.6.40-1.w6.x86_64
--> processing dependency: libmysqlclient.so.16(libmysqlclient_16)(64bit) for package: 2:postfix-2.6.6-6.el6_5.x86_64
--> processing dependency: libmysqlclient.so.16(libmysqlclient_16)(64bit) for package: mysql-5.1.73-5.el6_6.x86_64
--> processing dependency: libmysqlclient_r.so.16()(64bit) for package: php56w-mysql-5.6.40-1.w6.x86_64
--> processing dependency: libmysqlclient_r.so.16()(64bit) for package: mysql-5.1.73-5.el6_6.x86_64
--> processing dependency: libmysqlclient_r.so.16(libmysqlclient_16)(64bit) for package: php56w-mysql-5.6.40-1.w6.x86_64
--> processing dependency: libmysqlclient_r.so.16(libmysqlclient_16)(64bit) for package: mysql-5.1.73-5.el6_6.x86_64
--> processing dependency: mysql-libs for package: 2:postfix-2.6.6-6.el6_5.x86_64
--> processing dependency: mysql-libs = 5.1.73-5.el6_6 for package: mysql-5.1.73-5.el6_6.x86_64
--> running transaction check
---> package mysql.x86_64 0:5.1.73-5.el6_6 will be erased
---> package php56w-mysql.x86_64 0:5.6.40-1.w6 will be erased
---> package postfix.x86_64 2:2.6.6-6.el6_5 will be erased
--> finished dependency resolution

dependencies resolved

========================================================================================================================================
 package                          arch                       version                                repository                     size
========================================================================================================================================
removing:
 mysql-libs                       x86_64                     5.1.73-5.el6_6                         @base                         4.0 m
removing for dependencies:
 mysql                            x86_64                     5.1.73-5.el6_6                         @base                         2.4 m
 php56w-mysql                     x86_64                     5.6.40-1.w6                            @webtatic                     457 k
 postfix                          x86_64                     2:2.6.6-6.el6_5                        @updates                      9.7 m

transaction summary
========================================================================================================================================
remove        4 package(s)

installed size: 17 m
downloading packages:
running rpm_check_debug
running transaction test
transaction test succeeded
running transaction
  erasing    : php56w-mysql-5.6.40-1.w6.x86_64                                                                                      1/4 
  erasing    : 2:postfix-2.6.6-6.el6_5.x86_64                                                                                       2/4 
  erasing    : mysql-5.1.73-5.el6_6.x86_64                                                                                          3/4 
  erasing    : mysql-libs-5.1.73-5.el6_6.x86_64                                                                                     4/4 
  verifying  : mysql-libs-5.1.73-5.el6_6.x86_64                                                                                     1/4 
  verifying  : php56w-mysql-5.6.40-1.w6.x86_64                                                                                      2/4 
  verifying  : mysql-5.1.73-5.el6_6.x86_64                                                                                          3/4 
  verifying  : 2:postfix-2.6.6-6.el6_5.x86_64                                                                                       4/4 

removed:
  mysql-libs.x86_64 0:5.1.73-5.el6_6                                                                                                    

dependency removed:
  mysql.x86_64 0:5.1.73-5.el6_6              php56w-mysql.x86_64 0:5.6.40-1.w6              postfix.x86_64 2:2.6.6-6.el6_5             

complete!

 

3. 给centos添加rpm源,并且选择较新的源

 

1)下载rpm包

 

[root@iz2366ycl7sz software]# wget dev.mysql.com/get/mysql-community-release-el6-5.noarch.rpm --no-check-certificate
--2019-03-29 14:45:46--  http://dev.mysql.com/get/mysql-community-release-el6-5.noarch.rpm
resolving dev.mysql.com... 137.254.60.11
connecting to dev.mysql.com|137.254.60.11|:80... connected.
http request sent, awaiting response... 301 moved permanently
location: https://dev.mysql.com/get/mysql-community-release-el6-5.noarch.rpm [following]
--2019-03-29 14:45:46--  https://dev.mysql.com/get/mysql-community-release-el6-5.noarch.rpm
connecting to dev.mysql.com|137.254.60.11|:443... connected.
http request sent, awaiting response... 302 found
location: https://repo.mysql.com//mysql-community-release-el6-5.noarch.rpm [following]
--2019-03-29 14:45:48--  https://repo.mysql.com//mysql-community-release-el6-5.noarch.rpm
resolving repo.mysql.com... 104.127.195.16
connecting to repo.mysql.com|104.127.195.16|:443... connected.
http request sent, awaiting response... 200 ok
length: 5824 (5.7k) [application/x-redhat-package-manager]
saving to: “mysql-community-release-el6-5.noarch.rpm”

100%[==============================================================================================>] 5,824       --.-k/s   in 0s      

2019-03-29 14:45:48 (506 mb/s) - “mysql-community-release-el6-5.noarch.rpm” saved [5824/5824]

 

2)安装本地mysql源

 

[root@iz2366ycl7sz software]# yum localinstall mysql-community-release-el6-5.noarch.rpm
loaded plugins: security
setting up local package process
examining mysql-community-release-el6-5.noarch.rpm: mysql-community-release-el6-5.noarch
marking mysql-community-release-el6-5.noarch.rpm to be installed
resolving dependencies
--> running transaction check
---> package mysql-community-release.noarch 0:el6-5 will be installed
--> finished dependency resolution

dependencies resolved

========================================================================================================================================
 package                              arch                version              repository                                          size
========================================================================================================================================
installing:
 mysql-community-release              noarch              el6-5                /mysql-community-release-el6-5.noarch              4.3 k

transaction summary
========================================================================================================================================
install       1 package(s)

total size: 4.3 k
installed size: 4.3 k
is this ok [y/n]: y
is this ok [y/n]: y
downloading packages:
running rpm_check_debug
running transaction test
transaction test succeeded
running transaction
  installing : mysql-community-release-el6-5.noarch                                                                                 1/1 
  verifying  : mysql-community-release-el6-5.noarch                                                                                 1/1 

installed:
  mysql-community-release.noarch 0:el6-5                                                                                                

complete!

 

3)验证是否安装成功

 

[root@iz2366ycl7sz software]# yum repolist all | grep mysql
mysql-connectors-community        mysql connectors community     enabled:     83
mysql-connectors-community-source mysql connectors community - s disabled
mysql-tools-community             mysql tools community          enabled:     74
mysql-tools-community-source      mysql tools community - source disabled
mysql55-community                 mysql 5.5 community server     disabled
mysql55-community-source          mysql 5.5 community server - s disabled
mysql56-community                 mysql 5.6 community server     enabled:    493
mysql56-community-source          mysql 5.6 community server - s disabled
mysql57-community-dmr             mysql 5.7 community server dev disabled
mysql57-community-dmr-source      mysql 5.7 community server dev disabled

 

4)修改默认版本为5.7

 

 

注:如下是截取的老徐之前文章 -》原文 

 


如上,默认是5.6版本可用,如果想安装5.7怎么操作?

有如下两个方法:

 

方法一:

执行:

yum-config-manager --disable mysql56-community

yum-config-manager --enable mysql57-community-dmr

 

如上操作,是把5.6禁用,把5.7启用

此法,会有异常情况:

如果执行命令出现如下错误:

-bash: yum-config-manager: command not found

可用执行如下命令解决,然后继续上面的操作命令:

yum -y install yum-utils

 

注意:如上操作可能有一部分同学的会出现一些问题;好处是操作简单,两个命令搞定~

如果有问题,底部给老徐留言~

 

 

方法二:

直接编辑配置文件,简单、直接,基本不会出现错误~

vi /etc/yum.repos.d/mysql-community.repo 

把5.6的enabled=0

把5.7的enabled=1

然后保存就ok

 

# enable to use mysql 5.5

[mysql55-community]

name=mysql 5.5 community server

baseurl=http://repo.mysql.com/yum/mysql-5.5-community/el/6/$basearch/

enabled=0

gpgcheck=1

gpgkey=file:/etc/pki/rpm-gpg/rpm-gpg-key-mysql

 

# enable to use mysql 5.6

[mysql56-community]

name=mysql 5.6 community server

baseurl=http://repo.mysql.com/yum/mysql-5.6-community/el/6/$basearch/

enabled=0

gpgcheck=1

gpgkey=file:/etc/pki/rpm-gpg/rpm-gpg-key-mysql

 

# note: mysql 5.7 is currently in development. for use at your own risk.

# please read with sub pages: https://dev.mysql.com/doc/relnotes/mysql/5.7/en/

[mysql57-community-dmr]

name=mysql 5.7 community server development milestone release

baseurl=http://repo.mysql.com/yum/mysql-5.7-community/el/6/$basearch/

enabled=1

gpgcheck=1

gpgkey=file:/etc/pki/rpm-gpg/rpm-gpg-key-mysql


如上,颜色标记处 。

此时,再执行:

yum repolist all | grep mysql

就可以看到,5.7是启用的

 

 

[root@localhost webserver]# yum repolist all | grep mysql

mysql-connectors-community        mysql connectors community         启用:    21

mysql-connectors-community-source mysql connectors community - sourc 禁用

mysql-tools-community             mysql tools community              启用:    38

mysql-tools-community-source      mysql tools community - source     禁用

mysql55-community                 mysql 5.5 community server         禁用

mysql55-community-source          mysql 5.5 community server - sourc 禁用

mysql56-community                 mysql 5.6 community server         禁用

mysql56-community-source          mysql 5.6 community server - sourc 禁用

mysql57-community-dmr             mysql 5.7 community server develop 启用:   130

mysql57-community-dmr-source      mysql 5.7 community server develop 禁用


如上 。

ok,至此,基础准备工作完成 。

 

 

 

4. 安装mysql

执行如下命令:

yum install mysql-community-server

 

[root@iz2366ycl7sz software]# yum install mysql-community-server
loaded plugins: security
setting up install process
resolving dependencies
--> running transaction check
---> package mysql-community-server.x86_64 0:5.7.25-1.el6 will be installed
--> processing dependency: mysql-community-common(x86-64) = 5.7.25-1.el6 for package: mysql-community-server-5.7.25-1.el6.x86_64
--> processing dependency: mysql-community-client(x86-64) >= 5.7.9 for package: mysql-community-server-5.7.25-1.el6.x86_64
--> running transaction check
---> package mysql-community-client.x86_64 0:5.7.25-1.el6 will be installed
--> processing dependency: mysql-community-libs(x86-64) >= 5.7.9 for package: mysql-community-client-5.7.25-1.el6.x86_64
---> package mysql-community-common.x86_64 0:5.7.25-1.el6 will be installed
--> running transaction check
---> package mysql-community-libs.x86_64 0:5.7.25-1.el6 will be installed
--> finished dependency resolution

dependencies resolved

========================================================================================================================================
 package                                arch                   version                      repository                             size
========================================================================================================================================
installing:
 mysql-community-server                 x86_64                 5.7.25-1.el6                 mysql57-community-dmr                 153 m
installing for dependencies:
 mysql-community-client                 x86_64                 5.7.25-1.el6                 mysql57-community-dmr                  23 m
 mysql-community-common                 x86_64                 5.7.25-1.el6                 mysql57-community-dmr                 332 k
 mysql-community-libs                   x86_64                 5.7.25-1.el6                 mysql57-community-dmr                 2.1 m

transaction summary
========================================================================================================================================
install       4 package(s)

total download size: 178 m
installed size: 887 m
is this ok [y/n]: y
downloading packages:
(1/4): mysql-community-client-5.7.25-1.el6.x86_64.rpm                                                            |  23 mb     00:01     
(2/4): mysql-community-common-5.7.25-1.el6.x86_64.rpm                                                            | 332 kb     00:00     
(3/4): mysql-community-libs-5.7.25-1.el6.x86_64.rpm                                                              | 2.1 mb     00:00     
(4/4): mysql-community-server-5.7.25-1.el6.x86_64.rpm                                                            | 153 mb     00:04     
----------------------------------------------------------------------------------------------------------------------------------------
total                                                                                                    32 mb/s | 178 mb     00:05     
warning: rpmts_hdrfromfdno: header v3 dsa/sha1 signature, key id 5072e1f5: nokey
retrieving key from file:/etc/pki/rpm-gpg/rpm-gpg-key-mysql
importing gpg key 0x5072e1f5:
 userid : mysql release engineering <mysql-build@oss.oracle.com>
 package: mysql-community-release-el6-5.noarch (@/mysql-community-release-el6-5.noarch)
 from   : file:/etc/pki/rpm-gpg/rpm-gpg-key-mysql
is this ok [y/n]: y
running rpm_check_debug
running transaction test
transaction test succeeded
running transaction
  installing : mysql-community-common-5.7.25-1.el6.x86_64                                                                           1/4 
  installing : mysql-community-libs-5.7.25-1.el6.x86_64                                                                             2/4 
  installing : mysql-community-client-5.7.25-1.el6.x86_64                                                                           3/4 
  installing : mysql-community-server-5.7.25-1.el6.x86_64                                                                           4/4 
  verifying  : mysql-community-libs-5.7.25-1.el6.x86_64                                                                             1/4 
  verifying  : mysql-community-common-5.7.25-1.el6.x86_64                                                                           2/4 
  verifying  : mysql-community-client-5.7.25-1.el6.x86_64                                                                           3/4 
  verifying  : mysql-community-server-5.7.25-1.el6.x86_64                                                                           4/4 

installed:
  mysql-community-server.x86_64 0:5.7.25-1.el6                                                                                          

dependency installed:
  mysql-community-client.x86_64 0:5.7.25-1.el6 mysql-community-common.x86_64 0:5.7.25-1.el6 mysql-community-libs.x86_64 0:5.7.25-1.el6

complete!

 

 

5. 启动mysql

 

 

[root@iz2366ycl7sz software]# service mysqld start
initializing mysql database:                               [  ok  ]
starting mysqld:                                           [  ok  ]

 

6. 查看mysql服务状态

 

 

[root@iz2366ycl7sz software]# service mysqld status
mysqld (pid  7036) is running...

 

7. 查看mysql 初始密码

mysql5.7之后初始密码不再默认为空

 

[root@iz2366ycl7sz software]# grep 'temporary password' /var/log/mysqld.log 
2019-03-29t07:09:36.375706z 1 [note] a temporary password is generated for root@localhost: xo%lbtyoo2mv

其中,最后的xo%lbtyoo2mv 就是密码

 

 

8. 命令行登录mysql ,并修改密码

 

登录之后 第一步必须先修改密码,

否则其他操作都执行不了。

mysql -u root -p

 

mysql> show databases;
error 1820 (hy000): you must reset your password using alter user statement before executing this statement.
mysql> 

 

9. 修改密码的方法:

alter user root@localhost identified by 'passwd';

# 'passwd' 里,填写你的新密码 。

新修改的密码中 必须包含 大小写字母数字及符号

 

 

end 。

 

完整的mysql相关操作,见之前的文章 

 

补充,

搭建博客的文章文章 -》