RHEL7.0下安装MySQL5.7 (以rpm包模式安装)

下载

安装

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

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

查看是否已经安装mysql

rpm -qa | grep mysql
  • 1

解压tar文件

  • 命令
tar -xvf mysql-5.7.19-1.el7.x86_64.rpm-bundle.tar
  • 1
  • 执行结果
[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
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13

卸载冲突的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
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9

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

  • 查看postfixmariadb-libs
rpm -qa | grep postfix
rpm -qa | grep mariadb
  • 1
  • 2
  • 执行过程
[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
  • 1
  • 2
  • 3
  • 4
  • 5
  • 卸载postfixmariadb-libs
rpm -ev postfix-2.10.1-6.el7.x86_64
rpm -ev mariadb-libs-5.5.52-1.el7.x86_64
  • 1
  • 2
  • 执行过程
[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
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

安装依赖组件

在我进行安装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
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11

由上面的错误可以看出我们需要安装相应的依赖 
1. libaio 
2. net-tools 
3. perl

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

安装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 --nodeps
  • 1
  • 2
  • 3
  • 4
  • 执行过程
[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%]
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20

启动数据库

# 查看mysql是否启动
service mysqld status

# 启动mysql
service mysqld start

# 停止mysql
service mysqld stop

# 重启mysql
service mysqld restart
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11

修改密码

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

  • 查看临时密码
grep password /var/log/mysqld.log
  • 1
  • 执行过程
[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
  • 1
  • 2

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

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

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

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

# 退出当前登录
quit;
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 执行过程
[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;
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18

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



配置mysql远程访问权限

(1)执行命令:/usr/local/mysql/bin/mysql -u root -p,输入登录密码,进入mysql


注意输入密码的时候控制台是不会显示密码的

(2)执行命令:use mysql;  注意这里分号也是命令的一部分


(3)创建远程登录用户并授权,执行命令:grant all privileges on *.* to root @"%" identified by 'Mysql_123456' WITH GRANT OPTION;


命令中的root是远程登录名,123456是远程登录用户密码,密码对应途中红线覆盖的部分

(4)执行命令:flush privileges;强制刷新权限


现在就可以在其他主机上通过设置的远程用户名和密码登录到mysql了




  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Centos7安装mysql5.7 rpm安装 卸载MariaDB CentOS7默认安装MariaDB而不是MySQL,而且yum服务器上也移除了MySQL相关的软件。因为MariaDB和MySQL可能会冲突,故先卸载MariaDB。 1、安装新版mysql之前,我们需要将系统自带的mariadb-lib卸载 [root@iZwz94qazh62gk5ewl4ei2Z home]# rpm -qa | grep -i mariadb mariadb-libs-5.5.52-1.el7.x86_64 [root@iZwz94qazh62gk5ewl4ei2Z home]# rpm -e --nodeps mariadb-libs-5.5.52-1.el7.x86_64 如果系统之前有安装过mysql,要先查看有没有安装: rpm -qa | grep -i mysql 如果有安装要先进行删除,避免安装冲突; yum -y remove mysql-libs-5.1.73-7.el6.x86_64 2、到mysql的官网下载最新版mysql的rpm集合:mysql-5.7.19-1.el6.x86_64.rpm-bundle.tar 3、上传mysql-5.7.18-1.el6.x86_64.rpm-bundle.tar到linux服务器,并解压tar 复制代码 [root@iZwz94qazh62gk5ewl4ei2Z home]# mkdir mysql [root@iZwz94qazh62gk5ewl4ei2Z home]# tar -xf mysql-5.7.19-1.el6.x86_64.rpm-bundle.tar -C mysql [root@iZwz94qazh62gk5ewl4ei2Z home]# cd mysql [root@iZwz94qazh62gk5ewl4ei2Z mysql]# ll total 459492 -rw-r--r-- 171553141523618836 Mar 2017:40 mysql-community-client-5.7.19-1.el6.x86_64.rpm -rw-r--r-- 1715531415335496 Mar 2017:40 mysql-community-common-5.7.19-1.el6.x86_64.rpm -rw-r--r-- 17155314153747352 Mar 2017:40 mysql-community-devel-5.7.19-1.el6.x86_64.rpm -rw-r--r-- 171553141539086508 Mar 2017:40 mysql-community-embedded-5.7.19-1.el6.x86_64.rpm -rw-r--r-- 1715531415135869292 Mar 2017:40 mysql-community-embedded-devel-5.7.19-1.el6.x86_64.rpm -rw-r--r-- 17155314152177064 Mar 2017:40 mysql-community-libs-5.7.19-1.el6.x86_64.rpm -rw-r--r-- 17155314151723180 Mar 2017:40 mysql-community-libs-compat-5.7.19-1.el6.x86_64.rpm -rw-r--r-- 1715531415159060212 Mar 2017:41 mysql-community-server-5.7.19-1.el6.x86_64.rpm -rw-r--r-- 1715531415104881084 Mar 2017:41 mysql-community-test-5.7.19-1.el6.x86_64.rpm 复制代码 4、使用rpm -ivh命令进行安装 复制代码 [root@iZwz94qazh62gk5ewl4ei2Z mysql]# rpm -ivh mysql-community-common-5.7.19-1.el6.x86_64.rpm warning: mysql-community-common-5.7.18-1.el6.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY Preparing... ################################# [100%] Updating / installing... 1:mysql-community-common-5.7.18-1.e################################# [100%] [root@iZwz94qazh62gk5ewl4ei2Z mysql]# rpm -ivh mysql-community-libs-5.7.19-1.el6.x86_64.rpm warning: mysql-community-libs-5.7.18-1.el6.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY Preparing... ################################# [100%] Updating / installing... 1:mysql-community-libs-5.7.18-1.el6################################# [100%] [root@iZwz94qazh62gk5ewl4ei2Z mysql]# rpm -ivh mysql-community-client-5.7.19-1.el6.x86_64.rpm warning: mysql-community-client-5.7.18-1.el6.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY Preparing... ################################# [100%] Updating / installing... 1:mysql-community-client-5.7.18-1.e################################# [100%] [root@iZwz94qazh62gk5ewl4ei2Z mysql]# rpm -ivh mysql-community-server-5.7.19-1.el6.x86_64.rpm warning: mysql-community-server-5.7.18-1.el6.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY Preparing... ################################# [100%] Updating / installing... 1:mysql-community-server-5.7.18-1.e################################# [100%] [root@iZwz94qazh62gk5ewl4ei2Z mysql]# 复制代码 上面几个有依赖关系,执行有先后。 使用rpm安装方式安装mysql,安装的路径如下:(系统自动配置好了,不需要手动配置) a 数据库目录 /var/lib/mysql/ b 配置文件 /usr/share/mysql(mysql.server命令及配置文件) c 相关命令 /usr/bin(mysqladmin mysqldump等命令) d 启动脚本 /etc/rc.d/init.d/(启动脚本文件mysql的目录) e /etc/my.conf 5、 数据库初始化 为了保证数据库目录为与文件的所有者为 mysql 登陆用户,如果你的linux系统是以 root 身份运行 mysql 服务,需要执行下面的命令初始化 [root@iZwz94qazh62gk5ewl4ei2Z mysql]# mysqld --initialize --user=mysql 如果是以 mysql 身份登录运行,则可以去掉 --user 选项。 另外 --initialize 选项默认以“安全”模式来初始化,则会为 root 用户生成一个密码并将该密码标记为过期,登陆后你需要设置一个新的密码, 而使用 --initialize-insecure 命令则不使用安全模式,则不会为 root 用户生成一个密码。 这里演示使用的 --initialize 初始化的,会生成一个 root 账户密码,密码在log文件里,红色区域的就是自动生成的密码 复制代码 [root@iZwz94qazh62gk5ewl4ei2Z mysql]# cat /var/log/mysqld.log 2017-06-05T14:30:52.709474Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details). 2017-06-05T14:30:55.590590Z 0 [Warning] InnoDB: New log files created, LSN=457902017-06-05T14:30:56.000269Z 0 [Warning] InnoDB: Creating foreign key constraint system tables. 2017-06-05T14:30:56.109868Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 960c533e-49fb-11e7-91f2-00163e089fd2. 2017-06-05T14:30:56.116186Z 0 [Warning] Gtid table isnot ready to be used. Table 'mysql.gtid_executed' cannot be opened. 2017-06-05T14:30:56.116777Z 1 [Note] A temporary password is generated for root@localhost: :Wu?2QQutQwj 复制代码 现在启动mysql数据库 [root@iZwz94qazh62gk5ewl4ei2Z mysql]# service mysqld start 可以使用下面两个命令对mysql进行停止,启动和重启: 启动: 使用 service 启动:service mysqld start 使用 mysqld 脚本启动:/etc/inint.d/mysqld start 使用 safe_mysqld 启动:safe_mysqld& 停止: 使用 service 启动:service mysqld stop 使用 mysqld 脚本启动:/etc/inint.d/mysqld stop mysqladmin shutdown 重启: 使用 service 启动:service mysqld restart 使用 mysqld 脚本启动:/etc/inint.d/mysqld restart 连接数据库 [root@iZwz94qazh62gk5ewl4ei2Z mysql]# mysql -u root -p Enter password: 密码输入: :Wu?2QQutQwj 修改密码: set password = password('你的密码'); 设置远程访问 grant all privileges on *.* to 'root' @'%' identified by '123456'; flush privileges; 设置mysql开机启动 复制代码 加入到系统服务: chkconfig --add mysqld 自动启动: chkconfig mysqld on 查询列表: chkconfig
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值