mysql error 1227 42000_mysql导入报错

mysql error 1227 42000_mysql导入报错今天在学习mysql的时候,一顿蜜汁操作,再次使用mysql的时候发现,不管用啥子命令,都出现了一个报错mysql>selectuser,passwordfrommysql.user;ERROR1142(42000):SELECTcommanddeniedtouser‘root’@‘localhost’fortable‘user’看了一下报错信息,权限不够…

大家好,又见面了,我是你们的朋友全栈君。如果您正在找激活码,请点击查看最新教程,关注关注公众号 “全栈程序员社区” 获取激活教程,可能之前旧版本教程已经失效.最新Idea2022.1教程亲测有效,一键激活。

Jetbrains全系列IDE稳定放心使用

今天在学习mysql的时候,一顿蜜汁操作,再次使用mysql的时候发现,不管用啥子命令,都出现了一个报错
mysql> select user,password from mysql.user;
ERROR 1142 (42000): SELECT command denied to user ‘root’@‘localhost’ for table ‘user’
看了一下报错信息,权限不够。。。那就是没有权限了,so,给他权限就好了

step01

退出数据库并且关闭mysql服务
 mysql> quit
 Bye
 [root@jinch ~]# /etc/init.d/mysqld stop
 Shutting down MySQL.. SUCCESS! 

step02

安全模式启动mysql,root用户登录
 [root@jinch ~]# mysqld_safe --skip-grant-tables &
 [root@jinch ~]# mysql -uroot -p123 mysql

step03

切换数据库&查看表信息中的root用户的localhost权限
 mysql> use mysql;
 Database changed
 mysql> show tables;
 +---------------------------+
 | Tables_in_mysql           |
 +---------------------------+
 | columns_priv              |
 | db                        |
 | event                     |
 | func                      |
 | general_log               |
 | help_category             |
 | help_keyword              |
 | help_relation             |
 | help_topic                |
 | innodb_index_stats        |
 | innodb_table_stats        |
 | ndb_binlog_index          |
 | plugin                    |
 | proc                      |
 | procs_priv                |
 | proxies_priv              |
 | servers                   |
 | slave_master_info         |
 | slave_relay_log_info      |
 | slave_worker_info         |
 | slow_log                  |
 | tables_priv               |
 | time_zone                 |
 | time_zone_leap_second     |
 | time_zone_name            |
 | time_zone_transition      |
 | time_zone_transition_type |
 | user                      |
 +---------------------------+
 28 rows in set (0.00 sec)
 
 mysql> select * from user where user='root' and host='localhost'\G;
 *************************** 1. row ***************************
                   Host: localhost
                   User: root
               Password: *23AE809DDACAF96AF0FD78ED04B6A265E05AA257
            Select_priv: N
            Insert_priv: N
            Update_priv: N
            Delete_priv: N
            Create_priv: N
              Drop_priv: N
            Reload_priv: N
          Shutdown_priv: N
           Process_priv: N
              File_priv: N
             Grant_priv: N
        References_priv: N
             Index_priv: N
             Alter_priv: N
           Show_db_priv: N
             Super_priv: N
  Create_tmp_table_priv: N
       Lock_tables_priv: N
           Execute_priv: N
        Repl_slave_priv: N
       Repl_client_priv: N
       Create_view_priv: N
         Show_view_priv: N
    Create_routine_priv: N
     Alter_routine_priv: N
       Create_user_priv: N
             Event_priv: N
           Trigger_priv: N
 Create_tablespace_priv: N
               ssl_type: 
             ssl_cipher: 
            x509_issuer: 
           x509_subject: 
          max_questions: 0
            max_updates: 0
        max_connections: 0
   max_user_connections: 0
                 plugin: mysql_native_password
  authentication_string: NULL
       password_expired: N
 1 row in set (0.00 sec)
 
 ERROR: 
 No query specified
这里发现全部都是N ,表示root用户本地登陆没有权限

step04

修改root用户的localhost权限(两种写法)
写法1:
mysql> update mysql.user set Grant_priv='Y',Super_priv='Y' where user='root';

mysql> flush privileges;

 mysql>grant all on *.* to 'root'@'localhost';
写法2:
 mysql> update user set `Insert_priv` ='Y' where user='root' and host='localhost';
 
 mysql> update user set `Update_priv` ='Y' where user='root' and host='localhost';
 
 mysql> update user set `Delete_priv` ='Y' where user='root' and host='localhost';
 
 mysql> update user set `Create_priv` ='Y' where user='root' and host='localhost';
 
 mysql> update user set `Drop_priv` ='Y' where user='root' and host='localhost';
 
 mysql> update user set `Reload_priv` ='Y' where user='root' and host='localhost';
 
 mysql> update user set `Shutdown_priv` ='Y' where user='root' and host='localhost';
 
 mysql> update user set `Process_priv` ='Y' where user='root' and host='localhost';
 
 mysql> update user set `File_priv` ='Y' where user='root' and host='localhost';
 
 mysql> update user set `Grant_priv` ='Y' where user='root' and host='localhost';
 
 mysql> update user set `References_priv` ='Y' where user='root' and host='localhost';
 
 mysql> update user set `Index_priv` ='Y' where user='root' and host='localhost';
 
 mysql> update user set `Alter_priv` ='Y' where user='root' and host='localhost';
 
 mysql> update user set `Show_db_priv` ='Y' where user='root' and host='localhost';
 
 mysql> update user set `Super_priv` ='Y',`Create_tmp_table_priv` = 'Y' where user='root'' and host='localhost';
 
 
 mysql> update user set `Lock_tables_priv` ='Y' where user='root' and host='localhost';  
 
 mysql> update user set `Execute_priv` ='Y' where user='root' and host='localhost';
 
 mysql> update user set `Repl_slave_priv` ='Y' where user='root' and host='localhost';
 
 
 mysql> update user set `Repl_client_priv` ='Y' where user='root' and host='localhost';
 
 mysql> update user set `Create_view_priv` ='Y' where user='root' and host='localhost';
 
 mysql> update user set `Show_view_priv` ='Y' where user='root' and host='localhost';
 
 mysql> update user set `Create_routine_priv` ='Y' where user='root' and host='localhost'';
 
 mysql> update user set `Alter_routine_priv` ='Y' where user='root' and host='localhost';;
 
 mysql> update user set `Create_user_priv` ='Y' where user='root' and host='localhost'; 
 
 mysql> update user set `Event_priv` ='Y' where user='root' and host='localhost';
 
 mysql> update user set `Trigger_priv` ='Y' where user='root' and host='localhost';
 
 mysql> flush privileges;
 Query OK, 0 rows affected (0.00 sec)
我这里有点傻。。。自己一个一个敲了一遍,可以直接用‘,’ 分割一次写完的,,,

step05

退出&重启&登陆
 mysql> quit
 Bye
 [root@jinch ~]# /etc/init.d/mysqld restart
 Shutting down MySQL.. SUCCESS! 
 Starting MySQL.. SUCCESS! 
 [root@jinch ~]# mysql -uroot -p123

step06

切换库
 mysql> use mysql;
 Reading table information for completion of table and column names
 You can turn off this feature to get a quicker startup with -A
 
 Database changed

step07

查看表信息
 mysql> select * from user\G;
 *************************** 1. row ***************************
                   Host: localhost
                   User: root
               Password: *23AE809DDACAF96AF0FD78ED04B6A265E05AA257
            Select_priv: Y
            Insert_priv: Y
            Update_priv: Y
            Delete_priv: Y
            Create_priv: Y
              Drop_priv: Y
            Reload_priv: Y
          Shutdown_priv: Y
           Process_priv: Y
              File_priv: Y
             Grant_priv: Y
        References_priv: Y
             Index_priv: Y
             Alter_priv: Y
           Show_db_priv: Y
             Super_priv: Y
  Create_tmp_table_priv: Y
       Lock_tables_priv: Y
           Execute_priv: Y
        Repl_slave_priv: Y
       Repl_client_priv: Y
       Create_view_priv: Y
         Show_view_priv: Y
    Create_routine_priv: Y
     Alter_routine_priv: Y
       Create_user_priv: Y
             Event_priv: Y
           Trigger_priv: Y
 Create_tablespace_priv: N
               ssl_type: 
             ssl_cipher: 
            x509_issuer: 
           x509_subject: 
          max_questions: 0
            max_updates: 0
        max_connections: 0
   max_user_connections: 0
                 plugin: mysql_native_password
  authentication_string: NULL
       password_expired: N
 1 row in set (0.01 sec)
 
 ERROR: 
 No query specified
 
 权限已经基本都有了
测试一下
 mysql> create database jinc;
 Query OK, 1 row affected (0.00 sec)
 
 mysql> select user,host from mysql.user;
 +------+-----------+
 | user | host      |
 +------+-----------+
 | root | localhost |
 +------+-----------+
 1 row in set (0.00 sec)
 
 mysql> drop database jinc;
 Query OK, 0 rows affected (0.00 sec)

好了,基本的权限又回来了

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/187024.html原文链接:https://javaforall.net

(0)
上一篇 2022年10月1日 下午6:46
下一篇 2022年10月1日 下午6:46


相关推荐

  • mysql批量增加数据_数据库最大连接数设置为多少合适

    mysql批量增加数据_数据库最大连接数设置为多少合适文章目录一、前言二、批量插入前准备1、插入到数据表的字段2、计算一行字段占用的空间3、在数据里做插入操作的时候,整体时间的分配三、批量插入数据测试1、SQL语句的大小限制2、查看服务器上的参数:3、计算一次能插入的最大行记录4、测试插入数据比对(1)插入11W条数据,按照每次10,600,1000,20000,80000来测试:(2)加大数据量到24w(3)加大测试量到42W5、如果插入的值就是sql语句限制的最大值,那么性能真的好吗?四、其他影响插入性能的因…

    2026年4月16日
    10
  • html常用空白符

    html常用空白符普通的英文半角空格 nbsp nbsp nbsp no breakspace 普通的英文半角空格但不换行 中文全角空格 一个中文宽度 en 空格 半个中文宽度 em 空格 一个中文宽度

    2026年3月18日
    2
  • OpenClaw安装sharp模块编译失败解决办法

    OpenClaw安装sharp模块编译失败解决办法

    2026年3月14日
    4
  • idea在类中搜索方法的快捷键_idea控制台搜索快捷键

    idea在类中搜索方法的快捷键_idea控制台搜索快捷键展开全部IntelliJIDEA代码常用的快捷键有:Alt+回车导入包,自动修正Ctrl+N查找类Ctrl+Shift+N查找文件Ctrl+Alt+L格式e69da5e887aa62616964757a686964616f31333365646234化代码Ctrl+Alt+O优化导入的类和包Alt+Insert生成代码(如get,set方法,构造函数等)Ctrl+E或者Alt+…

    2022年10月10日
    3
  • 使用 Anaconda 安装 Pytorch

    使用 Anaconda 安装 Pytorch本文的主要内容是使用Anaconda安装Pytorch,PyTorch是一个开源的Python机器学习库,基于Torch,用于自然语言处理等应用程序,其运行环境已兼容Windows(CUDA,CPU)、MacOS(CPU)、Linux(CUDA,ROCm,CPU)。

    2022年10月6日
    3
  • mac phpstrom 激活码【2022最新】「建议收藏」

    (mac phpstrom 激活码)这是一篇idea技术相关文章,由全栈君为大家提供,主要知识点是关于2021JetBrains全家桶永久激活码的内容IntelliJ2021最新激活注册码,破解教程可免费永久激活,亲测有效,下面是详细链接哦~https://javaforall.net/100143.html4KDDGND3CI-eyJsa…

    2022年4月1日
    109

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号