Centos 下mysql数据库完整安装过程

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


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]


补充:

如果上面的wget文件下载不了(有同学反馈无法下载),老徐下了一份在自己的git 库,可直接下载 ;


git地址 http://t.istester.com:3000/istester/idoxu.git 

不知道怎么玩Git命令的,翻看前面的git打卡 ; 


补充:如果没有Git仓库账号的,去 http://git.istester.com/ 注册


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!


注:如果安装过程遇到报错,见文章 http://istester.com/linux /429.html



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' 里,填写你的新密码 。

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

比如:isTester123@456



End 。


完整的mysql相关操作,见之前的文章 http://istester.com/huanjing/134.html


补充,

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



安装完Mysql后,接下来的常用操作(合集)

http://istester.com/mysql/433.html


文章底部-联系
注:如果看完文章,还有不清晰的,可联系 IDO老徐 ,描述你遇到的具体问题,会解答( 微信 957863300 ) 
栏目(点每个栏目看文章)

1、长线能力提升:八年合伙人副业·个人IP实验室

2、测试硬技能:LinuxSQLGit测试工具Jenkins

3、测试软技能:简历面试管理职业发展

4、副业:视频号公众号知乎社群私域小报童专栏  /  免费写作社群  /  小红书资料  /  年度陪伴群

本站申明

1. 所有文章,均为IDO老徐原创(免费学习,欢迎收藏、转发),博客地址 isTester.com

2. 顶部菜单,按栏目查询,可快速检索你需要的所有文章 。看完文章还有不明白的,微信联系 IDO老徐

3. 欢迎关注 公号、进 微信群、进社群「软件测试圈

写作星球new

成长,写作,副业,赚钱社群

写作·成长·副业赚钱,万人免费社群

365 * 24 随时向 IDO老徐 免费提问

完整的 14 个社群入口,点这里


老徐陪你副业避坑

老徐陪你副业避坑

100 个实战小项目,少亏钱,多赚钱

送《一人企业复利商业化》实体书(包邮)

365 * 24 随时向 IDO老徐 免费提问

微信 957863300


技术(硬技能)
个人IP(副业)
公众号-简尚


想了解更多 ?

所有原创软件测试文章都在这

有近10W 软件测试工程师关注

助力「软件测试从业者综合能力提升

关注后,回复 666 有惊喜

简尚公众号

长按/扫码  关注@简尚

我的个人微信 957863300


公众号-IDO老徐


IDO老徐

全网同名,个人IP公众号

日更10年,每天 1 分钟、解决 1 个问题

职场、副业、轻创业、写作、个人IP

公众号、视频号、小红书、知乎

简尚公众号

长按/扫码,关注IDO老徐

关注回复 401 送你一份资料包


联系老徐
联系人: IDO老徐
Email: 957863300@qq.com
QQ: 957863300
微信: 957863300
微博: isTester
网址: isTester.com
地址: 中国 . 广东 . 深圳
职场(软技能)
轻创业
个人微信
IDO老徐 个人微信