mysql使用报错1142(42000)解决方法
今天在学习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> quitBye[root@jinch ~]# /etc/init.d/mysqld stopShutting 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 changedmysql> 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: localhostUser: rootPassword: *23AE809DDACAF96AF0FD78ED04B6A265E05AA257Select_priv: NInsert_priv: NUpdate_priv: NDelete_priv: NCreate_priv: NDrop_priv: NReload_priv: NShutdown_priv: NProcess_priv: NFile_priv: NGrant_priv: NReferences_priv: NIndex_priv: NAlter_priv: NShow_db_priv: NSuper_priv: NCreate_tmp_table_priv: NLock_tables_priv: NExecute_priv: NRepl_slave_priv: NRepl_client_priv: NCreate_view_priv: NShow_view_priv: NCreate_routine_priv: NAlter_routine_priv: NCreate_user_priv: NEvent_priv: NTrigger_priv: NCreate_tablespace_priv: Nssl_type: ssl_cipher: x509_issuer: x509_subject: max_questions: 0max_updates: 0max_connections: 0max_user_connections: 0plugin: mysql_native_passwordauthentication_string: NULLpassword_expired: N1 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> quitBye[root@jinch ~]# /etc/init.d/mysqld restartShutting down MySQL.. SUCCESS! Starting MySQL.. SUCCESS! [root@jinch ~]# mysql -uroot -p123
step06
切换库
mysql> use mysql;Reading table information for completion of table and column namesYou can turn off this feature to get a quicker startup with -ADatabase changed
step07
查看表信息
mysql> select * from user\G;*************************** 1. row ***************************Host: localhostUser: rootPassword: *23AE809DDACAF96AF0FD78ED04B6A265E05AA257Select_priv: YInsert_priv: YUpdate_priv: YDelete_priv: YCreate_priv: YDrop_priv: YReload_priv: YShutdown_priv: YProcess_priv: YFile_priv: YGrant_priv: YReferences_priv: YIndex_priv: YAlter_priv: YShow_db_priv: YSuper_priv: YCreate_tmp_table_priv: YLock_tables_priv: YExecute_priv: YRepl_slave_priv: YRepl_client_priv: YCreate_view_priv: YShow_view_priv: YCreate_routine_priv: YAlter_routine_priv: YCreate_user_priv: YEvent_priv: YTrigger_priv: YCreate_tablespace_priv: Nssl_type: ssl_cipher: x509_issuer: x509_subject: max_questions: 0max_updates: 0max_connections: 0max_user_connections: 0plugin: mysql_native_passwordauthentication_string: NULLpassword_expired: N1 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)
好了,基本的权限又回来了
mysql使用报错1142(42000)解决方法相关推荐
- mysql 启动服务1067_windows无法启动MySQL服务报错1067的解决方法
突然登陆MySQL时,出现禁止访问或者无法连接到数据库,回到服务,去打开wampmysqld ,发现 "windows无法启动MySQL服务 错误1067" ,死活启动不了,咋办? ...
- 1067 mysql_windows无法启动MySQL服务报错1067的解决方法
突然登陆MySQL时,出现禁止访问或者无法连接到数据库,回到服务,去打开wampmysqld ,发现 "windows无法启动MySQL服务 错误1067" ,死活启动不了,咋办? ...
- MySQL使用报错:1054 - Unknown column ‘sno‘ in ‘field list‘(表中字段编码与SQL语句中编码不统一)
情况描述:在Navicat中新建了一个数据库,然后导入了几个CSV文件,建立了几个表: 其中sno_info结构如下所示: 当我简单查询Sno的时候: 报错了: 1054 - Unknown colu ...
- git使用报错:fatal: Couldn't find remote ref master的解决方法
git使用报错:fatal: Couldn't find remote ref master的解决方法 fatal: Couldn't find remote ref master 翻译过来就是:致命 ...
- “this”不能在常量表达式中使用报错的解决方法
"this"不能在常量表达式中使用报错的解决方法 问题描述与思考 在用C++书写下面一段代码时,编译器报错"'this'不能在常量表达式中使用".在这里,我最开 ...
- Python安装xlrd和xlwt的步骤以及使用报错的解决方法
Python安装xlrd和xlwt的步骤以及使用报错的解决方法 参考文章: (1)Python安装xlrd和xlwt的步骤以及使用报错的解决方法 (2)https://www.cnblogs.com/ ...
- git使用报错: fatal: Couldn‘t find remote ref master的解决方法
git使用报错: fatal: Couldn't find remote ref master的解决方法 参考文章: (1)git使用报错: fatal: Couldn't find remote r ...
- git使用报错:fatal: Couldn‘t find remote ref master的解决方法
git使用报错:fatal: Couldn't find remote ref master的解决方法 参考文章: (1)git使用报错:fatal: Couldn't find remote ref ...
- 登录mysql报错2059_navicat连接mysql报错2059的解决方法
navicat连接mysql报错2059的解决方法 发布时间:2020-12-21 10:27:37 来源:亿速云 阅读:82 作者:小新 栏目:数据库 这篇文章给大家分享的是有关navicat连接m ...
最新文章
- 精通JavaScript--07设计模式:行为型
- 【原创】 PostgreSQL 实现MySQL 的auto_increment 字段
- 使用国内源安装k8s
- perl怎么拷贝一个文件到另一个文件夹中或者怎么拷贝文件夹到另一个文件夹
- 微课|《Python编程基础与案例集锦(中学版)》第3章(1)
- 大道至简:微众银行区块链全栈技术体系纵览
- iOS 12 真的能让旧款 iPhone 速度飞起吗?
- C++学习 8.2 - 类及类成员
- 各种安装包下载地址汇总
- 微信小程序 java通过 rawData 和 session_key 生成 signature 签名
- 流水作业调度问题 Johnson 算法
- java jdbc 批处理_JDBC的批处理操作
- freemark导出word全过程 + 图片不显示问题
- npm init vite@latest 构建项目报错解决办法
- linux rstudio 卸载,R与Rstudio的安装与卸载
- 在教育孩子上少一点功利心,就会快乐?
- ❤️Hello Programmer❤️
- 教你快速制作一个简单的网页
- xshell6使用技巧_Xshell6的正确打开方式
- Python爬虫爬取Google图片