mysql使用報錯1142(42000)的問題及解決
mysql使用報錯1142(42000)
在學(xué)習(xí)mysql的時候,一頓蜜汁操作,再次使用mysql的時候發(fā)現(xiàn),不管用啥子命令,都出現(xiàn)了一個報錯
mysql> select user,password from mysql.user;
ERROR 1142 (42000): SELECT command denied to user ‘root’@‘localhost’ for table ‘user’
看了一下報錯信息,權(quán)限不夠。。。
那就是沒有權(quán)限了,so,給他權(quán)限就好了
step01
退出數(shù)據(jù)庫并且關(guān)閉mysql服務(wù)
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
切換數(shù)據(jù)庫&查看表信息中的root用戶的localhost權(quán)限
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
這里發(fā)現(xiàn)全部都是N ,表示root用戶本地登陸沒有權(quán)限
step04
修改root用戶的localhost權(quán)限(兩種寫法)
寫法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)
我這里有點(diǎn)傻。。。自己一個一個敲了一遍,可以直接用‘,’ 分割一次寫完的,,,
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 權(quán)限已經(jīng)基本都有了
測試一下
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)
好了,基本的權(quán)限又回來了
總結(jié)
以上為個人經(jīng)驗,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關(guān)文章
MySQL系列之redo log、undo log和binlog詳解
這篇文章主要介紹了MySQL系列之redo log、undo log和binlog詳解,本文給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下2020-12-12mysql啟動提示mysql.host 不存在,啟動失敗的解決方法
我將s9當(dāng)眾原來的mysql4.0刪除后,重新裝了個mysql5.0,啟動過程中報一下錯誤,啟動失敗,查了一下群里面的老帖子也沒有個具體的明確說明2011-10-10MySQL無服務(wù)及服務(wù)無法啟動的終極解決方案分享
又是MySQL的問題,之前已經(jīng)遇見過一次本地MySQL服務(wù)無法啟動的情況,現(xiàn)在又出現(xiàn)了,下面這篇文章主要給大家介紹了關(guān)于MySQL無服務(wù)及服務(wù)無法啟動的終極解決方案,需要的朋友可以參考下2022-06-06Mysql基礎(chǔ)學(xué)習(xí)之LAG與LEAD開窗函數(shù)
lead和lag是在SQL中用于創(chuàng)建窗口函數(shù)的兩個常用函數(shù),這篇文章主要給大家介紹了關(guān)于Mysql基礎(chǔ)學(xué)習(xí)之LAG與LEAD開窗函數(shù)的相關(guān)資料,文中通過代碼介紹的非常詳細(xì),需要的朋友可以參考下2023-11-11深度解析MySQL啟動時報“The server quit without up
這篇文章主要介紹了MySQL啟動時報“The server quit without updating PID file”錯誤的原因,需要的朋友可以參考下2017-05-05