【Linux服务器Java环境搭建】08 通过用户root创建MySQL数据库报错1044 (42000): Access denied for user ‘root‘@‘%‘ to database

【Linux服务器Java环境搭建】01购买云服务器以及在服务器中安装Linux系统
【Linux服务器Java环境搭建】02 通过xftp和xshell远程连接云服务器
【Linux服务器Java环境搭建】03 Git工具安装
【Linux服务器Java环境搭建】04 JDK安装(JAVA环境安装)
【Linux服务器Java环境搭建】05 Node JS安装及环境变量配置
【Linux服务器Java环境搭建】06 maven项⽬构建和管理⼯具安装
【Linux服务器Java环境搭建】07 在linux中安装MySql,以及对MySQL的配置与远程连接
【Linux服务器Java环境搭建】08 通过用户root创建MySQL数据库报错1044 (42000): Access denied for user ‘root‘@‘%‘ to database
待续…
【Linux服务器Java环境搭建】附录01:判断Linux服务器是X64还是arm架构的方式
【Linux服务器Java环境搭建】附录02:压缩格式tar.gz和tar.xz的区别

centos 中通过用户root创建MySQL数据库报错,RROR 1044 (42000): Access denied for user ‘root’@‘%’ to database ‘lzhmysql’

在这里插入图片描述

1、检查现有权限

  • 执行如下语句,查看root用户现有权限
mysql> show grants for 'root'@'%';

在这里插入图片描述

GRANT SELECT, UPDATE, RELOAD, SHUTDOWN, PROCESS, FILE, REFERENCES, INDEX, ALTER, SHOW DATABASES, SUPER, CREATE TEMPORARY TABLES, LOCK TABLES, EXECUTE, REPLICATION SLAVE, REPLICATION CLIENT, CREATE VIEW, SHOW VIEW, CREATE ROUTINE, ALTER ROUTINE, CREATE USER, EVENT, TRIGGER, CREATE TABLESPACE, CREATE ROLE, DROP ROLE ON *.* TO `root`@`%` WITH GRANT OPTION
  • 执行如下语句,查看root用户的权限为Y
mysql> SELECT host,user,Grant_priv,Super_priv FROM mysql.user;

【Linux服务器Java环境搭建】08 通过用户root创建MySQL数据库报错1044 (42000): Access denied for user ‘root‘@‘%‘ to database_第1张图片

  • 但是通过SELECT * FROM mysql.user;命令查询权限信息,可以看到root对应的很多权限都是N
    【Linux服务器Java环境搭建】08 通过用户root创建MySQL数据库报错1044 (42000): Access denied for user ‘root‘@‘%‘ to database_第2张图片
    出现此问题的原因可能是安装mysql的时候MySQL权限配置不正确。

2、解决方案

  • 执行如下语句,将root用户的如下权限都设置为Y
use mysql; 
update user set Update_priv ='Y' where user = 'root';
update user set Select_priv ='Y' where user = 'root';
update user set Insert_priv ='Y' where user = 'root';
update user set Update_priv ='Y' where user = 'root';
update user set Delete_priv ='Y' where user = 'root';
update user set Create_priv ='Y' where user = 'root';
update user set Drop_priv ='Y' where user = 'root';
update user set Reload_priv ='Y' where user = 'root';
update user set Shutdown_priv ='Y' where user = 'root';
update user set Process_priv ='Y' where user = 'root';
update user set File_priv ='Y' where user = 'root';
update user set Grant_priv ='Y' where user = 'root';
update user set References_priv ='Y' where user = 'root';
update user set Index_priv ='Y' where user = 'root';
update user set Alter_priv ='Y' where user = 'root';
update user set Show_db_priv ='Y' where user = 'root';
update user set Super_priv ='Y' where user = 'root';
update user set Create_tmp_table_priv ='Y' where user = 'root';
update user set Lock_tables_priv ='Y' where user = 'root';
update user set Execute_priv ='Y' where user = 'root';
update user set Repl_slave_priv ='Y' where user = 'root';
update user set Repl_client_priv ='Y' where user = 'root';
update user set Create_view_priv ='Y' where user = 'root';
update user set Show_view_priv ='Y' where user = 'root';
update user set Create_routine_priv ='Y' where user = 'root';
update user set Alter_routine_priv ='Y' where user = 'root';
update user set Create_user_priv ='Y' where user = 'root';
update user set Event_priv ='Y' where user = 'root';
update user set Trigger_priv ='Y' where user = 'root';

执行效果如下
【Linux服务器Java环境搭建】08 通过用户root创建MySQL数据库报错1044 (42000): Access denied for user ‘root‘@‘%‘ to database_第3张图片

  • 执行完成后,输入exit退出MySQL
exit
  • 重启MySQL服务
[root@yisu-655382d078761 ~]# systemctl restart mysqld

在这里插入图片描述

3、再次创建数据库(成功)

mysql> create database test01

【Linux服务器Java环境搭建】08 通过用户root创建MySQL数据库报错1044 (42000): Access denied for user ‘root‘@‘%‘ to database_第4张图片

你可能感兴趣的:(服务器,数据库,linux,mysql,root,centos)