cd /home/apps/mysql
## 解压缩
tar -zvf
下载Mysql :
我是从网易开源镜像站开源下载的 : http://mirrors.163.com/mysql/Downloads/MySQL-5.7/mysql-5.7.24-1.el7.x86_64.rpm-bundle.tar
解压安装 :
cd /home/app/mysql
##解压
tar -xvf MySQL-5.7/mysql-5.7.24-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
卸载掉centos7自带的mariadb-lib:
- 方法一 :
- 查询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
2. 使用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
完毕!
安装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%]
初始化数据库
[root@VM_0_16_centos mysql5.7.23]# mysqld --initialize #初始化后会在/var/log/mysqld.log生成随机密码
## 出现错误
--initialize specified but the data directory has files in it. Aborting
## 解决
将 /var/lib/mysql 目录备份 并重新创建一个空文件夹
参考: https://blog.csdn.net/qq_28652401/article/details/83478811
修改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.
登录mysql,并修改root用户的密码(系统强制要求,否则不能操作mysql)
[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('password11');
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
4 rows in set (0.00 sec)
修改访问权限
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'password11' WITH GRANT OPTION;
参考链接 : https://blog.csdn.net/qq_23123177/article/details/82759057