Linux下MySQL的安装-rpm包安装

在我们Linux 下MySQL 安装之yum命令安装介绍了使用yum 命令安装MySQL,本篇我们介绍使用rpm包安装MySQL,与使用yum安装一样。rpm安装之前也需要检查是否已经安装过MySQL服务器,具体步骤和用yum安装之前的检查一样。

使用RPM安装MySQL我们首先需要下载相应的RPM包,在这之前,我们需要查看自己的系统的内核,然后在镜像网站:http://mirrors.sohu.com/mysql/MySQL-5.7/下载相应的RPM包。我们可以使用uname -a查看系统版本:

[root@192 ~]# uname -an
Linux 192.168.226.129 3.10.0-514.el7.x86_64 #1 SMP Tue Nov 22 16:42:41 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux

之后,我们可以从镜像网站下载MySQL RPM包,并且上传到我们的服务器,需要下载的RPM包邮mysql-community-server-5.7.17-1.el7.x86_64.rpm和mysql-community-client-5.7.16-1.el7.x86_64.rpm。实际上只下载这两个包是不够的,因为他们有自己的依赖包,这里先不下载,我们查看执行这两个包时会出现什么问题。如下我们使用rpm命令执行RPM包时的信息:

[root@192 Downloads]# rpm -ivh mysql-community-client-5.7.16-1.el7.x86_64.rpm 
warning: mysql-community-client-5.7.16-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
error: Failed dependencies:
	mysql-community-libs(x86-64) >= 5.7.9 is needed by mysql-community-client-5.7.16-1.el7.x86_64
[root@192 Downloads]# rpm -ivh mysql-community-server-5.7.17-1.el7.x86_64.rpm 
warning: mysql-community-server-5.7.17-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
error: Failed dependencies:
	mysql-community-client(x86-64) >= 5.7.9 is needed by mysql-community-server-5.7.17-1.el7.x86_64
	mysql-community-common(x86-64) = 5.7.17-1.el7 is needed by mysql-community-server-5.7.17-1.el7.x86_64

通过上面的信息,我们可以看到server和client包需要依赖mysql-community-common-5.7.17-1.el7.x86_64.rpm和mysql-community-libs-5.7.17-1.el7.x86_64.rpm两个包,我们需要从镜像网站下载这两个RPM包。然后我们就可以继续执行mysql的rmp包,执行过程如下:

[root@192 Downloads]# rpm -ivh mysql-community-common-5.7.17-1.el7.x86_64.rpm 
warning: mysql-community-common-5.7.17-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:mysql-community-common-5.7.17-1.e################################# [100%]
[root@192 Downloads]# rpm -ivh mysql-community-libs-5.7.17-1.el7.x86_64.rpm 
warning: mysql-community-libs-5.7.17-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:mysql-community-libs-5.7.17-1.el7################################# [100%]
[root@192 Downloads]# rpm -ivh mysql-community-client-5.7.16-1.el7.x86_64.rpm 
warning: mysql-community-client-5.7.16-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:mysql-community-client-5.7.16-1.e################################# [100%]
[root@192 Downloads]# rpm -ivh mysql-community-server-5.7.17-1.el7.x86_64.rpm 
warning: mysql-community-server-5.7.17-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:mysql-community-server-5.7.17-1.e################################# [100%]

然后我们启动mysql服务,通过mysql客户端,连接mysql,与用yum不同的时,使用RPM包安装之后,root用户被设置了密码,而我们此时不知道密码,无法连接到mysql服务,命令如下所示:

[root@192 ~]#/bin/systemctl start  mysqld.service
[root@192 ~]# mysql -uroot
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

此时我们关闭MySQL服务,设置启动MySQL环境时跳过权限检查表,重启MySQL之后就能进入mysql,命令如下:

[root@192 ~]#  /bin/systemctl stop  mysqld.service
[root@192 ~]# systemctl set-environment MYSQLD_OPTS="--skip-grant-tables"
[root@192 ~]#  /bin/systemctl start  mysqld.service
[root@192 ~]# mysql -uroot
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.17 MySQL Community Server (GPL)

Copyright (c) 2000, 2016, 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.

更改root用户密码,此时不同的版本可能密码存储字段不同,当前版本字段为authentication_string,所以使用password字段时会报列名不存在错误,如下为修改密码的命令:

mysql> use mysql
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> update user set password=PASSWORD('123456') where user='root';
ERROR 1054 (42S22): Unknown column 'password' in 'field list'
mysql> update user set authentication_string=PASSWORD('123456') where user='root';
Query OK, 1 row affected, 1 warning (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 1
mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)

到此MySQL安装就结束了。然后关闭MySQL把前面设置的环境关闭,重新进入MySQL输入自己设置的密码即可,命令如下:

[root@192 ~]#  /bin/systemctl stop  mysqld.service
[root@192 ~]# systemctl unset-environment MYSQLD_OPTS8
[root@192 ~]#  /bin/systemctl start  mysqld.service
[root@192 ~]# mysql -uroot -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.17 MySQL Community Server (GPL)

Copyright (c) 2000, 2016, 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.

猜你喜欢

转载自blog.csdn.net/wk19920726/article/details/108428206
今日推荐