Linux系统下怎么安装mysql
这篇文章给大家分享的是有关Linux系统下怎么安装MySQL的内容。小编觉得挺实用的,因此分享给大家做个参考,一起跟随小编过来看看吧。
成都创新互联是一家专注于成都网站建设、做网站与策划设计,绿园网站建设哪家好?成都创新互联做网站,专注于网站建设十余年,网设计领域的专业建站公司;建站业务涵盖:绿园等地区。绿园做网站价格咨询:18980820575
1.查看linux操作系统版本和系统内核版本
[root@nfs_client ~]# cat /etc/redhat-release 查看操作系统版本
CentOS Linux release 7.5.1804 (Core)
[root@nfs_client ~]# uname -r 查看系统内核版本
3.10.0-862.el7.x86_64
二 下载对应版本的MySQL 安装文件
1.下载地址:https://dev.mysql.com/downloads/mysql/
下载下来:
三 卸载旧版本的MySql (没有的话,则跳过此步骤)
1、查看旧版本MySql
rpm -qa | grep mysql
将会列出旧版本MySql的组件列表,如:
我的电脑这里只显示一个,有可能会有多个。
2、逐个删除掉旧的组件
使用命令rpm -e --nodeps {-file-name}进行移除操作,移除的时候可能会有依赖,要注意一定的顺序。
第一次没有删除成功是因为最后多了一个空格。
四、安装过程:
解压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
安装依赖组件
在我进行安装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]#
由上面的错误可以看出我们需要安装相应的依赖
libaio
net-tools
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%]
启动数据库
×
广告
MySQL5.7 安装 - Linux下RPM方式安装
番薯IT 关注
0.1 2017.09.09 16:19* 字数 623 阅读 1557评论 1喜欢 1
目前MySQL5.7的最新版本是5.7.19,
下载
地址:https://dev.mysql.com/downloads/mysql/
名称:
mysql-5.7.19-1.el7.x86_64.rpm-bundle.tar
安装
我已经把安装包放到/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
可以看出,我们需要卸载postfix
和mariadb-libs
相关的组件。卸载我们可以使用rpm -ev xxx
。
查看
postfix
和mariadb-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
卸载
postfix
和mariadb-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]#
由上面的错误可以看出我们需要安装相应的依赖
libaio
net-tools
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: hcLMTxbOh3?w
这样我们得知临时密码是:hcLMTxbOh3?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;
重新登录,这样我们就能用新的密码登录了。我们可以愉快的进行数据库操作了。
感谢各位的阅读!关于“Linux系统下怎么安装mysql”这篇文章就分享到这里了,希望以上内容可以对大家有一定的帮助,让大家可以学到更多知识,如果觉得文章不错,可以把它分享出去让更多的人看到吧!
当前标题:Linux系统下怎么安装mysql
当前地址:http://azwzsj.com/article/pijsdc.html