CentOS 系统手动部署 MySQL 数据库

本文来自于【阿里云官方镜像站:https://developer.aliyun.com/mirror/?utm_content=g_1000307095 】

原文链接:https://developer.aliyun.com/article/757708?spm=a2c6h.12873581.0.0.484f7e46SbqQDx

镜像下载、域名解析、时间同步请点击 阿里巴巴开源镜像站

一、前提条件

已注册阿里云账号。

如果在中国内地地域中使用云服务器ECS,请确保账号已完成实名认证。

已创建一台ECS实例。详细步骤请参见使用向导创建实例。

二、背景信息

本教程在示例步骤中使用了以下实例规格和版本软件。实际操作时,请以您的软件版本为准。

实例规格:ecs.c6.large(2 vCPU,4 GiB内存)

操作系统:公共镜像CentOS 7.2 64位

MySQL:5.7.26

数据库端口:3306

说明 您需要在ECS实例所使用的安全组入方向添加规则并放行3306端口。具体步骤,请参见添加安全组规则。

三、操作步骤

步骤一:准备环境

远程连接您的ECS实例。具体操作,请参见使用SSH密钥对连接Linux实例或使用用户名密码验证连接Linux实例。

步骤二:安装MySQL

1、运行以下命令更新YUM源。(点击 试用)

rpm -Uvh http://dev.mysql.com/get/mysql57-community-release-el7-9.noarch.rpm

2、运行以下命令安装MySQL。

yum -y install mysql-community-server

3、运行以下命令查看MySQL版本号。

mysql -V

返回结果如下,表示MySQL安装成功。

mysql Ver 14.14 Distrib 5.7.26, for Linux (x86_64) using EditLine wrapper

步骤三:配置MySQL

1、运行以下命令启动MySQL服务。

systemctl start mysqld

2、运行以下命令设置MySQL服务开机自启动。

systemctl enable mysqld

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

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

2019-04-28T06:50:56.674085Z 1 [Note] A temporary password is generated for root@localhost: 3w)WqGlM7-o,

说明 下一步对MySQL进行安全性配置时,会使用该初始密码。

4、运行下列命令对MySQL进行安全性配置。

mysql_secure_installation

重置root用户的密码。

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

The 'validate_password' plugin is installed on the server.

The subsequent steps will run with the existing configuration of the plugin.

Using existing password for root.

Estimated strength of the password: 100

Change the password for root ? ((Press y|Y for Yes, any other key for No) : Y #是否更改root用户密码,输入Y

New password: #输入新密码,长度为8至30个字符,必须同时包含大小写英文字母、数字和特殊符号。特殊符号可以是()` ~!@#$%^&*-+=|{}[]:;‘<>,.?/

Re-enter new password: #再次输入新密码

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

删除匿名用户账号。

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

Success.

禁止root账号远程登录。

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

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

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

- Dropping test database...

Success.

重新加载授权表。

Reload privilege tables now? (Press y|Y for Yes, any other key for No) : Y #是否重新加载授权表,输入YSuccess.All done!

安全性配置的更多详情,请参见MySQL官方文档。

步骤四:远程访问MySQL数据库

您可以使用数据库客户端或阿里云提供的数据管理服务DMS(Data Management Service)来远程访问MySQL数据库。本节以DMS为例,介绍远程访问MySQL数据库的操作步骤。

1、在ECS实例上,创建远程登录MySQL的账号。

运行以下命令后,输入root用户的密码登录MySQL。

mysql -uroot -p

依次运行以下命令创建远程登录MySQL的账号。示例账号为dms、密码为123456。

mysql> grant all on *.* to 'dms'@'%'IDENTIFIED BY '123456'; #使用root替换dms,可设置为允许root账号远程登录。

mysql> flush privileges;

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值