centos7 安装mysql

本文涉及的产品
RDS MySQL Serverless 基础系列,0.5-2RCU 50GB
RDS MySQL Serverless 高可用系列,价值2615元额度,1个月
云数据库 RDS MySQL,高可用系列 2核4GB
简介: 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;


相关实践学习
每个IT人都想学的“Web应用上云经典架构”实战
本实验从Web应用上云这个最基本的、最普遍的需求出发,帮助IT从业者们通过“阿里云Web应用上云解决方案”,了解一个企业级Web应用上云的常见架构,了解如何构建一个高可用、可扩展的企业级应用架构。
MySQL数据库入门学习
本课程通过最流行的开源数据库MySQL带你了解数据库的世界。   相关的阿里云产品:云数据库RDS MySQL 版 阿里云关系型数据库RDS(Relational Database Service)是一种稳定可靠、可弹性伸缩的在线数据库服务,提供容灾、备份、恢复、迁移等方面的全套解决方案,彻底解决数据库运维的烦恼。 了解产品详情: https://www.aliyun.com/product/rds/mysql 
相关文章
|
22天前
|
Ubuntu 关系型数据库 MySQL
MySQL源码编译安装
本文详细介绍了MySQL 8.0及8.4版本的源码编译安装全过程,涵盖用户创建、依赖安装、cmake配置、编译优化等步骤,并提供支持多Linux发行版的一键安装脚本,适用于定制化数据库部署需求。
111 4
MySQL源码编译安装
|
22天前
|
Ubuntu 关系型数据库 MySQL
MySQL二进制包安装
本文详细介绍了在多种Linux系统上通过二进制包安装MySQL 8.0和8.4版本的完整过程,涵盖用户创建、glibc版本匹配、程序解压、环境变量配置、初始化数据库及服务启动等步骤,并提供支持多发行版的一键安装脚本,助力高效部署MySQL环境。
141 4
MySQL二进制包安装
|
22天前
|
安全 关系型数据库 MySQL
MySQL包安装 -- SUSE系列(离线RPM包安装MySQL)
本文详细介绍在openSUSE系统上通过离线RPM包安装MySQL 8.0和8.4版本的完整步骤,包括下载地址、RPM包解压、GPG密钥导入、使用rpm或zypper命令安装及服务启动验证,涵盖初始密码获取与安全修改方法,适用于无网络环境下的MySQL部署。
240 3
MySQL包安装 -- SUSE系列(离线RPM包安装MySQL)
|
22天前
|
关系型数据库 MySQL Linux
MySQL包安装 -- SUSE系列(SUSE资源库安装MySQL)
本文介绍了在openSUSE系统上通过SUSE资源库安装MySQL 8.0和8.4版本的完整步骤,包括配置国内镜像源、安装MySQL服务、启动并验证运行状态,以及修改初始密码等操作,适用于希望在SUSE系列系统中快速部署MySQL的用户。
122 3
MySQL包安装 -- SUSE系列(SUSE资源库安装MySQL)
|
19天前
|
NoSQL 算法 Redis
【Docker】(3)学习Docker中 镜像与容器数据卷、映射关系!手把手带你安装 MySql主从同步 和 Redis三主三从集群!并且进行主从切换与扩容操作,还有分析 哈希分区 等知识点!
Union文件系统(UnionFS)是一种**分层、轻量级并且高性能的文件系统**,它支持对文件系统的修改作为一次提交来一层层的叠加,同时可以将不同目录挂载到同一个虚拟文件系统下(unite several directories into a single virtual filesystem) Union 文件系统是 Docker 镜像的基础。 镜像可以通过分层来进行继承,基于基础镜像(没有父镜像),可以制作各种具体的应用镜像。
174 5
|
1月前
|
缓存 关系型数据库 BI
使用MYSQL Report分析数据库性能(下)
使用MYSQL Report分析数据库性能
84 3
|
1月前
|
关系型数据库 MySQL 数据库
自建数据库如何迁移至RDS MySQL实例
数据库迁移是一项复杂且耗时的工程,需考虑数据安全、完整性及业务中断影响。使用阿里云数据传输服务DTS,可快速、平滑完成迁移任务,将应用停机时间降至分钟级。您还可通过全量备份自建数据库并恢复至RDS MySQL实例,实现间接迁移上云。
|
2月前
|
存储 运维 关系型数据库
从MySQL到云数据库,数据库迁移真的有必要吗?
本文探讨了企业在业务增长背景下,是否应从 MySQL 迁移至云数据库的决策问题。分析了 MySQL 的优势与瓶颈,对比了云数据库在存储计算分离、自动化运维、多负载支持等方面的优势,并提出判断迁移必要性的五个关键问题及实施路径,帮助企业理性决策并落地迁移方案。
|
1月前
|
关系型数据库 MySQL 分布式数据库
阿里云PolarDB云原生数据库收费价格:MySQL和PostgreSQL详细介绍
阿里云PolarDB兼容MySQL、PostgreSQL及Oracle语法,支持集中式与分布式架构。标准版2核4G年费1116元起,企业版最高性能达4核16G,支持HTAP与多级高可用,广泛应用于金融、政务、互联网等领域,TCO成本降低50%。
|
1月前
|
关系型数据库 MySQL 数据库
阿里云数据库RDS费用价格:MySQL、SQL Server、PostgreSQL和MariaDB引擎收费标准
阿里云RDS数据库支持MySQL、SQL Server、PostgreSQL、MariaDB,多种引擎优惠上线!MySQL倚天版88元/年,SQL Server 2核4G仅299元/年,PostgreSQL 227元/年起。高可用、可弹性伸缩,安全稳定。详情见官网活动页。