Centos7 安装 Mysql5.7 阿里云安装

本贴最后更新于 2218 天前,其中的信息可能已经东海扬尘

Centos7 安装 Mysql5.7 阿里云安装

可以参照之前第一篇的 Mysql 安装,都是可以的
CentOS7 安装 Mysql

卸载

卸载掉安装的部分 首先执行查看命令,看一下都安转了什么东东:

[root@ppl ~]# rpm -qa|grep -i mysql
mysql57-community-release-el7-10.noarch
mysql-community-client-5.7.24-1.el7.x86_64
mysql-community-libs-5.7.24-1.el7.x86_64
mysql-community-libs-compat-5.7.24-1.el7.x86_64
mysql-community-common-5.7.24-1.el7.x86_64
mysql-community-server-5.7.24-1.el7.x86_64
[root@ppl ~]#

有的话就开始卸载 执行卸载命令:

yum remove mysql-community mysql-community-server mysql-community-libs mysql-communitycommon
yum remove mysql57-community-release-el7-10.noarch

终极检查 再进行一遍检查: rpm -qa |grep -i mysql ,安装部分已完全卸载掉。
清理文件 查看 mysql 文件目录: find / -name mysql .

[root@ppl ~]# rpm -qa|grep -i mysql
[root@ppl ~]# find / -name mysql
/usr/share/mysql
[root@ppl ~]# rm -rf /usr/share/mysql
[root@ppl ~]# find / -name mysql
[root@ppl ~]#

安装

下载 mysql 源安装包

[root@ppl ~]# wget http://dev.mysql.com/get/mysql57-community-release-el7-9.noarch.rpm
--2018-11-05 23:29:42-- http://dev.mysql.com/get/mysql57-community-release-el7-
9.noarch.rpm
Resolving dev.mysql.com (dev.mysql.com)... 137.254.60.11
Connecting to dev.mysql.com (dev.mysql.com)|137.254.60.11|:80... connected.
HTTP request sent, awaiting response... 302 Found
Location: http://101.96.10.45/dev.mysql.com/get/mysql57-community-release-el7-
9.noarch.rpm [following]
--2018-11-05 23:29:42-- http://101.96.10.45/dev.mysql.com/get/mysql57-communityrelease-
el7-9.noarch.rpm
Connecting to 101.96.10.45:80... connected.
HTTP request sent, awaiting response... 301 Moved Permanently
Location: https://dev.mysql.com/get/mysql57-community-release-el7-9.noarch.rpm
[following]
--2018-11-05 23:29:42-- https://dev.mysql.com/get/mysql57-community-release-el7-
9.noarch.rpm
Connecting to dev.mysql.com (dev.mysql.com)|137.254.60.11|:443... connected.
HTTP request sent, awaiting response... 302 Found
Location: https://repo.mysql.com//mysql57-community-release-el7-9.noarch.rpm
[following]
--2018-11-05 23:29:44-- https://repo.mysql.com//mysql57-community-release-el7-
9.noarch.rpm
Resolving repo.mysql.com (repo.mysql.com)... 23.41.23.231
Connecting to repo.mysql.com (repo.mysql.com)|23.41.23.231|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 9224 (9.0K) [application/x-redhat-package-manager]
Saving to: ‘mysql57-community-release-el7-9.noarch.rpm’
100%
[======================================================================================
=====================================>] 9,224 --.-K/s in 0s
2018-11-05 23:29:46 (156 MB/s) - ‘mysql57-community-release-el7-9.noarch.rpm’ saved
[9224/9224]
[root@ppl ~]#

安装 mysql 源

[root@ppl ~]# yum localinstall mysql57-community-release-el7-9.noarch.rpm
Loaded plugins: fastestmirror
Examining mysql57-community-release-el7-9.noarch.rpm: mysql57-community-release-el7-
9.noarch
Marking mysql57-community-release-el7-9.noarch.rpm to be installed
Resolving Dependencies
--> Running transaction check
---> Package mysql57-community-release.noarch 0:el7-9 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
=======================================================================================
==============================================================================
Package Arch Version
Repository Size
=======================================================================================
==============================================================================
Installing:
mysql57-community-release noarch el7-9
/mysql57-community-release-el7-9.noarch 8.6 k
Transaction Summary
=======================================================================================
==============================================================================
Install 1 Package
Total size: 8.6 k
Installed size: 8.6 k
Is this ok [y/d/N]: y
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : mysql57-community-release-el7-9.noarch
1/1
Verifying : mysql57-community-release-el7-9.noarch
1/1
Installed:
mysql57-community-release.noarch 0:el7-9
Complete!
[root@ppl ~]#

检查 mysql 源是否安装成功

[root@ppl ~]# yum repolist enabled | grep "mysql.*-community.*"
mysql-connectors-community/x86_64 MySQL Connectors Community 74
mysql-tools-community/x86_64 MySQL Tools Community 74
mysql57-community/x86_64 MySQL 5.7 Community Server 307
[root@ppl ~]#

或者安装完成后会将 MySQL 的 Yum 仓库添加到系统的仓库 list 中,可以/etc/yum.repos.d 目录下看到新增的两个文
件(mysql-community.repo 和 mysql-community-source.repo)。

[root@ppl ~]# cd /etc/yum.repos.d
[root@ppl yum.repos.d]# pwd
/etc/yum.repos.d
[root@ppl yum.repos.d]# ll -h
total 44K
-rw-r--r--. 1 root root 2.5K Jun 15 18:22 CentOS-Base.repo
-rw-r--r--. 1 root root 1.7K Apr 28 2018 CentOS-Base.repo.bak
-rw-r--r--. 1 root root 1.3K Apr 28 2018 CentOS-CR.repo
-rw-r--r--. 1 root root 649 Apr 28 2018 CentOS-Debuginfo.repo
-rw-r--r--. 1 root root 314 Apr 28 2018 CentOS-fasttrack.repo
-rw-r--r--. 1 root root 630 Apr 28 2018 CentOS-Media.repo
-rw-r--r--. 1 root root 1.3K Apr 28 2018 CentOS-Sources.repo
-rw-r--r--. 1 root root 4.7K Apr 28 2018 CentOS-Vault.repo
-rw-r--r--. 1 root root 1.4K Sep 12 2016 mysql-community.repo
-rw-r--r--. 1 root root 1.5K Sep 12 2016 mysql-community-source.repo
[root@ppl yum.repos.d]#

安装 MySQL

[root@ppl ~]# yum install mysql-community-server
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.aliyun.com
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
base
| 3.6 kB 00:00:00
extras
| 3.4 kB 00:00:00
mysql-connectors-community
| 2.5 kB 00:00:00
mysql-tools-community
| 2.5 kB 00:00:00
mysql57-community
| 2.5 kB 00:00:00
updates
| 3.4 kB 00:00:00
Resolving Dependencies
--> Running transaction check
---> Package mysql-community-server.x86_64 0:5.7.24-1.el7 will be installed
--> Processing Dependency: mysql-community-common(x86-64) = 5.7.24-1.el7 for package:
mysql-community-server-5.7.24-1.el7.x86_64
--> Processing Dependency: mysql-community-client(x86-64) >= 5.7.9 for package: mysqlcommunity-
server-5.7.24-1.el7.x86_64
--> Running transaction check
---> Package mysql-community-client.x86_64 0:5.7.24-1.el7 will be installed
--> Processing Dependency: mysql-community-libs(x86-64) >= 5.7.9 for package: mysqlcommunity-
client-5.7.24-1.el7.x86_64
---> Package mysql-community-common.x86_64 0:5.7.24-1.el7 will be installed
--> Running transaction check
---> Package mysql-community-libs.x86_64 0:5.7.24-1.el7 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
=======================================================================================
==============================================================================
Package Arch Version
Repository Size
=======================================================================================
==============================================================================
Installing:
mysql-community-server x86_64 5.7.24-
1.el7 mysql57-community 165 M
Installing for dependencies:
mysql-community-client x86_64 5.7.24-
1.el7 mysql57-community 24 M
mysql-community-common x86_64 5.7.24-
1.el7 mysql57-community 274 k
mysql-community-libs x86_64 5.7.24-
1.el7 mysql57-community 2.2 M
Transaction Summary
=======================================================================================
==============================================================================
Install 1 Package (+3 Dependent packages)
Total download size: 192 M
Installed size: 863 M
Is this ok [y/d/N]: y
.....
....
Total
525 kB/s | 192 MB 00:06:13
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : mysql-community-common-5.7.24-1.el7.x86_64
1/4
Installing : mysql-community-libs-5.7.24-1.el7.x86_64
2/4
Installing : mysql-community-client-5.7.24-1.el7.x86_64
3/4
Installing : mysql-community-server-5.7.24-1.el7.x86_64
4/4
Verifying : mysql-community-server-5.7.24-1.el7.x86_64
1/4
Verifying : mysql-community-libs-5.7.24-1.el7.x86_64
2/4
Verifying : mysql-community-common-5.7.24-1.el7.x86_64
3/4
Verifying : mysql-community-client-5.7.24-1.el7.x86_64
4/4
Installed:
mysql-community-server.x86_64 0:5.7.24-1.el7
Dependency Installed:
mysql-community-client.x86_64 0:5.7.24-1.el7 mysql-community-common.x86_64
0:5.7.24-1.el7 mysql-community-libs.x86_64 0:5.7.24-1.el7
Complete!
[root@ppl ~]#

如果出现以下错误

Error downloading packages:
mysql-community-common-5.7.24-1.el7.x86_64: [Errno 256] No more mirrors to try.
yum clean all
yum makecache
yum update 或者 yum -y update

登录

修改 root 本地登录密码
安装完成后,会生成一个临时的随机密码给 root 账户,保存在/var/log/mysqld.log,可以使用命令查看。

[root@ppl ~]# grep 'temporary password' /var/log/mysqld.log
2018-11-05T04:41:11.945054Z 1 [Note] A temporary password is generated for
root@localhost: rgX(v.oM>3nl
[root@ppl ~]#

启动 MySQL 服务

systemctl start mysqld

查看 MySQL 的启动状态

systemctl status mysqld

结果如下

[root@ppl ~]# systemctl start mysqld
[root@ppl ~]# systemctl status mysqld
● mysqld.service - MySQL Server
Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset:
disabled)
Active: active (running) since Mon 2018-11-05 23:56:28 EST; 5s ago
Docs: man:mysqld(8)
http://dev.mysql.com/doc/refman/en/using-systemd.html
Process: 49576 ExecStart=/usr/sbin/mysqld --daemonize --pidfile=/
var/run/mysqld/mysqld.pid $MYSQLD_OPTS (code=exited, status=0/SUCCESS)
Process: 49502 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited,
status=0/SUCCESS)
Main PID: 49580 (mysqld)
CGroup: /system.slice/mysqld.service
└─49580 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid
Nov 05 23:56:23 ppl systemd[1]: Starting MySQL Server...
Nov 05 23:56:28 ppl systemd[1]: Started MySQL Server.
[root@ppl ~]#

登录后要立即修改密码

[root@ppl ~]# mysql -u root -p 或者 mysql -uroot -p
输入初始密码后
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY '1qazxsw2A@#';
Query OK, 0 rows affected (0.00 sec)
mysql>

允许 root 远程登录

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

暂时先这些吧,有问题可以进群讨论,获取相关最新开发教程,欢迎你的加入!


技术改变人生 Q 群:702101215
爱学习:www.aixx123.com


  • B3log

    B3log 是一个开源组织,名字来源于“Bulletin Board Blog”缩写,目标是将独立博客与论坛结合,形成一种新的网络社区体验,详细请看 B3log 构思。目前 B3log 已经开源了多款产品:SymSoloVditor思源笔记

    1063 引用 • 3454 回帖 • 189 关注
  • MySQL

    MySQL 是一个关系型数据库管理系统,由瑞典 MySQL AB 公司开发,目前属于 Oracle 公司。MySQL 是最流行的关系型数据库管理系统之一。

    692 引用 • 535 回帖
  • Linux

    Linux 是一套免费使用和自由传播的类 Unix 操作系统,是一个基于 POSIX 和 Unix 的多用户、多任务、支持多线程和多 CPU 的操作系统。它能运行主要的 Unix 工具软件、应用程序和网络协议,并支持 32 位和 64 位硬件。Linux 继承了 Unix 以网络为核心的设计思想,是一个性能稳定的多用户网络操作系统。

    946 引用 • 943 回帖

相关帖子

欢迎来到这里!

我们正在构建一个小众社区,大家在这里相互信任,以平等 • 自由 • 奔放的价值观进行分享交流。最终,希望大家能够找到与自己志同道合的伙伴,共同成长。

注册 关于
请输入回帖内容 ...