阿里云Linux安装mysql

阿里云linux安装mysql

参考文档 https://help.aliyun.com/document_detail/178136.html

操作系统:公共镜像Aliyun Linux 2.1903 LTS 64位

1. 准备工作

在ecs实例所在使用的安全组入方向添加规则并放行3306接口
在这里插入图片描述

1. 开始安装

运行命令更新YUM源。

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

运行命令安装mysql

yum -y install mysql-community-server

在这里插入图片描述

出现错误 Warning: RPMDB altered outside of yum
解决办法:删除 yum 的历史记录
运行 rm -rf /var/lib/yum/history/*.sqlite
(没有请忽略)

运行查看mysql版本号

mysql -V

返回

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

安装完成

3.设置本地数据库

systemctl start mysqld	启动mysql
service mysqld stop		关闭mysql
service mysqld restart	重启mysql
systemctl enable mysqld	开机启动mysql

运行命令获取初始密码

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

返回

2020-08-17T08:37:57.436929Z 1 [Note] A temporary password is generated for root@localhost: mSL!-*O&U9DN

root@localhost:后面为初始密码

执行命令进行安全设置

mysql_secure_installation

在这里插入图片描述

如果出现
在这里插入图片描述
密码太简单不符合政策需求 提高密码复杂度即可

修改密码

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 -uroot -p密码

在这里插入图片描述

mysql: [Warning] Using a password on the command line interface can be insecure.
mysql:[警告]在命令行界面上使用密码可能不安全。
mysql建议不要明文输入密码

解决方法:vim /etc/my.cnf
在这里插入图片描述

将账号密码写入配置文件中然后直接执行 mysql即可
在这里插入图片描述

4.连接阿里云RDS数据库

RDS设置白名单获取内外网地址 即可登陆
连接命令

mysql -h阿里云RDS内(外)网地址 -u用户名 -p密码 -P3306
  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值