centos7 安装mysql

本文涉及的产品
云数据库 RDS MySQL Serverless,0.5-2RCU 50GB
简介: centos7 安装mysql

方法一

1、官网下载需要的版本:https://downloads.mysql.com/archives/community/

如果觉得下载慢可以去阿里开源镜像下:https://mirrors.aliyun.com/mysql/MySQL-8.0/?spm=a2c6h.25603864.0.0.65db712bCE0lD5

例如:(方法多多,不一定要这个)我的centos7 下载mysql-8.0.28-1.el7.x86_64.rpm-bundle.tar

2、删除以前安装的残留(如果有mariadb的也要删除)

#查找mysql

rpm -qa | grep mysql

#查找mariadb

rpm -qa |grep mariadb

#没有则不用卸载,有则卸载

rpm -e--nodeps 名称

3、把下载好的mysql传至centos7

(为了方便管理,我把mysql上传至新创建的mysql目录下;如果不会传送至centos7可以去下载finalshell等连接工具,当然如果自己的本机电脑是Linux系统就不需要)

4、查看是否存在libaio

rpm -qa|grep libaio

#如果没有则进行安装

yum install -y libaio

5、解压

tar -xf  mysql-8.0.28-1.el7.x86_64.rpm-bundle.tar

6、安装(有顺序要求)

rpm -ivh mysql-community-common-8.0.28-1.el7.x86_64.rpm --nodeps--force

rpm -ivh mysql-community-libs-8.0.28-1.el7.x86_64.rpm --nodeps--force

rpm -ivh mysql-community-devel-8.0.28-1.el7.x86_64.rpm --nodeps--force

rpm -ivh mysql-community-libs-compat-8.0.28-1.el7.x86_64.rpm --nodeps--force

rpm -ivh mysql-community-client-8.0.28-1.el7.x86_64.rpm  --nodeps--force

rpm -ivh mysql-community-server-8.0.28-1.el7.x86_64.rpm --nodeps--force

6、启动MySQL服务

systemctl start mysqld

7 、设置MySQL服务开机自启动。

systemctl enable mysqld

8、命令查看/var/log/mysqld.log文件,获取并记录root用户的初始密码。

grep 'temporary password' /var/log/mysqld.log

9、对MySQL进行安全性配置。

mysql_secure_installation

(1)重置密码

Enter password for user root: #输入已获取的root用户初始密码

The existing password for the user account root has expired. Please set a new password.

New password: #输入新的MySQL密码(密码安全性要求比较高,密码需要有大写字母、小写字母、数字、字符组合,;比如:Qkkf56439!)

Re-enter new password: #重复输入新的MySQL密码

The 'validate_password' component is installed on the server.

The subsequent steps will run with the existing configuration

of the component.

Using existing password for root.

Change the password for root ? ((Press y|Y for Yes, any other key for No) :Y #输入Y选择更新MySQL密码。您也可以输入N不再更新MySQL密码。

New password: #输入新的MySQL密码

Re-enter new password: #重复输入新的MySQL密码

Estimated strength of the password: 100

Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) :Y #输入Y确认使用已设置的密码。

(2)删除匿名用户。

By default, a MySQL installation has an anonymous user,

allowing anyone to log into MySQL without having to have

a user account created for them. This is intended only for

testing, and to make the installation go a bit smoother.

You should remove them before moving into a production

environment.

Remove anonymous users? (Press y|Y for Yes, any other key for No) :Y #输入Y删除MySQL默认的匿名用户。

Success.

(3)禁止root账号远程登录(出于安全考虑)

Normally, root should only be allowed to connect from

'localhost'. This ensures that someone cannot guess at

the root password from the network.

Disallow root login remotely? (Press y|Y for Yes, any other key for No) :Y #输入Y禁止root远程登录。

Success.

(4)删除test库以及对test库的访问权限。

By default, MySQL comes with a database named 'test' that

anyone can access. This is also intended only for testing,

and should be removed before moving into a production

environment.

Remove test database and access to it? (Press y|Y for Yes, any other key for No) :Y #输入Y删除test库以及对test库的访问权限。

- Dropping test database...

Success.

- Removing privileges on test database...

Success.

(5)重新加载授权表。

Reloading the privilege tables will ensure that all changes

made so far will take effect immediately.

Reload privilege tables now? (Press y|Y for Yes, any other key for No) :Y #输入Y重新加载授权表。

Success.

All done!

10、远程访问MySQL数据库

(1)登录

mysql -uroot -p

(2)创建远程访问账户

mysql> create user 'dmsTest'@'%' identified by '123456'; #创建数据库用户dmsTest,并授予远程连接权限。

mysql> grant all privileges on *.* to 'dmsTest'@'%'; #为dmsTest用户授权数据库所有权限。

mysql> flush privileges; #刷新权限。

方法二(适合小白使用,直接把命令复制粘贴就行)

注:在此解释为什么不适合老手,因为以这种方式安装的MySQL默认最新版本,一般最新版本是不太稳定的,老手更适合安装自己想要的稳定版本

准备:删除以前安装的残留(如果有mariadb的也要删除)

#查找mysql

rpm -qa | grep mysql

#查找mariadb

rpm -qa |grep mariadb

#没有则不用卸载,有则卸载

rpm -e --nodeps 名称

1、更新YUM源

sudo rpm -Uvh https://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm

2、安装MySQL

sudo yum -y install mysql-community-server --enablerepo=mysql80-community --nogpgcheck

3、查看MySQL版本号(一般会直接安装最新版本)

mysql -V

4、启动MySQL服务

systemctl start mysqld

5、设置MySQL服务开机自启动。

systemctl enable mysqld

6、命令查看/var/log/mysqld.log文件,获取并记录root用户的初始密码。

grep 'temporary password' /var/log/mysqld.log

7、对MySQL进行安全性配置。

mysql_secure_installation

(1)重置密码

Enter password for user root: #输入已获取的root用户初始密码

The existing password for the user account root has expired. Please set a new password.

New password: #输入新的MySQL密码(密码安全性要求比较高,密码需要有大写字母、小写字母、数字、字符组合,;比如:Qkkf56439!)

Re-enter new password: #重复输入新的MySQL密码

The 'validate_password' component is installed on the server.

The subsequent steps will run with the existing configuration

of the component.

Using existing password for root.

Change the password for root ? ((Press y|Y for Yes, any other key for No) :Y #输入Y选择更新MySQL密码。您也可以输入N不再更新MySQL密码。

New password: #输入新的MySQL密码

Re-enter new password: #重复输入新的MySQL密码

Estimated strength of the password: 100

Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) :Y #输入Y确认使用已设置的密码。

(2)删除匿名用户。

By default, a MySQL installation has an anonymous user,

allowing anyone to log into MySQL without having to have

a user account created for them. This is intended only for

testing, and to make the installation go a bit smoother.

You should remove them before moving into a production

environment.

Remove anonymous users? (Press y|Y for Yes, any other key for No) :Y #输入Y删除MySQL默认的匿名用户。

Success.

(3)禁止root账号远程登录(出于安全考虑)

Normally, root should only be allowed to connect from

'localhost'. This ensures that someone cannot guess at

the root password from the network.

Disallow root login remotely? (Press y|Y for Yes, any other key for No) :Y #输入Y禁止root远程登录。

Success.

(4)删除test库以及对test库的访问权限。

By default, MySQL comes with a database named 'test' that

anyone can access. This is also intended only for testing,

and should be removed before moving into a production

environment.

Remove test database and access to it? (Press y|Y for Yes, any other key for No) :Y #输入Y删除test库以及对test库的访问权限。

- Dropping test database...

Success.

- Removing privileges on test database...

Success.

(5)重新加载授权表。

Reloading the privilege tables will ensure that all changes

made so far will take effect immediately.

Reload privilege tables now? (Press y|Y for Yes, any other key for No) :Y #输入Y重新加载授权表。

Success.

All done!

8、远程访问MySQL数据库

(1)登录

mysql -uroot -p

(2)创建远程访问账户

mysql> create user 'dmsTest'@'%' identified by '123456'; #创建数据库用户dmsTest,并授予远程连接权限。

mysql> grant all privileges on *.* to 'dmsTest'@'%'; #为dmsTest用户授权数据库所有权限。

mysql> flush privileges; #刷新权限。

小知识

如果嫌弃密码安全度要求高,可以自己改

1、查看 MySQL密码策略

SHOW VARIABLES LIKE 'validate_password%';

2、修改密码策略(更改为最低)

set global validate_password.policy=LOW;

3、修改密码的长度(当前为8),如果嫌长可以改为6

set global validate_password.length=6;


相关实践学习
基于CentOS快速搭建LAMP环境
本教程介绍如何搭建LAMP环境,其中LAMP分别代表Linux、Apache、MySQL和PHP。
全面了解阿里云能为你做什么
阿里云在全球各地部署高效节能的绿色数据中心,利用清洁计算为万物互联的新世界提供源源不断的能源动力,目前开服的区域包括中国(华北、华东、华南、香港)、新加坡、美国(美东、美西)、欧洲、中东、澳大利亚、日本。目前阿里云的产品涵盖弹性计算、数据库、存储与CDN、分析与搜索、云通信、网络、管理与监控、应用服务、互联网中间件、移动服务、视频服务等。通过本课程,来了解阿里云能够为你的业务带来哪些帮助     相关的阿里云产品:云服务器ECS 云服务器 ECS(Elastic Compute Service)是一种弹性可伸缩的计算服务,助您降低 IT 成本,提升运维效率,使您更专注于核心业务创新。产品详情: https://www.aliyun.com/product/ecs
相关文章
|
3天前
|
SQL 存储 关系型数据库
MySQL Cluster集群安装及使用
MySQL Cluster集群安装及使用
|
1天前
|
关系型数据库 MySQL 数据安全/隐私保护
安装mysql和远程连接
安装mysql和远程连接
8 0
|
1天前
|
关系型数据库 MySQL Java
Linux 安装 JDK、MySQL、Tomcat(图文并茂)
Linux 安装 JDK、MySQL、Tomcat(图文并茂)
13 2
|
3天前
|
Linux
centos 6.5安装yum
centos 6.5安装yum
22 0
|
3天前
|
运维 网络协议 Linux
【运维系列】Centos7安装并配置PXE服务
PXE是Intel开发的预启动执行环境,允许工作站通过网络从远程服务器启动操作系统。它依赖DHCP分配IP,DNS服务分配主机名,TFTP提供引导程序,HTTP/FTP/NFS提供安装源。要部署PXE服务器,需关闭selinux和防火墙,安装dhcpd、httpd、tftp、xinetd及相关服务,配置引导文件和Centos7安装源。最后,通过syslinux安装引导文件,并创建pxelinux.cfg/default配置文件来定义启动参数。
15 0
|
3天前
|
运维 网络协议 Linux
【运维系列】Centos7安装并配置postfix服务
安装CentOS7的Postfix和Dovecot,配置Postfix的`main.cf`文件,包括修改完全域名、允许所有IP、启用邮箱等。然后,配置Dovecot的多个配置文件以启用auth服务和调整相关设置。重启Postfix和Dovecot,设置开机自启,并关闭防火墙进行测试。最后,创建邮箱账户并在Windows邮箱客户端中添加账户设置。
10 0
|
3天前
|
关系型数据库 MySQL Windows
windows安装MySQL5.7教程
windows安装MySQL5.7教程
13 0
|
3天前
|
Linux 网络安全
Centos6.5安装并配置NFS服务
该内容描述了在Linux系统中设置NFS服务的步骤。首先挂载yum源,然后安装NFS服务,并编辑配置文件。接着,重启rpcbind和NFS服务,可能需要重复此过程以解决初始可能出现的问题。此外,关闭防火墙策略,并再次重启服务。最终,根目录被共享,特定IP网段被允许访问。
11 0
|
2月前
|
关系型数据库 MySQL Linux
centos7.0环境下安装MySql_8.0.12
centos7.0环境下安装MySql_8.0.12
|
2月前
|
缓存 关系型数据库 MySQL
百度搜索:蓝易云【CentOS8服务器安装MySQL报错:no match mysql-community-server】
现在,你已经成功安装了MySQL服务器并解决了"no match mysql-community-server"的报错问题。祝你使用愉快!
43 1