AWS安装Mysql

原创
2019/10/18 17:36
阅读数 1.2K

第一步: 切换到root账户

sudo -s

更换时区为东八区(北京时间)

mv /etc/localtime /etc/localtime.bak 
cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime

第二步: 需要更新一下yum(因为亚马逊的yum版本经常都是晚于潮流)

yum update

第三步: 安装mysql

yum install -y mysql57-server

如果提示 Unable to find a match: mysql57-server则需要去mysql官网获取下安装包

//下载
sudo rpm -ivh https://repo.mysql.com//mysql57-community-release-el7-11.noarch.rpm
//安装
sudo yum install mysql-server

第四步: 启动mysql

service mysqld start
#设置开机自启动
chkconfig mysqld on

第五步: 做一些基础配置

mysql_secure_installation

下面的内容会比较多,其实就几个

[root@ip-172-31-35-183 ec2-user]# mysql_secure_installation

Securing the MySQL server deployment.

Connecting to MySQL using a blank password.

VALIDATE PASSWORD PLUGIN can be used to test passwords
and improve security. It checks the strength of password
and allows the users to set only those passwords which are
secure enough. Would you like to setup VALIDATE PASSWORD plugin?

#询问你是否启用密码校验
Press y|Y for Yes, any other key for No: y

There are three levels of password validation policy:

LOW    Length >= 8
MEDIUM Length >= 8, numeric, mixed case, and special characters
STRONG Length >= 8, numeric, mixed case, special characters and dictionary                  file

#询问你要使用什么强度的密码,输入0就可以使用任意密码,还有 1和2可选自己看上两行的强度要求
Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: 0
Please set the password for root here.
#输入你的密码
New password: 
#再次数据你的密码
Re-enter new password: 
#这行是评价你设定密码的强度,可以忽略
Estimated strength of the password: 50 
#上一行评价了你的密码强度,如果你觉得不够,你可以输入n重新设置密码,如果对自己的密码满意就输入y,确认使用新密码
Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : 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.
#询问你是否删除所有匿名用户,直接选y即可,不需要多想(要多想也随意)
Remove anonymous users? (Press y|Y for Yes, any other key for No) : y
Success.


Normally, root should only be allowed to connect from
'localhost'. This ensures that someone cannot guess at
the root password from the network.
#问你是否要禁用root账户的远程连接,如果禁用了你就只能玩单机操作了,所以选择 n
Disallow root login remotely? (Press y|Y for Yes, any other key for No) : n

 ... skipping.
By default, MySQL comes with a database named 'test' that
anyone can access. This is also intended only for testing,
and should be removed before moving into a production
environment.

#问你要不要删除所有测试数据,数据库新装会有一些默认的测试数据,删不删没影响,y和n随意
Remove test database and access to it? (Press y|Y for Yes, any other key for No) : y
 - Dropping test database...
Success.

 - Removing privileges on test database...
Success.

Reloading the privilege tables will ensure that all changes
made so far will take effect immediately.
#问你要不要更新配置(屁话,设置这么辛苦肯定马上更新使用了) y
Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y
Success.

All done! 

第六步: 使用刚设置的密码登入数据库,修改远程ip权限

mysql -u root -p

设置用户 root 可以在任意 IP 下被访问:

grant all privileges on *.* to root@"%" identified by "你的密码";

设置用户 root 可以在本地被访问:

grant all privileges on *.* to root@"localhost" identified by "你的密码";

设置完访问权限后,需要刷新一下

flush privileges

至此结束

展开阅读全文
打赏
0
0 收藏
分享
加载中
更多评论
打赏
0 评论
0 收藏
0
分享
返回顶部
顶部