RedHat7.4安装mysql5.7.21

1、 Windows环境下下载mysql安装包,选择RPM Bundle 下载,这是多个rpm文件的压缩包
网址: https://dev.mysql.com/downloads/mysql/
2、 用xshell链接虚拟机的redhat7,然后再xshell中输入rz选择我们下载的安装包mysql-5.7.21-1.el7.x86_64.rpm-bundle.tar,导入的虚拟机中,并解压;
3、 检查系统是否已经安装了mysql
 rpm -aq | grep mysql,如果有旧版本就需要像下面卸载mariadb一样卸载掉。Mariadb是rhel系统已经安装好了的,需要卸载掉,Mariadb也被视为开源数据库MySQL的替代品,安装MySQL时可能有冲突,查看Mariadb,代码 rpm  -qa | grep mariadb,通过rpm -e命令将mariadb卸载掉
例如:  rpm  -e mariadb-libs-5.5.52-1.el7.x86_64 --nodeps    

  rpm -e mariadb-server-5.5.52-1.el7.x86_64  --nodeps  

  rpm  -e  mariadb-5.5.52-1.el7.x86_64  --nodeps 

4、 root用户下,在目录/usr/local下创建mysql目录,然后将我们需要安装的文件复制到该目录;
[root@bogon mysql_rpm]# cp mysql-community-client-5.7.21-1.el7.x86_64.rpm /usr/local/mysql/
[root@bogon mysql_rpm]# cp mysql-community-common-5.7.21-1.el7.x86_64.rpm /usr/local/mysql
[root@bogon mysql_rpm]# cp mysql-community-libs-5.7.21-1.el7.x86_64.rpm /usr/local/mysql/
[root@bogon mysql_rpm]# cp mysql-community-server-5.7.21-1.el7.x86_64.rpm /usr/local/mysql/
[root@bogon mysql_rpm]# cp mysql-community-devel-5.7.21-1.el7.x86_64.rpm /usr/local/mysql
5、 按顺序对rpm文件进行安装
[root@bogon mysql]# rpm -ivh mysql-community-common-5.7.21-1.el7.x86_64.rpm
警告:mysql-community-common-5.7.21-1.el7.x86_64.rpm: 头V3 DSA/SHA1 Signature, 密钥 ID 5072e1f5: NOKEY
准备中... ################################# [100%]
正在升级/安装...
1:mysql-community-common-5.7.21-1.e################################# [100%]
[root@bogon mysql]# rpm -ivh mysql-community-libs-5.7.21-1.el7.x86_64.rpm
警告:mysql-community-libs-5.7.21-1.el7.x86_64.rpm: 头V3 DSA/SHA1 Signature, 密钥 ID 5072e1f5: NOKEY
准备中... ################################# [100%]
正在升级/安装...
1:mysql-community-libs-5.7.21-1.el7################################# [100%]
[root@bogon mysql]# rpm -ivh mysql-community-client-5.7.21-1.el7.x86_64.rpm
警告:mysql-community-client-5.7.21-1.el7.x86_64.rpm: 头V3 DSA/SHA1 Signature, 密钥 ID 5072e1f5: NOKEY
准备中... ################################# [100%]
正在升级/安装...
1:mysql-community-client-5.7.21-1.e################################# [100%]
[root@bogon mysql]# rpm -ivh mysql-community-server-5.7.21-1.el7.x86_64.rpm
警告:mysql-community-server-5.7.21-1.el7.x86_64.rpm: 头V3 DSA/SHA1 Signature, 密钥 ID 5072e1f5: NOKEY
准备中... ################################# [100%]
正在升级/安装...
1:mysql-community-server-5.7.21-1.e################################# [100%]
[root@bogon mysql]# rpm -ivh mysql-community-devel-5.7.21-1.el7.x86_64.rpm
警告:mysql-community-devel-5.7.21-1.el7.x86_64.rpm: 头V3 DSA/SHA1 Signature, 密钥 ID 5072e1f5: NOKEY
准备中... ################################# [100%]
正在升级/安装...
1:mysql-community-devel-5.7.21-1.el################################# [100%]

6、 打开mysql的服务
[root@bogon mysql]# service mysqld start
Redirecting to /bin/systemctl start mysqld.service

7、 查看MySQL服务状态
[root@bogon mysql]# service mysqld status
Redirecting to /bin/systemctl status mysqld.service
● mysqld.service - MySQL Server
Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
Active: active (running) since 六 2018-01-27 20:45:49 PST; 18s ago
Docs: man:mysqld(8)
http://dev.mysql.com/doc/refman/en/using-systemd.html
Process: 50557 ExecStart=/usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid $MYSQLD_OPTS (code=exited, status=0/SUCCESS)
Process: 50473 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
Main PID: 50559 (mysqld)
CGroup: /system.slice/mysqld.service
└─50559 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid

1月 27 20:45:34 bogon systemd[1]: Starting MySQL Server...
1月 27 20:45:49 bogon systemd[1]: Started MySQL Server.

8、 MySQL安装成功后,会生成一个临时密码,我们第一次登陆需要输入这个密码,所以查看该临时密码,如下,cbZUwQ&Ry3Ut即为临时密码
[root@bogon mysql_rpm]# grep password /var/log/mysqld.log
2018-01-28T04:45:43.117298Z 1 [Note] A temporary password is generated for root@localhost: cbZUwQ&Ry3Ut

9、 登陆MySQL
登录代码 mysql -u root -p  回车就让你输入密码,输入密码的时候,粘贴上面的cbZUwQ&Ry3Ut即可;

10、修改密码
mysql> set password for 'root'@'localhost'='Aoeiuv_123';
Query OK, 0 rows affected (0.00 sec)

11、授权用户momo登陆
mysql> grant all privileges on *.* to momo@'%' identified by 'Aoeiuv_123';
Query OK, 0 rows affected, 1 warning (0.01 sec)

12、momo用户登陆MySQL
[momo@bogon mysql_rpm]$ mysql -u momo -p
Enter password: 
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 10
Server version: 5.7.21 MySQL Community Server (GPL)

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

你可能感兴趣的:(Linux)