ubuntu18.04安装与配置MySQL

安装MySQL

命令一

sudo apt-get update
root@VM-12-10-ubuntu:/home# sudo apt-get update
Hit:1 http://mirrors.tencentyun.com/ubuntu bionic InRelease
Hit:2 http://mirrors.tencentyun.com/ubuntu bionic-security InRelease
Hit:3 http://mirrors.tencentyun.com/ubuntu bionic-updates InRelease
Reading package lists... Done  

 命令二

sudo apt-get install mysql-server

初始化配置MySQL

命令一(开始初始化配置密码等等)

sudo 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: 

我这里的选择是选择N,我个人用123456就好了,复杂的反而会忘记

第二项就是设置密码了

Press y|Y for Yes, any other key for No: N
Please set the password for root here.

New password: 

Re-enter new password: 

第三项的意思是

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) : 
   默认情况下,MySQL安装有一个匿名用户,允许任何人登录MySQL而无需为他们创建用户帐户。这仅用于测试,并使安装更加顺利。您应该在进入生产环境之前删除它们。删除匿名用户?(按ylY表示“是”,其他键表示“否”):

我选择是N

第四项

Normally, root should only be allowed to connect from
'localhost'. This ensures that someone cannot guess at
the root password from the network.

Disallow root login remotely? (Press y|Y for Yes, any other key for No) : 
通常情况下,根用户只能从“localhost”连接。这可以确保有人无法从网络中猜到根密码。禁止远程root登录?(按ylY表示“是”,其他键表示“否”):|

 我的选择是N

第五项

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.


Remove test database and access to it? (Press y|Y for Yes, any other key for No) : 

默认情况下,MySQL带有一个名为“test”的数据库,任何人都可以访问。这也仅用于测试,在进入生产环境之前应该删除。删除测试数据库并访问它?(按yly表示“是”,其他键表示“否”):

我的选项N

第六项

Reloading the privilege tables will ensure that all changes
made so far will take effect immediately.

Reload privilege tables now? (Press y|Y for Yes, any other key for No) : 

重新加载特权表将确保到目前为止所做的所有更改将立即生效。现在重新加载特权表?(按ylY表示“是”,其他键表示“否”):

我的选项Y

接下来可以检查mysql数据库的服务状态了

systemctl status mysql.service
root@VM-12-10-ubuntu:/home# systemctl status mysql.service
● mysql.service - MySQL Community Server
   Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled)
   Active: active (running) since Sat 2022-12-17 19:39:58 CST; 12min ago
 Main PID: 4600 (mysqld)
    Tasks: 29 (limit: 2312)
   CGroup: /system.slice/mysql.service
           └─4600 /usr/sbin/mysqld --daemonize --pid-file=/run/mysqld/mysqld.pid

Dec 17 19:39:58 VM-12-10-ubuntu systemd[1]: Starting MySQL Community Server...
Dec 17 19:39:58 VM-12-10-ubuntu systemd[1]: Started MySQL Community Server.

出现active(running)即为正常运行

登录MySQL

mysql -uroot -p

 如果输入密码正确了还是进不去

就在前面加sudo,给权限就好了

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值