ubuntu mysql access denied,Ubuntu安装/配置MySQL及root用户access denied报错解决

安装MySQL

sudo apt-get upgrade

sudo apt-get install mysql-server

sudo apt-get install mysql-client

88a78a499a1c

运行截图

配置

a. 初始化配置

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: # (是/否)

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) : # (是/否)

... skipping.

Normally, root should only be allowed to connect from 'localhost'.

This ensures that someone cannot guess at the root password from the network.

# 通常root用户只能从本地访问数据库以增加安全

# 询问是否可以远程登陆root用户

Disallow root login remotely? (Press y|Y for Yes, any other key for No) : # (是/否)

Success.

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.

# MySQL默认创建test数据库

# 询问是否删除

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

... skipping.

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) : # (是/否)

Success.

All done!

b. 检查MySql服务状态

systemctl status mysql.service

88a78a499a1c

MySQL服务正在运行

c. (尝试连接数据库时报错)

mysql -u root -p

错误信息: ERROR 1698 (28000): Access denied for user 'root'@'localhost'

Workbench也无法连接

我的解决方案:

i. 检查3306端口占用

88a78a499a1c

端口情况

端口✔

ii. 管理员登陆MySQL

sudo mysql -u root

mysql> GRANT ALL PRIVILEGES ON *.* to 'root'@'localhost';

mysql> flush privileges;

mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '';

mysql> exit

TIP: MySQL版本5.7之后在mysql.user中用authentication_string代替了password

iii. 刷新MySQL服务

sudo service mysql restart

iv. 再次连接, 成功

88a78a499a1c

Terminal

88a78a499a1c

Workbench

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值