【Ubuntu18.04】安装Mysql8.0踩坑

本文档详细介绍了在Ubuntu系统中安装MySQL时遇到的权限问题,包括如何更新源、升级软件、下载并安装MySQL,以及在遇到'Access denied for user 'root'@'localhost''错误时的解决步骤。通过设置sql_safe_updates、修改用户表、刷新权限、更改密码策略和配置文件,最终成功登录并修改MySQL的root密码。
摘要由CSDN通过智能技术生成

安装

下载

# 更新源
sudo apt-get update
# 更新软件
sudo apt-get upgrade
wget https://dev.mysql.com/get/mysql-apt-config_0.8.14-1_all.deb
sudo dpkg -i mysql-apt-config_0.8.14-1_all.deb
sudo apt-get update
sudo apt-get install mysql-community-server

遇到的问题

ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)

-- 查询一下安全模式开关
show variables like 'sql_safe_updates';
-- 关闭安全模式
set sql_safe_updates = 0;
-- 关闭安全模式下,才可以执行authentication_string为空
update user set authentication_string='' where user='root';
-- authentication_string空了的情况下,才可以真正修改密码
-- 刷新权限表
flush privileges;
-- 修改密码
alter user 'root'@'%' identified by 'S32*sdf312@';
alter user 'root'@'localhost' identified by 'S32*sdf312@';
-- 修改密码强度
show variables like 'validate%';
set global validate_password.length = 4;
set global validate_password.policy = LOW;

 在mysql配置文件中添加mysqld.cnf

skip-grant-tables

添加重启后,会发现3306端口没了。 

# 查看
show global variables like 'port';
SHOW VARIABLES LIKE 'skip_networking';

 也有可能时运行了mysqld的安全模式

ps -ef |grep mysql

# 重启MySQL服务
sudo service mysql restart
 
# 登录MySQL
mysql -u root -p
 
# 选择管理user表的数据库
use mysql;
 
# 将authentication_string 置空
update user set authentication_string='' where user='root';
 
# 将plugin改为以前版本的密码认证方式
update user set plugin='mysql_native_password' where user='root';
 
# 刷新
FLUSH PRIVILEGES;

# 修改密码
alter user 'root'@'localhost' identified by 'password';
 
# 重启MySQL
service mysql restart

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值