ubantu安装mysql

场景

记录ubantu20.04安装mysql5.7



一、安装

# 更新系统软件包
sudo spt update
# 安装mysql
sudo apt mysql-server-5.7 mysql-client-5.7

看到下面这句话,重启一下服务器

ureadahead will be reprofiled on next reboot

重启后直接查看状态

sudo systemctl status mysql

看到active就是启动成功

Active: active (running) 

二、设置

安全相关

sudo mysql_secure_installation

出现提示,需要配置一下

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

Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: 1
# 如果上一步选择了校验密码强度,这里需要选择校验强度的等级
Please set the password for root here.

New password:
# 输入新密码,密码需要符合上面所选的等级要求
Re-enter new password:
# 确认密码
Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : y
# 是否要通过刚设置的密码连接mysql
Remove anonymous users? (Press y|Y for Yes, any other key for No) : y
# 是否移除匿名用户
Disallow root login remotely? (Press y|Y for Yes, any other key for No) : n
# 不允许root用户远程登录?
Remove test database and access to it? (Press y|Y for Yes, any other key for No) : y
# 是否移除test库
Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y
# 刷新权限表

三、连接

1.本地命令连接

sudo mysql -u root -p

在这里插入图片描述

2.远程连接

  • 启用mysql远程连接,修改mysql配置文件
vim /etc/mysql/mysql.conf.d/mysqld.cnf

注释bind-address = 127.0.0.1
修改完成之后重启数据库服务

sudo systemctl restart mysql
  • 创建远程登录账号
    使用root本地登录mysql
-- 创建zhangsan账号
create user 'zhangsan'@'%' identified by 'zhangsan@1234';
-- 授予数据库权限(所有)
grant all privileges on *.* to 'zhangsan'@'%' with grant option;
-- 刷新权限
flush privileges;

远程使用zhangsan/zhangsan@1234就可以登录了

四、总结

数据库往往都是一个项目或者是一个任务的开始,希望大家后面遇到问题都能不懈应对,保持热爱
最后说一句:数据库密码还是应该设置复杂一点,不然存在数据被盗风险(有幸历过数据被盗),root只允许本地登录,账号权限也应该细化。

  • 9
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值