阿里云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