CentOS 7手动部署mysql数据库(阿里云官方文档)

前提条件

1、已注册阿里云账号。如还未注册,请先完成账号注册。
2、如果在中国内地地域中使用云服务器ECS,请确保账号已完成实名认证。如还未认证,请先完成实名认证。
3、已创建一台ECS实例。详细步骤请参见使用向导创建实例。

背景信息

实例规格:ecs.c6.large(2 vCPU,4 GiB内存)
操作系统:公共镜像CentOS 7.2 64位
MySQL:5.7.33
本示例中,MySQL相关安装路径说明如下:
配置文件:/etc/my.cnf
数据存储:/var/lib/mysql
命令文件:/usr/bin和/usr/sbin
数据库端口:3306

步骤一:准备环境

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

步骤二:安装MySQL

运行以下命令更新YUM源。

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

运行以下命令安装MySQL。

yum -y install mysql-community-server

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

mysql -V

在这里插入图片描述

步骤三:配置MySQL

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

systemctl start mysqld

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

systemctl enable mysqld

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

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

执行​命令结果示例如下。

2020-04-08T08:12:07.893939Z 1 [Note] A temporary password is generated for root@localhost: xvlo1lZs7>uI

在这里插入图片描述
(一定要记好这个密码 一会要用)

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

mysql_secure_installation

1、重置root用户的密码。

说明 在输入密码时,系统为了最大限度的保证数据安全,命令行将不做任何回显。您只需要输入正确的密码信息,然后按Enter键即可。

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

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
Success.

3、禁止root账号远程登录。

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

4、删除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.

5、重新加载授权表。

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

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

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

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

 mysql -uroot -p

依次运行以下命令创建远程登录MySQL的账号。 建议您使用非root账号远程登录MySQL数据库,本示例账号为dms、密码为123456。
注意
实际创建账号时,需将示例密码123456更换为符合要求的密码,并妥善保存。密码要求:长度为8至30个字符,必须同时包含大小写英文字母、数字和特殊符号。可以使用以下特殊符号:
()` ~!@#$%^&*-+=|{}[]:;‘<>,.?/

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

然后去navcation远程连接把!!! 以后本地就可以用了 ip写服务器公网ip,用户dms,密码是上面的123456 。(依照自己为主)

附阿里云文档:

https://help.aliyun.com/document_detail/133666.html

猜你喜欢

转载自blog.csdn.net/weixin_45678130/article/details/120736889