当前位置:   article > 正文

Ubuntu安装mysql8.0教程(20.04)及mysql服务的开启、关闭、重启

Ubuntu安装mysql8.0教程(20.04)及mysql服务的开启、关闭、重启

第一步、执行下列命令

sudo apt install mysql-server
  • 1

出现下图表示安装mysql8.0成功

在这里插入图片描述

测试mysql进程是否开启

ps -elf|grep mysql
  • 1

在这里插入图片描述

如果查不到mysql进程,则执行下列命令启动mysql进程

sudo service mysql start
  • 1

第二步、初始化mysql配置,配置完成后重启mysql服务

sudo mysql_secure_installation
  • 1
...
# 1.询问是否安装密码插件,我选择 No
VALIDATE PASSWORD COMPONENT 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 component?
Press y|Y for Yes, any other key for No: n

# 2.为root用户设置密码
Please set the password for root here.

New password: 

Re-enter new password: 
# 出现下面报错的 解决方法详见第三步,解决bug
 ... Failed! Error: SET PASSWORD has no significance for user 'root'@'localhost' as the authentication method used doesn't store authentication data in the MySQL server. Please consider using ALTER USER instead if you want to change authentication parameters.

#  解决bug后,重新设置密码,也可以不设置,刚刚sudo mysql设置的就是root的密码
New password: 

Re-enter new password: 

#3.删除匿名用户,我选No
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) : n

 ... skipping.

#4.禁止root管理员从远程登录,这里我选 No
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) : n

 ... skipping.
 
 #5.删除test数据库并取消对它的访问权限, 我选 No
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) : n

 ... skipping.
 
 #6.刷新授权表,让初始化后的设定立即生效, 选 Yes
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) : y
Success.

All done! 

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63

第三步、解决bug

首先输入下列命令

sudo mysql
  • 1

然后输入下列命令修改密码, 最后的;不能丢

ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'your_password';
  • 1

在这里插入图片描述

最后按exit退出,继续执行第二步的初始化配置

第四步、登陆mysql,成功登陆则说明配置成功

mysql -u root -p
  • 1

在这里插入图片描述

注:mysql服务的基本操作方法

开启服务  sudo service mysql start
停止服务  sudo service mysql stop
重启服务  sudo service mysql restart
  • 1
  • 2
  • 3
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/菜鸟追梦旅行/article/detail/187911
推荐阅读
相关标签
  

闽ICP备14008679号