环境:centos:7.5
查看centos7的版本
[root@localhost ~]# cat /etc/redhat-release
CentOS Linux release 7.5.1804 (Core)
[root@localhost ~]#
检查是否安装mysql
[root@localhost ~]# yum list installed | grep mariadb
mariadb-libs.x86_64 1:5.5.56-2.el7 @anaconda
卸载安装包
[root@localhost ~]# yum -y remove mariadb*
已加载插件:fastestmirror
正在解决依赖关系
--> 正在检查事务
---> 软件包 mariadb-libs.x86_64.1.5.5.56-2.el7 将被 删除
--> 正在处理依赖关系 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 将被 删除
--> 解决依赖关系完成
依赖关系解决
==========================================================================================================================
Package 架构 版本 源 大小
==========================================================================================================================
正在删除:
mariadb-libs x86_64 1:5.5.56-2.el7 @anaconda 4.4 M
再次查看
[root@localhost ~]# yum list installed | grep mariadb
[root@localhost ~]#
下载RPM
[root@localhost ~]# cd /usr/local/
[root@localhost local]# mkdir mysql
[root@localhost local]# cd mysql/
[root@localhost mysql]# wget https://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm
--2021-03-31 19:44:56-- https://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm
正在解析主机 dev.mysql.com (dev.mysql.com)... 137.254.60.11
正在连接 dev.mysql.com (dev.mysql.com)|137.254.60.11|:443... 已连接。
已发出 HTTP 请求,正在等待回应... 302 Found
位置:https://repo.mysql.com//mysql57-community-release-el7-11.noarch.rpm [跟随至新的 URL]
--2021-03-31 19:44:57-- https://repo.mysql.com//mysql57-community-release-el7-11.noarch.rpm
正在解析主机 repo.mysql.com (repo.mysql.com)... 104.75.165.42
正在连接 repo.mysql.com (repo.mysql.com)|104.75.165.42|:443... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:25680 (25K) [application/x-redhat-package-manager]
正在保存至: “mysql57-community-release-el7-11.noarch.rpm”
100%[================================================================================>] 25,680 --.-K/s 用时 0s
2021-03-31 19:44:58 (254 MB/s) - 已保存 “mysql57-community-release-el7-11.noarch.rpm” [25680/25680])
如果想要确认下载的文件是否完整,可通过md5sum生成MD5值并确保官方网站上的MD5值相同,以确保文件无损坏。
[root@localhost mysql]# md5sum mysql57-community-release-el7-11.noarch.rpm
c070b754ce2de9f714ab4db4736c7e05 mysql57-community-release-el7-11.noarch.rpm
[root@localhost mysql]#
安装RPM包,并确认yum源
[root@localhost mysql]# rpm -ivh mysql57-community-release-el7-11.noarch.rpm
警告:mysql57-community-release-el7-11.noarch.rpm: 头V3 DSA/SHA1 Signature, 密钥 ID 5072e1f5: NOKEY
准备中... ################################# [100%]
正在升级/安装...
1:mysql57-community-release-el7-11 ################################# [100%]
[root@localhost mysql]# yum repolist enabled | grep "mysql.*-community.*"
mysql-connectors-community/x86_64 MySQL Connectors Community 185
mysql-tools-community/x86_64 MySQL Tools Community 123
mysql57-community/x86_64 MySQL 5.7 Community Server 484
查看mysql版本
[root@localhost mysql]# yum repolist all | grep mysql
mysql-cluster-7.5-community/x86_64 MySQL Cluster 7.5 Community 禁用
mysql-cluster-7.5-community-source MySQL Cluster 7.5 Community - So 禁用
mysql-cluster-7.6-community/x86_64 MySQL Cluster 7.6 Community 禁用
mysql-cluster-7.6-community-source MySQL Cluster 7.6 Community - So 禁用
mysql-connectors-community/x86_64 MySQL Connectors Community 启用: 185
mysql-connectors-community-source MySQL Connectors Community - Sou 禁用
mysql-tools-community/x86_64 MySQL Tools Community 启用: 123
mysql-tools-community-source MySQL Tools Community - Source 禁用
mysql-tools-preview/x86_64 MySQL Tools Preview 禁用
mysql-tools-preview-source MySQL Tools Preview - Source 禁用
mysql55-community/x86_64 MySQL 5.5 Community Server 禁用
mysql55-community-source MySQL 5.5 Community Server - Sou 禁用
mysql56-community/x86_64 MySQL 5.6 Community Server 禁用
mysql56-community-source MySQL 5.6 Community Server - Sou 禁用
mysql57-community/x86_64 MySQL 5.7 Community Server 启用: 484
mysql57-community-source MySQL 5.7 Community Server - Sou 禁用
mysql80-community/x86_64 MySQL 8.0 Community Server 禁用
mysql80-community-source MySQL 8.0 Community Server - Sou 禁用
安装mysql
[root@localhost mysql]# yum install mysql-community-server
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.aliyun.com
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
(1/2): mysql57-community/x86_64/primary_db | 258 kB 00:00:00
(2/2): epel/x86_64/primary_db | 6.9 MB 00:00:08
正在解决依赖关系
--> 正在检查事务
---> 软件包 mysql-community-server.x86_64.0.5.7.33-1.el7 将被 安装
--> 正在处理依赖关系 mysql-community-common(x86-64) = 5.7.33-1.el7,它被软件包 mysql-community-server-5.7.33-1.el7.x86_64 需要
--> 正在处理依赖关系 mysql-community-client(x86-64) >= 5.7.9,它被软件包 mysql-community-server-5.7.33-1.el7.x86_64 需要
--> 正在检查事务
---> 软件包 mysql-community-client.x86_64.0.5.7.33-1.el7 将被 安装
--> 正在处理依赖关系 mysql-community-libs(x86-64) >= 5.7.9,它被软件包 mysql-community-client-5.7.33-1.el7.x86_64 需要
---> 软件包 mysql-community-common.x86_64.0.5.7.33-1.el7 将被 安装
--> 正在检查事务
---> 软件包 mysql-community-libs.x86_64.0.5.7.33-1.el7 将被 安装
启动mysql并查看进程
[root@localhost mysql]# systemctl start mysqld
[root@localhost mysql]# ps -ef|grep mysqld |grep -v grep
mysql 11534 1 0 20:06 ? 00:00:00 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid
登录mysql
[root@localhost mysql]# mysql -u root
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
刚安装的 MySQL 是没有密码的,所以需要设置密码
① 停止 MySQL 服务:
[root@localhost mysql]# systemctl stop mysqld
② 以不检查权限的方式启动 MySQL:
[root@localhost mysql]# mysqld --user=root --skip-grant-tables &
[1] 11580
③ 再次输入 mysql -u root 或者 mysql,这次就可以进来了。
[root@localhost mysql]# mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.33 MySQL Community Server (GPL)
Copyright (c) 2000, 2021, Oracle and/or its affiliates.
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>
④ 更新密码:
mysql> UPDATE mysql.user SET authentication_string=PASSWORD('artisan') where USER='root';
Query OK, 1 row affected, 1 warning (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 1
⑤ 刷新:
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
⑥ 退出:
mysql> exit
Bye
[root@localhost mysql]#
设置完之后,这时输入刚设置的密码,就可以登进数据库了。
[root@localhost mysql]# mysql -uroot -partisan
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 4
Server version: 5.7.33
Copyright (c) 2000, 2021, Oracle and/or its affiliates.
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>
mysql5.7安装完毕!!!!!!!