1. 首页
  2. 阿里云ECS云服务器使用教程

阿里云Linux服务器安装MySQL数据库教程

阿里云服务器Linux系统上如何安装MySQL数据库?阿小云以Alibaba Cloud Linux 2系统镜像为例,Alibaba Cloud Linux是完全兼容CentOS的,所以下方教程中Linux服务器上安装MySQL数据库命令和CentOS是通用的:

阿里云Linux服务器安装MySQL数据库

阿里云服务器Linux系统上手动安装MySQL数据库,服务器系统、云服务器ECS实例规格信息如下:

  • 实例规格:ecs.c6.large(2 vCPU,4 GiB内存)
  • 操作系统:公共镜像Alibaba Cloud Linux 2.1903 LTS 64位,兼容CentOS
  • MySQL:5.7.31
  • 数据库端口:3306

MySQL相关安装路径说明如下:
配置文件:/etc/my.cnf
数据存储:/var/lib/mysql
命令文件:/usr/bin/usr/sbin

阿里云服务器Linux安装MySQL数据库教程开始:

一:SSH连接云服务器

命令:ssh root@云服务器ip

二:安装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  Ver 14.14 Distrib 5.7.31, for Linux (x86_64) using  EditLine wrapper

至此阿里云服务器Linux安装MySQL数据库教程完毕,以下是MySQL数据库启动、阿全等配置。

三:配置MySQL

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

systemctl start mysqld

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

systemctl enable mysqld

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

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

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远程登录,输入Y
Success.

删除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 #是否重新加载授权表,输入Y
Success.
All done!

关于阿里云服务器Linux安装MySQL数据库详细教程可以参考官方文档:

官方文档:手动部署MySQL数据库 – 阿里云

原创文章,作者:阿小云,如若转载,请注明出处:https://www.axiaoyun.com/ecs/linux-mysql.html