一     查看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/

 

 2、选择对应的Linux版本和x86/x64进行下载

可以选择 RPM Bundle,下载完记得解压  tar -xvf xxx.tar

[root@nfs_client ~]# wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.22-1.el7.x86_64.rpm-bundle.tar

也可以细化下载,下载须要的mysql组件,有4个:分别是 server、client、common、libs

三 卸载旧版本的MySql (没有的话,则跳过此步骤)

1、查看旧版本MySql

rpm -qa | grep mysql

将会列出旧版本MySql的组件列表,如:

我的电脑这里只显示一个,有可能会有多个。

2、逐个删除掉旧的组件

使用命令rpm -e --nodeps {-file-name}进行移除操作,移除的时候可能会有依赖,要注意一定的顺序。

第一次没有删除成功是因为nodeps 前面的两个中划线有一个写成了中文。

四 使用 rpm 命令安装MySql组件

使用命令rpm -ivh {-file-name}进行安装操作。

按照依赖关系依次安装rpm包 依赖关系依次为common→libs→client→server

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

注:ivh中, i-install安装;v-verbose进度条;h-hash哈希校验

在安装 mysql-community-libs-5.7.22-1.el7.x86_64.rpm 时有可能会报错:mysql依赖错误

[root@nfs_client tools]# rpm -ivh mysql-community-libs-5.7.22-1.el7.x86_64.rpm
warning: mysql-community-libs-5.7.22-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
error: Failed dependencies:mysql-community-common(x86-64) >= 5.7.9 is needed by mysql-community-libs-5.7.22-1.el7.x86_64mariadb-libs is obsoleted by mysql-community-libs-5.7.22-1.el7.x86_64

解决:清除yum里所有mysql依赖包

[root@nfs_client tools]# rpm -qa|grep mysql
[root@nfs_client tools]# yum remove mysql-libs注意:
有的系统可能不太一样,没有mysql-libs,而是mariadb-libs,此时要移除的则是mariadb-libs
[root@nfs_client tools]# rpm -qa|grep mariadb
[root@nfs_client tools]# yum remove mariadb-libs

清除完yum里所有mysql的依赖包后,再次安装mysql组件就不会报错了:

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

注意细节:
1> 执行 yum remove mysql-libs   命令后,会自动删除掉 /etc/ 下的 my.cnf 文件
2> 对于安装mysql组件,只有安装了 mysql-community-server-5.7.22-1.el7.x86_64.rpm 组件,才会:
a). 在 /etc/下生成 my.cnf 文件 和 my.cnf.d 文件夹

b). 在/var/lib/下生产以下三个文件夹

c). 在/var/log/ 下生成 mysqld.log 文件

d). 在/var/run/ 下生成 mysqld 目录

个别情况:
个别情况1:

在阿里云ECS云服务器上安装mysql5.7,当安装 mysql-community-server-5.7.22-1.el7.x86_64.rpm 时报错,报错如下:

[root@i3467544tdsxfrZ ~]# rpm -ivh mysql-community-server-5.7.22-1.el7.x86_64.rpm
warning: mysql-community-server-5.7.22-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
error: Failed dependencies:
        libaio.so.1()(64bit) is needed by mysql-community-server-5.7.22-1.el7.x86_64
        libaio.so.1(LIBAIO_0.1)(64bit) is needed by mysql-community-server-5.7.22-1.el7.x86_64
        libaio.so.1(LIBAIO_0.4)(64bit) is needed by mysql-community-server-5.7.22-1.el7.x86_64

真正原因:

真正的原因是 MySQL依赖libaio,所以先要安装libaio,我们通过 rpm -qa|grep libaio 命令查看一下,如图:

经过对比发现,无法正常安装mysql-community-server-5.7.22-1.el7.x86_64的服务器的确没有安装libaio

所以,解决法案就是:

安装libaio

[root@iZbp1845cet96se1qmb5ekZ ~]# yum -y install libaio
安装libaio后,再重新安装一次mysql-community-server-5.7.22-1.el7.x86_64.rpm,此时就能正常安装了

个别情况2:

比如解决了“个别情况1”,但在启动mysql的时候,启动不起来,或启动后,去查找临时密码,使用命令没反应。查看日志mysqld.log(可在/etc/my.cnf中查找到mysqld.log的配置位置),报如下错误,此时怎么解决?

[ERROR] Fatal error: Can't open and lock privilege tables: Table 'mysql.user' doesn't exist

此时,1>先通过rpm -e --nodeps xxx  卸载掉server,卸载后删除datadir目录,2>卸载后查看 /etc/my.cnf 中,datadir的配置情况,将datedir目录删除,3>最后通过命令rpm -ivh xxx 重新安装server,此时就能正常使用mysql了

命令代码如下:

[root@izbp1845cet96se1qmb5ekz ~]# rpm -e --nodeps mysql-community-server-5.7.22-1.el7.x86_64[root@izbp1845cet96se1qmb5ekz ~]# cat /etc/my.cnf
xxxxxxxxxxxxx
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sockxxxxxxxxxxxxxxx[root@izbp1845cet96se1qmb5ekz ~]# cd /var/lib[root@izbp1845cet96se1qmb5ekz lib]# rm -rf mysql[root@izbp1845cet96se1qmb5ekz ~]# rpm -ivh mysql-community-server-5.7.22-1.el7.x86_64.rpm[root@izbp1845cet96se1qmb5ekz ~]# systemctl start mysqld.service
[root@izbp1845cet96se1qmb5ekz ~]# ps -ef|grep mysql
root      3306  1068  0 14:34 pts/0    00:00:00 mysql -uroot -p
mysql    27009     1  1 15:26 ?        00:00:00 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid
root     27038 26239  0 15:27 pts/6    00:00:00 grep --color=auto mysql

编辑my.cnf

# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html[mysqld]
#
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
#
# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin
#
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M
datadir=/home/mysql
#socket=/home/mysql/mysql.sock
character-set-server=utf8
#禁用dns反向查询,可解决IP address 'xxxx' could not be resolved: Name or service not known
skip-name-resolve
##忽略大小写
lower_case_table_names=1
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
#设置group by
sql_mode ='STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION'
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid[client]
default-character-set=utf8[mysql]
default-character-set=utf8

五 登录并创建MySql密码

1 启动MySql

安装完后,使用命令 service mysqld start 或 systemctl start mysqld.service 启动MySQL服务。(如果mysql服务无法启动,就重启一下系统)

systemctl start mysqld.service    启动mysql
systemctl status mysqld.service  查看mysql状态
systemctl stop mysqld.service   关闭mysql
查看mysql进程 ps -ef|grep mysql
查看3306端口 netstat -anop|grep 3306

eg:

[root@nfs_client tools]# ps -ef|grep mysql
mysql      4102      1  0 14:29 ?        00:00:01 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid
root       4806   1464  0 14:43 pts/0    00:00:00 grep --color=auto mysql
[root@nfs_client tools]# ps -ef|grep mysqld
mysql      4102      1  0 14:29 ?        00:00:01 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid
root       4829   1464  0 14:43 pts/0    00:00:00 grep --color=auto mysqld
[root@nfs_client tools]# firewall-cmd --state
not running
[root@nfs_client tools]# netstat -anop|grep 3306
tcp6       0      0 :::3306                 :::*                    LISTEN      4102/mysqld          off (0.00/0/0)
[root@nfs_client tools]#

2 登陆mysql修改root密码

由于MySQL5.7.4之前的版本中默认是没有密码的,登录后直接回车就可以进入数据库,进而进行设置密码等操作。其后版本对密码等安全相关操作进行了一些改变,在安装过程中,会在安装日志中生成一个临时密码。

怎么找到这个临时密码呢?

使用:

grep 'temporary password' /var/log/mysqld.log

即可查询到类似于如下的一条日志记录:

[root@nfs_client tools]# grep 'temporary password' /var/log/mysqld.log    # 在/var/log/mysqld.log文件中搜索字段‘temporary password’
2018-07-18T06:02:23.579753Z 1 [Note] A temporary password is generated for root@localhost: n(jPp4l-C33#

 n(jPp4l-C33#即为登录密码。使用这个随机密码登录进去,然后修改密码,使用命令:

   mysql -uroot -p

[root@nfs_client tools]# mysql -uroot -p
Enter password:   # 在这里输入密码
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.22Copyright (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> quit      # 输入quit 或 exit 都能退出mysql
Bye

执行下面的命令修改MySql root密码

在5.6后,mysql内置密码增强机制,低强度密码会报错:

ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
mysql> alter user root@localhost identified by 'sdbrk';
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements或
mysql> set password for root@localhost=password('sdbrk');
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements

解决方案如下:

可参见:ERROR 1819 (HY000):Your password does not satisfy the current policy requirments

step1: 更改策略,设置 validate_password_policy=0;

mysql> set global validate_password_policy=0;    # 此时,新密码长度大于等于8位才有效,否则报错

修改有效密码长度:

mysql> set global validate_password_length=1;
Query OK, 0 rows affected (0.00 sec)

不管设置  validate_password_length=1,还是2,3,4 ,‘有效密码长度’这个参数的实际值都是4。超过4后设置是多少实际就是多少。

step2:重设密码:

mysql> set password for root@localhost=password('9527');
Query OK, 0 rows affected, 1 warning (0.00 sec)

此时,虽然防火墙我时关着的,但root用户只能用于本机访问,不能用于远程访问,否则会报以下错误。因此,接下来要做的是授予root用户远程访问权限。

查看当前授予过的权限:
use mysql;
select user,host from user;

本机上:

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 -ADatabase changed
mysql> select user,host from user;
+---------------+-----------+
| user          | host      |
+---------------+-----------+
| root          | %         |
| mysql.session | localhost |
| mysql.sys     | localhost |
| root          | localhost |
+---------------+-----------+
4 rows in set (0.00 sec)mysql> show grants;
+---------------------------------------------------------------------+
| Grants for root@localhost                                           |
+---------------------------------------------------------------------+
| GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' WITH GRANT OPTION |
| GRANT PROXY ON ''@'' TO 'root'@'localhost' WITH GRANT OPTION        |
+---------------------------------------------------------------------+
2 rows in set (0.00 sec)

step3: 授予root用户远程访问权限:

mysql> grant all privileges on *.* to root@'%' identified by '9527';
Query OK, 0 rows affected, 1 warning (0.05 sec)

step4: 刷新权限,使设置生效, OK。

mysql> flush privileges;
Query OK, 0 rows affected (0.36 sec)

在远程机器上测试远程连接:  mysql -h192.168.0.241 -uroot -p

[root@localhost ~]# mysql -h192.168.0.241  -uroot -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 20
Server version: 5.7.22 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> show grants;
+-------------------------------------------+
| Grants for root@%                         |
+-------------------------------------------+
| GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' |
+-------------------------------------------+
1 row in set (0.01 sec)mysql>
mysql中可以给一个用户授予如select,insert,update,delete等其中的一个或者多个权限,主要使用grant命令,用法格式为:
grant 权限 on 数据库对象 to 用户
一、grant 普通数据用户,查询、插入、更新、删除 数据库中所有表数据的权利。
grant select on testdb.* to common_user@'%'
grant insert on testdb.* to common_user@'%'
grant update on testdb.* to common_user@'%'
grant delete on testdb.* to common_user@'%'
或者,用一条 MySQL 命令来替代:
grant select, insert, update, delete on testdb.* to common_user@'%'

centos7下安装mysql5.7(rpm)相关推荐

  1. VMware虚拟机里centos7下安装mysql5.6并授权远程连接Navicat

    正文内容 这节来安装Mysql5.6,并远程授权连接本地windows的Navicat,可以根据以下步骤安装.此文章为自己收藏,必要时拿出来直接用的,有需要的友友可以查看查看的.文章图片有借助于网络的 ...

  2. CentOS7下安装MySQL5.7安装与配置(转)

    原文地址:http://www.centoscn.com/mysql/2016/0626/7537.html 安装环境:CentOS7 64位 MINI版,安装MySQL5.7 1.配置YUM源 在M ...

  3. centos7下安装mysql5.6_Linux-CentOS7下安装mysql5.6常见问题解决!

    第一次写博客,写的不好请大家多见谅!有遇到问题可以评论到下方,我会抽空帮大家解决!! ps:安装时要遵循每一步的安装顺序 下载MySQL-5.6.tar安装包(包含server,client等) 首先 ...

  4. centos7下安装mysql之rpm方式

    文章目录 一 查看linux操作系统版本和系统内核版本 二 下载rpm安装包 1. 网页下载地址 2. 服务器直接下载 三 查看已安装的mysql,并卸载 1. 查看已有的mysql组件 2. 卸载m ...

  5. CentOS7下安装MySQL5.7安装与配置(YUM)

    安装环境:CentOS7 64位,MySQL5.7 1.配置YUM源 在MySQL官网中下载YUM源rpm安装包:http://dev.mysql.com/downloads/repo/yum/ 1 ...

  6. CentOS7下安装mysql-5.7.24

    文章目录 一:安装前期准备 1.检查是否已经安装过mysql 2.查询所有mysql对应的文件夹 3.下载linux版本的mysql安装包 二:安装mysql 1.解压文件 2.将解压后的文件重新命名 ...

  7. CentOS7下安装 mysql5.7.25(glibc版)(可用)

    一.安装前的检查 1. 检查 linux 系统版本 [root@localhost ~]# cat /etc/system-release 2. 检查是否安装了 mysql (mysql 有三种安装方 ...

  8. CentOS7 下安装 MySQL5.7 (包含mysql安装报错处理)

    1.将mysql-5.7.24-1.el7.x86_64.rpm-bundle.tar的安装包放到root跟目录下,安装版本可到MySQL官网去下载. 2.查看是否安装过MySQL,如果安装了,将其卸 ...

  9. 在CentOS7下安装mysql5.7

    一.安装YUM Repo 1.由于CentOS 的yum源中没有mysql,需要到mysql的官网下载yum repo配置文件. 下载命令: wget https://dev.mysql.com/ge ...

  10. Linux复习资料——CentOS7下安装MySQL5.7.22(完整版本)

    目录 下载地址: CSDN下载地址 xftp上传包 解压包 批量安装: 启动mysql,并查看运行状态,显示初始密码 登录MySQL 修改密码与刷新: 外网链接 下载地址: https://downl ...

最新文章

  1. Python知识点进阶——生成器
  2. AI和机器学习如何改善用户体验?
  3. (转)使.Net程序在未安装framework的电脑上运行(公布方法、源代码)
  4. 从原理上搞懂如何设置线程池参数大小?
  5. 【数据结构-查找】4.五千字干活长文带你搞懂——B树和B+树
  6. 类QQ右下角弹出框(Qt)
  7. FirefoxOS 1.2 on ZTE Open
  8. Python入门6_抽象
  9. Cmake构建_设置全局编译选项
  10. VAF:高级Web模糊测试工具
  11. Edison:FL Studio中的常用音频录制与剪辑插件
  12. 玩转直播:如何从 0 到 1 构建简单直播系统
  13. 1142:单词的长度c语言解法
  14. Win10突然就不能连接网络了怎么办
  15. 我的家计算机教学反思,我的家教学反思
  16. 风变Python之旅4---字典列表的学习
  17. JSON long 型 数字过长精度丢失解决
  18. 【云杂谈】《公共云被用于黑客和恐怖活动的风险》
  19. CTF 隐写工具Steghide
  20. 计算机网络知识总结!!!

热门文章

  1. vue 点击按钮改变颜色
  2. 阿里云ASR 语音识别接口调用
  3. 28、ZigBee 开发教程之基础篇—红外对射计数器
  4. python怎么换背景颜色_Python给照片换底色(蓝底换红底)
  5. sdk寄存器地址linux,S32K SDK使用详解之PinSettings组件配置与使用详解(S32K1xx PORT 和GPIO模块)...
  6. 专利欠费怎么办?教你在网上缴纳专利年费,全网最详细步骤
  7. 软件著作权算法软件设计说明书_软件著作权设计说明书范本.doc
  8. python的flask前端显示图片_Python flask框架如何显示图像到web页面
  9. nslookup默认服务器修改,Windows nslookup“默认服务器:未知”是什么意思
  10. SAP License:SAP五大主流ERP一览