1.下载mysql

官网地址:https://dev.mysql.com/downloads/mysql/5.7.html#downloads

注意事项

(1)下载的安装包必须是.rpm-bundle.tar结尾的

(2)安装的时候,对应自己的下载版本号,不要直接复制命令

2.下载完成后,通过ftp上传到Linux服务器上

(1)创建mysql5.7.23目录

[root@VM_0_16_centos ~]# mkdir mysql5.7.23
mysql5.7.23

(2)将下载好的安装上传到该目录下

[root@VM_0_16_centos ~]# cd mysql5.7.23
[root@VM_0_16_centos mysql5.7.23]# ls
mysql-5.7.23-1.el7.x86_64.rpm-bundle.tar

3.解压安装包(mysql-5.7.23-1.el7.x86_64.rpm-bundle.tar)

[root@VM_0_16_centos mysql5.7.23]# tar xvf mysql-5.7.23-1.el7.x86_64.rpm-bundle.tar
mysql-community-common-5.7.23-1.el7.x86_64.rpm
mysql-community-libs-compat-5.7.23-1.el7.x86_64.rpm
mysql-community-minimal-debuginfo-5.7.23-1.el7.x86_64.rpm
mysql-community-server-5.7.23-1.el7.x86_64.rpm
mysql-community-devel-5.7.23-1.el7.x86_64.rpm
mysql-community-libs-5.7.23-1.el7.x86_64.rpm
mysql-community-client-5.7.23-1.el7.x86_64.rpm
mysql-community-server-minimal-5.7.23-1.el7.x86_64.rpm
mysql-community-test-5.7.23-1.el7.x86_64.rpm
mysql-community-embedded-devel-5.7.23-1.el7.x86_64.rpm
mysql-community-embedded-5.7.23-1.el7.x86_64.rpm
mysql-community-embedded-compat-5.7.23-1.el7.x86_64.rpm
[root@VM_0_16_centos mysql5.7.23]#

 4.卸载掉centos7自带的mariadb-lib

方法一:

(1)查询mariadb信息


[root@VM_0_16_centos mysql5.7.23]# rpm -qa|grep mariadb
mariadb-libs-5.5.56-2.el7.x86_64

(2)使用rpe -e命令卸载

[root@VM_0_16_centos mysql5.7.23]# rpm -e mariadb-libs-5.5.56-2.el7.x86_64 --nodeps

此方法卸载失败或者报错,请使用方法二

方法二:

使用yum remove 命名进行删除

[root@VM_0_16_centos mysql5.7.23]# yum remove mysql-libs
------------------------------------------------------------------------------------------------------------------------
已加载插件:fastestmirror, langpacks
正在解决依赖关系
--> 正在检查事务
---> 软件包 mariadb-libs.x86_64.1.5.5.44-2.el7.centos 将被 删除
--> 正在处理依赖关系 libmysqlclient.so.18()(64bit),它被软件包 2:postfix-2.10.1-6.el7.x86_64 需要
--> 正在处理依赖关系 libmysqlclient.so.18(libmysqlclient_18)(64bit),它被软件包 2:postfix-2.10.1-6.el7.x86_64 需要
--> 正在检查事务
---> 软件包 postfix.x86_64.2.2.10.1-6.el7 将被 删除
--> 解决依赖关系完成
base/7/x86_64                                                                                                   | 3.6 kB  00:00:00
extras/7/x86_64                                                                                                 | 3.4 kB  00:00:00
updates/7/x86_64                                                                                                | 3.4 kB  00:00:00
依赖关系解决
=======================================================================================================================================Package                         架构                      版本                                     源                            大小
=======================================================================================================================================
正在删除:mariadb-libs                    x86_64                    1:5.5.44-2.el7.centos                    @anaconda                    4.4 M
为依赖而移除:postfix                         x86_64                    2:2.10.1-6.el7                           @anaconda                     12 M
事务概要
=======================================================================================================================================
移除  1 软件包 (+1 依赖软件包)
安装大小:17 M
是否继续?[y/N]:y
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
警告:RPM 数据库已被非 yum 程序修改。
** 发现 4 个已存在的 RPM 数据库问题, 'yum check' 输出如下:
icedtea-web-1.6.1-4.el7.x86_64 有缺少的需求 java-1.8.0-openjdk
jline-1.0-8.el7.noarch 有缺少的需求 java >= ('0', '1.5', None)
1:libreoffice-core-4.3.7.2-5.el7.x86_64 有缺少的需求 java-headless >= ('1', '1.6', None)
1:libreoffice-ure-4.3.7.2-5.el7.x86_64 有缺少的需求 libjvm.so()(64bit)正在删除    : 2:postfix-2.10.1-6.el7.x86_64                                                                                      1/2正在删除    : 1:mariadb-libs-5.5.44-2.el7.centos.x86_64                                                                          2/2验证中      : 1:mariadb-libs-5.5.44-2.el7.centos.x86_64                                                                          1/2验证中      : 2:postfix-2.10.1-6.el7.x86_64                                                                                      2/2
删除:mariadb-libs.x86_64 1:5.5.44-2.el7.centos
作为依赖被删除:postfix.x86_64 2:2.10.1-6.el7
完毕!

5.安装mysql-server服务,只需要安装如下4个软件包即可,使用rpm -ivh进行安装(按顺序安装,后面的服务依赖前面的服务)

[root@VM_0_16_centos mysql5.7.23]# rpm -ivh mysql-community-common-5.7.23-1.el7.x86_64.rpm
警告:mysql-community-common-5.7.23-1.el7.x86_64.rpm: 头V3 DSA/SHA1 Signature, 密钥 ID 5072e1f5: NOKEY
准备中...                          ################################# [100%]
正在升级/安装...1:mysql-community-common-5.7.23-1.e################################# [100%]
[root@VM_0_16_centos mysql5.7.23]# rpm -ivh mysql-community-libs-5.7.23-1.el7.x86_64.rpm
警告:mysql-community-libs-5.7.23-1.el7.x86_64.rpm: 头V3 DSA/SHA1 Signature, 密钥 ID 5072e1f5: NOKEY
准备中...                          ################################# [100%]
正在升级/安装...1:mysql-community-libs-5.7.23-1.el7################################# [100%]
[root@VM_0_16_centos mysql5.7.23]# rpm -ivh mysql-community-client-5.7.23-1.el7.x86_64.rpm
警告:mysql-community-client-5.7.23-1.el7.x86_64.rpm: 头V3 DSA/SHA1 Signature, 密钥 ID 5072e1f5: NOKEY
准备中...                          ################################# [100%]
正在升级/安装...1:mysql-community-client-5.7.23-1.e################################# [100%]
[root@VM_0_16_centos mysql5.7.23]# rpm -ivh mysql-community-server-5.7.23-1.el7.x86_64.rpm
警告:mysql-community-server-5.7.23-1.el7.x86_64.rpm: 头V3 DSA/SHA1 Signature, 密钥 ID 5072e1f5: NOKEY
准备中...                          ################################# [100%]
正在升级/安装...1:mysql-community-server-5.7.23-1.e################################# [100%]

6.安装过程中可能出现的问题

1).缺少libaio
[root@VM_0_16_centos mysql5.7.23]# rpm -ivh mysql-community-server-5.7.17-1.el7.x86_64.rpm
警告:mysql-community-server-5.7.17-1.el7.x86_64.rpm: 头V3 DSA/SHA1 Signature, 密钥 ID 5072e1f5: NOKEY
错误:依赖检测失败:libaio.so.1()(64bit) 被 mysql-community-server-5.7.17-1.el7.x86_64 需要libaio.so.1(LIBAIO_0.1)(64bit) 被 mysql-community-server-5.7.17-1.el7.x86_64 需要libaio.so.1(LIBAIO_0.4)(64bit) 被 mysql-community-server-5.7.17-1.el7.x86_64 需要net-tools 被 mysql-community-server-5.7.17-1.el7.x86_64 需要
解决办法:
[root@VM_0_16_centos mysql5.7.23]# yum install libaio
2)缺少net-tools
[root@VM_0_16_centos mysql5.7.23]# rpm -ivh mysql-community-server-5.7.17-1.el7.x86_64.rpm
警告:mysql-community-server-5.7.17-1.el7.x86_64.rpm: 头V3 DSA/SHA1 Signature, 密钥 ID 5072e1f5: NOKEY
错误:依赖检测失败:net-tools 被 mysql-community-server-5.7.17-1.el7.x86_64 需要
解决办法:yum install net-tools
3)缺少numactl
[root@VM_0_16_centos mysql5.7.23]# rpm -ivh mysql-community-server-5.7.17-1.el7.x86_64.rpm 报错:warning: mysql-community-server-5.7.9-1.el6.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
error: Failed dependencies:libnuma.so.1()(64bit) is needed by mysql-community-server-5.7.9-1.el6.x86_64libnuma.so.1(libnuma_1.1)(64bit) is needed by mysql-community-server-5.7.9-1.el6.x86_64libnuma.so.1(libnuma_1.2)(64bit) is needed by mysql-community-server-5.7.9-1.el6.x86_64解决办法:yum  install numactl

7.初始化数据库

[root@VM_0_16_centos mysql5.7.23]# mysqld --initialize  #初始化后会在/var/log/mysqld.log生成随机密码

8.修改mysql数据库目录的所属用户及其所属组,然后启动mysql数据库

[root@VM_0_16_centos mysql5.7.23]# chown mysql:mysql /var/lib/mysql -R
[root@VM_0_16_centos mysql5.7.23]# systemctl start mysqld.service
[root@VM_0_16_centos mysql5.7.23]# systemctl status mysqld.service
● mysqld.service - MySQL ServerLoaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)Active: active (running) since 一 2018-08-06 20:41:25 CST; 6s agoDocs: man:mysqld(8)http://dev.mysql.com/doc/refman/en/using-systemd.htmlProcess: 13031 ExecStart=/usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid $MYSQLD_OPTS (code=exited, status=0/SUCCESS)Process: 13003 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)Main PID: 13034 (mysqld)Tasks: 27CGroup: /system.slice/mysqld.service└─13034 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid8月 06 20:41:22 eric111 systemd[1]: Starting MySQL Server...
8月 06 20:41:25 eric111 systemd[1]: Started MySQL Server.

9.登录mysql,并修改root用户的密码(系统强制要求,否则不能操作mysql)

初始登录密码可在/var/log/mysqld.log文件中找到

[root@VM_0_16_centos mysql5.7.23]# mysql -uroot -p'-4iq<tyjVpLb'
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.23Copyright (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> set password=password('123456');
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
4 rows in set (0.00 sec)

10.开启无密码登录模式

(1)mysql的配置文件在etc目录下,默认是my.cnf

[root@localhost /]# cd etc
[root@localhost etc]# find my.cnf
my.cnf
[root@localhost etc]# ls
abrt                     crontab                  gcrypt       kernel                    mtab               printcap        scl             system-release
adjtime                  cron.weekly              gdbinit      krb5.conf                 my.cnf             profile         securetty       system-release-cpe
aliases                  crypttab                 gdbinit.d    ld.so.cache               my.cnf.d           profile.d       security        tcsd.conf[root@localhost etc]#

(2)编辑my.cnf文件,加入skip-grant-tables配置,开启无密码登录

打开my.cnf文件,输入如下命令,按回车

[root@localhost etc]# vim /etc/my.cnf

按insert键切换编辑模式,增加skip-grant-tables配置

# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html[mysqld]
skip-grant-tables......省略......

(3)保存并退出,然后重启mysql服务

按esc键后,输入:wq   按回车键,保存退出,或者输入:wq!   按回车键,强制保存并退出

重启mysql服务

[root@localhost etc]# systemctl restart mysqld.service
[root@localhost etc]#

(4)登录mysql

[root@localhost etc]# mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.30 MySQL Community Server (GPL)Copyright (c) 2000, 2020, 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>

11.修改登录密码

(1)使用mysql数据库

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>

(2)查看mysql当前用户信息

host字段是允许连接mysql服务的客户端主机,%代表所有客户端主机,localhost代表只能在当前主机访问,及本地访问

user字段是登录mysql的用户名称,当前默认有root、mysql.sys、mysql.session三个用户

authentication_string字段是登录mysql的用户密码,加密后的密码,该字段是mysql5.7版本开始使用,之前版本字段为password

mysql> select host,user,authentication_string from user;
+-----------+---------------+-------------------------------------------+
| host      | user          | authentication_string                     |
+-----------+---------------+-------------------------------------------+
| %         | root          | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |
| localhost | mysql.session | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE |
| localhost | mysql.sys     | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE |
+-----------+---------------+-------------------------------------------+
3 rows in set (0.00 sec)mysql>

(3)修改root用户的密码为123456,以及客户端主机访问限制,允许所有主机访问,修改完成,使用flush privileges;刷新权限

mysql> update user set host='%',authentication_string=password('123456') where user='root';
Query OK, 0 rows affected, 1 warning (0.02 sec)
Rows matched: 1  Changed: 0  Warnings: 1mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)mysql>

(4)修改密码中,可能出现的错误解决

错误信息:

ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.

解决方案:

alter user 'root'@'%' identified by '123456';

12.修改访问权限

目的:任何主机通过用户root和密码123456连接到mysql服务器,并授权所有权限

mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456' WITH GRANT OPTION;
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)

13.取消无密码登录模式

(1)注释或者删除/etc/my.cnf文件中的skip-grant-tables配置

(2)重启mysql服务(systemctl restart mysqld.service)

到此,在Linux中,安装mysql的教程结束,如有不会,请@我

参考原文:

https://blog.csdn.net/tanjun592/article/details/71797972?locationNum=9&fps=1

https://blog.csdn.net/smiles13/article/details/81460617

Linux安装mysql(mysql-5.7.23-1.el7.x86_64.rpm-bundle.tar)(万能解决登录问题,最详细教程)相关推荐

  1. Linux安装jdk,mysql,tomcat,redis和nginx

    Linux安装jdk,mysql,tomcat,redis和nginx 1. jdk 2. mysql 3. tomcat 4. redis 5. nginx 首先安装lrzsz: yum -y in ...

  2. Linux安装卸载Mysql与基本操作

    一.安装Mysql软件 1.下载rpm包 本文章使用的系统是Linux,所以你需要下载一个mysql的rpm包 https://dev.mysql.com/downloads/ 根据系统版本下载,Ce ...

  3. linux安装主从mysql,mysql8.0安装以及主从复制搭建(linux)

    一主一从: 前提: 两台centos7(虚拟机或云服务器) 防火墙已关闭 主master:192.168.17.201 msql8.0.12 从slave:192.168.17.202 msql8.0 ...

  4. linux安装指定mysql版本安装,linux yum安装指定版本mysql

    1.下载mysql rpm包 cd /usr/local/src wget https://dev.mysql.com/get/mysql80-community-release-el7-.noarc ...

  5. linux安装卸载mysql,Linux6 系列 安装、卸载mysql

    Linux6 系列 安装.卸载mysql Linux6 系列 安装.卸载mysql Linux环境下载mysql: https://blog.csdn.net/weixin_40816738/arti ...

  6. linux 安装qt mysql库_Linux下QT平台Mysql数据库开发环境配置

    This doucment is about how to add mysql driver into QT and about database connections     由于之前安装RedH ...

  7. linux安装完mysql没有服务_Linux中安装mysql之后 mysql服务不能启动

    展开全部 1.可能是/usr/local/mysql/data/rekfan.pid文件没有写的权限 解决方法 :给予权限,执行 "chown -R mysql:mysql /var/dat ...

  8. linux安装jdk mysql tomcat之部署项目

    最近项目上线自己操作了几遍linux部署项目,有点心得写下来,也是第一次写博客的菜鸟,有不对之处,欢迎各位提出意见- 要求:已经安装好了虚拟机 目的:在虚拟机中安装各软件并实施ssh项目的部署 准备: ...

  9. Linux安装JDK,MySQL,Tomcat,Redis等软件

    添加微信号GO_HOME_2020一起探讨Java Linux安装软件 安装JDK 第一步 查看系统中是否存在JDk 第二步 安装JDK 第三步 配置环境变量 第四步 使配置的环境变量生效 第五步 查 ...

最新文章

  1. Python:阳光热线问政平台爬虫
  2. 五大分布式事务,你了解多少?
  3. Tyche 2147 旅行
  4. 在https上面使用ws不加密_ASP.NET Core 3.1 中使用JWT认证
  5. unity有用资源的导出未package便于在其他工程用的问题解决
  6. nsis出错_nsis error解决方法
  7. html设置默认选中状态,html select 标签设置默认选中
  8. Mixly-继电器控制直流电机
  9. word画图关闭自动捕捉功能
  10. row_number() over (partition by....order by...)用法
  11. 【leetcode-字符串】:重复的子字符串(是否由它的一个子串重复多次构成)
  12. 一个邮箱联结全球?也许不会是遥不可及的梦想
  13. Linux服务器下安装vsftpd,搭建文件服务器
  14. matlab积分求解(定积分/不定积分)总结
  15. HDU-4544-湫湫系列故事——消灭兔子--贪心+优先队列
  16. Hadoop起源简介
  17. linux下c通过虚拟地址映射读写文件
  18. Python + opencv 调用工业相机对模块进行拍照扫描并分析内容(一)
  19. PPT:基于5G的智慧仓储解决方案
  20. Photoshop期末大作业

热门文章

  1. Alfred Workflow 入门指南
  2. c语言教学知识,C语言的编程教程_入门教学知识
  3. android 判断文件是否存在
  4. 成功者刻骨铭心的一句话
  5. 深度学习的应用——检測糖尿病型视网膜症
  6. 图的m色着色问题 回溯法(算法设计与分析)Java
  7. 基于特征的图像匹配算法,图片相似度匹配算法
  8. SOAP Version 1.2
  9. Apple Store 亮相中国
  10. Hadoop源代码分析(完整图文版) part 1