Centos 下 mysql 安装过程

2019-03-29 14:40:00
IDO老徐
原创
239


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



注:如下是截取的老徐之前文章 -》原文 http://istester.com/huanjing/134.html



如上,默认是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相关操作,见之前的文章 http://istester.com/huanjing/134.html


补充,

搭建博客的文章文章 -》 http://istester.com/bushu/254.html


本站申明

1. 本站点,所有文章,均为IDO老徐原创,拒绝转载 。

2. 右上角,搜索框,输入关键词,可快速检索你感兴趣的所有文章 。

文章分类
Coding_banner
热门文章
公众号2



想了解更多 ?

欢迎关注老徐的公众号

Tester & 职场人 & 5W人都在关注

软件测试从业者综合能力提升&择业加薪 

第一时间,更新至此公众号

简尚公众号

长按二维码/微信扫码  关注老徐

老徐私人微信957863300

有问题,随时留言


联系老徐
联系人: IDO老徐
Email: 957863300@qq.com
QQ: 957863300
微信: 957863300
微博: isTester
网址: isTester.com
地址: 中国 . 广东 . 深圳