MySQL是一个关系型数据库管理系统,常用于LAMP和LNMP等网站场景中。本教程介绍如何在Linux系统ECS实例上安装、配置以及远程访问MySQL数据库。
背景信息
步骤一:准备环境
连接您的ECS实例。具体操作,请参见使用SSH密钥对连接Linux实例或使用用户名密码验证连接Linux实例。
步骤二:安装MySQL
- 运行以下命令更新YUM源。
rpm -Uvh http://dev.mysql.com/get/mysql57-community-release-el7-9.noarch.rpm
- 运行以下命令安装MySQL。
yum -y install mysql-community-server
- 运行以下命令查看MySQL版本号。
mysql -V
返回结果如下,表示MySQL安装成功。
mysql Ver 14.14 Distrib 5.7.26, for Linux (x86_64) using EditLine wrapper
步骤三:配置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进行安全性配置。
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!
安全性配置的更多详情,请参见MySQL官方文档。 - 重置root用户的密码。
步骤四:远程访问MySQL数据库
您可以使用数据库客户端或阿里云提供的数据管理服务DMS(Data Management Service)来远程访问MySQL数据库。本节以DMS为例,介绍远程访问MySQL数据库的操作步骤。
- 在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;
说明
- 建议您使用非root账号远程登录MySQL数据库。
- 实际创建账号时,需将
123456
更换为符合要求的密码: 长度为8至30个字符,必须同时包含大小写英文字母、数字和特殊符号。可以使用以下特殊符号:()` ~!@#$%^&*-+=|{}[]:;‘<>,.?/
- 运行以下命令后,输入root用户的密码登录MySQL。
暂无评论...
热评文章
热门文章
热门标签
PPT模板(5)
电影(4)
设计素材(4)
在线翻译(4)
在线学习(3)
xxl-job(3)
综艺(3)
音乐(3)
MV(3)
视频(3)
网上购物(3)
家电(3)
动漫(3)
网页素材(3)
公开课(2)
网络公开课(2)
在线教育(2)
php(2)
体育(2)
电视剧(2)
新闻(2)
财经(2)
在线观看(2)
手机(2)
计算机(2)
服装(2)
国际(2)
海外(2)
居家(2)
论坛(2)
母婴(2)
美妆(2)
bbs(2)
个护(2)
食品(2)
京东(2)
集运(2)
全球(2)
淘宝(2)
游戏(2)
淘寶(2)
淘寶網(2)
掏寶(2)
游戏视频(2)
掏保(2)
網上購物(2)
集運(2)
淘宝全球(2)
taobao(2)
免费ppt模板(2)
ppt教程(2)
房产(2)
科技(2)
素材(2)
PS素材(2)
动画(2)
图片素材(2)
翻译(2)
在线工具(2)
开发人员工具(2)
站长工具(2)
JavaScript(2)
mysql(2)
kubernetes(2)
nginx(2)
运维(2)
SSL免费证书(2)
在线编辑(2)
python(2)
网页搜索(2)
视频搜索(2)
图片搜索(2)
音乐搜索(2)
新闻搜索(2)
软件搜索(2)
微信搜索(1)
crop(1)
机器翻译(1)
数字货币(1)
问答搜索(1)