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

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_64
        libnuma.so.1(libnuma_1.1)(64bit) is needed by mysql-community-server-5.7.9-1.el6.x86_64
        libnuma.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 Server
   Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
   Active: active (running) since 一 2018-08-06 20:41:25 CST; 6s ago
     Docs: man:mysqld(8)
           http://dev.mysql.com/doc/refman/en/using-systemd.html
  Process: 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: 27
   CGroup: /system.slice/mysqld.service
           └─13034 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid
 
8月 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.23
 
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> 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 -A

Database 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: 1

mysql> 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

评论 7
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值