MySQL5.7 安装 - Linux下RPM方式安装

目前MySQL5.7的最新版本是5.7.19,

下载

安装

我已经把安装包放到/usr/local/software路径下面

[root@localhost software]# ls
mysql-5.7.19-1.el7.x86_64.rpm-bundle.tar

查看是否已经安装mysql

rpm -qa | grep mysql

解压tar文件

  • 命令
tar -xvf mysql-5.7.19-1.el7.x86_64.rpm-bundle.tar
  • 执行结果
[root@localhost software]# tar -xvf mysql-5.7.19-1.el7.x86_64.rpm-bundle.tar 
mysql-community-embedded-devel-5.7.19-1.el7.x86_64.rpm
mysql-community-client-5.7.19-1.el7.x86_64.rpm
mysql-community-server-5.7.19-1.el7.x86_64.rpm
mysql-community-test-5.7.19-1.el7.x86_64.rpm
mysql-community-embedded-compat-5.7.19-1.el7.x86_64.rpm
mysql-community-minimal-debuginfo-5.7.19-1.el7.x86_64.rpm
mysql-community-server-minimal-5.7.19-1.el7.x86_64.rpm
mysql-community-libs-compat-5.7.19-1.el7.x86_64.rpm
mysql-community-common-5.7.19-1.el7.x86_64.rpm
mysql-community-embedded-5.7.19-1.el7.x86_64.rpm
mysql-community-devel-5.7.19-1.el7.x86_64.rpm
mysql-community-libs-5.7.19-1.el7.x86_64.rpm

卸载冲突的RPM组件

在我们安装mysql相关组件的时候,如果不将此冲突的组件删除掉,我们是安装不成功的。
我们可以先跳过这步,直接进入下步操作,在安装的过程中会有相应的提示。下面是我所碰到的一个提示:

# 安装mysql组件时出现的依赖错误
error: Failed dependencies:
        mysql-community-common(x86-64) >= 5.7.9 is needed by mysql-community-libs-5.7.19-1.el7.x86_64
        mariadb-libs is obsoleted by mysql-community-libs-5.7.19-1.el7.x86_64
        
# 卸载mariadb-libs时出现的依赖错误
error: Failed dependencies:
        libmysqlclient.so.18()(64bit) is needed by (installed) postfix-2:2.10.1-6.el7.x86_64
        libmysqlclient.so.18(libmysqlclient_18)(64bit) is needed by (installed) postfix-2:2.10.1-6.el7.x86_64

可以看出,我们需要卸载postfixmariadb-libs相关的组件。卸载我们可以使用rpm -ev xxx

  • 查看postfixmariadb-libs
rpm -qa | grep postfix
rpm -qa | grep mariadb
  • 执行过程
[root@localhost software]# rpm -qa | grep postfix
postfix-2.10.1-6.el7.x86_64

[root@localhost software]# rpm -qa | grep mariadb
mariadb-libs-5.5.52-1.el7.x86_64
  • 卸载postfixmariadb-libs
rpm -ev postfix-2.10.1-6.el7.x86_64
rpm -ev mariadb-libs-5.5.52-1.el7.x86_64
  • 执行过程
[root@localhost software]# rpm -ev postfix-2.10.1-6.el7.x86_64
Preparing packages...
postfix-2:2.10.1-6.el7.x86_64
[root@localhost software]# rpm -ev mariadb-libs-5.5.52-1.el7.x86_64
Preparing packages...
mariadb-libs-1:5.5.52-1.el7.x86_64

安装依赖组件

在我进行安装msql-community-server-xxx的时候出现了下面的问题

[root@localhost software]# rpm -ivh mysql-community-server-5.7.19-1.el7.x86_64.rpm 
warning: mysql-community-server-5.7.19-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
error: Failed dependencies:
        /usr/bin/perl is needed by mysql-community-server-5.7.19-1.el7.x86_64
        libaio.so.1()(64bit) is needed by mysql-community-server-5.7.19-1.el7.x86_64
        libaio.so.1(LIBAIO_0.1)(64bit) is needed by mysql-community-server-5.7.19-1.el7.x86_64
        libaio.so.1(LIBAIO_0.4)(64bit) is needed by mysql-community-server-5.7.19-1.el7.x86_64
        net-tools is needed by mysql-community-server-5.7.19-1.el7.x86_64
        perl(Getopt::Long) is needed by mysql-community-server-5.7.19-1.el7.x86_64
        perl(strict) is needed by mysql-community-server-5.7.19-1.el7.x86_64
[root@localhost software]# 

由上面的错误可以看出我们需要安装相应的依赖

  1. libaio
  2. net-tools
  3. perl
  • 安装依赖
yum -y install libaio
yum -y install net-tools
yum -y install perl

安装mysql组件

经过上面的解压操作,我们得到了很多rpm文件。但是我们不需要这么多,我们只需要安装一下四个组件就可以了:

mysql-community-common-5.7.19-1.el7.x86_64.rpm
mysql-community-libs-5.7.19-1.el7.x86_64.rpm
mysql-community-client-5.7.19-1.el7.x86_64.rpm
mysql-community-server-5.7.19-1.el7.x86_64.rpm

因为具有依赖关系,所以我们需要按顺序执行。
rpm -ivh 文件名就能安装相应的组件。
在执行server的时候,需要依赖安装一些工具组件,已经在上文有说明了

  • 安装命令
rpm -ivh mysql-community-common-5.7.19-1.el7.x86_64.rpm
rpm -ivh mysql-community-libs-5.7.19-1.el7.x86_64.rpm
rpm -ivh mysql-community-client-5.7.19-1.el7.x86_64.rpm
rpm -ivh mysql-community-server-5.7.19-1.el7.x86_64.rpm
  • 执行过程
[root@localhost software]# rpm -ivh mysql-community-common-5.7.19-1.el7.x86_64.rpm 
warning: mysql-community-common-5.7.19-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:mysql-community-common-5.7.19-1.e################################# [100%]
[root@localhost software]# rpm -ivh mysql-community-libs-5.7.19-1.el7.x86_64.rpm 
warning: mysql-community-libs-5.7.19-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:mysql-community-libs-5.7.19-1.el7################################# [100%]
[root@localhost software]# rpm -ivh mysql-community-client-5.7.19-1.el7.x86_64.rpm 
warning: mysql-community-client-5.7.19-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:mysql-community-client-5.7.19-1.e################################# [100%]
[root@localhost software]# rpm -ivh mysql-community-server-5.7.19-1.el7.x86_64.rpm
warning: mysql-community-server-5.7.19-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:mysql-community-server-5.7.19-1.e################################# [100%]

启动数据库

# 查看mysql是否启动
service mysqld status

# 启动mysql
service mysqld start

# 停止mysql
service mysqld stop

# 重启mysql
service mysqld restart

修改密码

mysql安装完成之后我们是没有设置密码的,但是mysql为我们设置了一个临时的密码,我们可以查看mysql的日志知道这个临时密码。

  • 查看临时密码
grep password /var/log/mysqld.log
  • 执行过程
[root@localhost ~]# grep password /var/log/mysqld.log 
2017-09-01T16:43:10.889769Z 1 [Note] A temporary password is generated for root@localhost: hcLMTxbOh2?w

这样我们得知临时密码是:hcLMTxbOh2?w
然后我们用这个临时密码登录数据库。

数据库的密码需要满足以下条件:大小写字母,数字和特殊符号

  • 执行命令
# 登录mysql,之后需要输入密码
mysql -p

# 设置新密码
set password = password("Mysql_123456");

# 退出当前登录
quit;
  • 执行过程
[root@localhost ~]# mysql -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 6
Server version: 5.7.19 MySQL Community Server (GPL)

Copyright (c) 2000, 2017, 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> set password = password("Mysql_123456");
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> quit;

重新登录,这样我们就能用新的密码登录了。我们可以愉快的进行数据库操作了。

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 158,560评论 4 361
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 67,104评论 1 291
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 108,297评论 0 243
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 43,869评论 0 204
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 52,275评论 3 287
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 40,563评论 1 216
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 31,833评论 2 312
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 30,543评论 0 197
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 34,245评论 1 241
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 30,512评论 2 244
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 32,011评论 1 258
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 28,359评论 2 253
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 33,006评论 3 235
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 26,062评论 0 8
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 26,825评论 0 194
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 35,590评论 2 273
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 35,501评论 2 268

推荐阅读更多精彩内容