Having your own custom website is one of the most rewarding experiences you can have online, but from time to time, it can also throw seemingly random errors at you for no apparent reason. One of the more perplexing errors is MySQL error #1142 “INSERT command denied to user”. Unlike other errors, this particular issue can pop up in almost all content management systems, in phpMyAdmin, and even in code that you have written yourself. In this article, we will learn what causes the #1142 error and we will go over the possible solutions to this issue.
As the error message ”INSERT command denied to user” suggests, the root problem is that the INSERT command fails. The INSERT command is used to add new information to your MySQL database. So, you can potentially run into this problem whenever you update your website with new information or when you try to manually insert new data into your database.
Since this is a database-related issue, it can pop up on any website that uses a database to store information. The issue can affect everything from world-renowned content management systems like WordPress, Joomla, and Drupal, to small PHP websites that you may have coded yourself.
The #1142 error is most prevalent in shared hosting environments. Plans such as our free website hosting and our premium shared hosting packages fall into this category. The reason is that shared hosting plans often impose a limit, known as a quota, on the amount of information that can be stored in a single database.
What Is a Database Quota?
As more information is stored in a database, its size steadily grows. That is why hosting companies often impose a database quota which is essentially a storage limit for your database. When you reach this limit, you are no longer permitted to add new information in the database. In technical terms, when you reach your database storage limit, your database user loses its INSERT privileges.
How Can I Check My Database Quota and Current Space Usage?
You can easily check the current size of your MySQL database as well as the database quota imposed by your hosting plan using the Database Manager section of the Control Panel, as is shown below:
The only thing that we need to point out is that your current utilization statistics are not updated in real-time. As such, it may take an hour or so for any changes to the size of your database to be reflected in our Database Manager.
How Do I Fix MySQL Error #1142 “INSERT Command Denied to User”?
There are three approaches you can take to resolve the ”INSERT command denied to user” problem:
- you can optimize your database in order to reduce its size without sacrificing any of your data.
- you can delete information that you no longer need.
- you can upgrade to a better hosting plan that grants you additional database storage.
Below we will discuss the three options in greater detail.
Option 1: Optimize the Database
Optimizing the database is arguably the best approach to take as it allows you to instantly reduce your database’s size without sacrificing any data. The only downside to this option is that for large websites this can prove to be only a temporary solution.
To optimize your database, follow the steps below:
- Go to the Database Manager section of our Control Panel.
- Click on the name of the database that is over quota.
- Open the Management tab.
- Choose the 1-click Optimization option, as is shown in the screenshot below:
- At this point, your database is optimized. However, it may take some time for this optimization to be reflected. To speed up the process, scroll further down the list of management options and choose the 1-click Permissions Fix button. By doing so, you will be granted full access to your database immediately and you can continue working on your website.
For more information on how database optimization works and the different ways of optimizing your database that you have available, you can refer to our full guide on how to optimize a MySQL database.
Option 2: Delete Unnecessary Data
Your other alternative when it comes to reducing your database size is to straight-up delete any data that is no longer necessary. This can be achieved using phpMyAdmin to DROP (delete) any tables that you no longer need. An example of this can be seen below:
Some website software products offer the ability for you to log every site visit for further analysis at a later time. Such information is often stored in your database. While this may be a useful feature to some, it can very quickly take up the majority of your database, especially if you have regular site visitors who spend plenty of time on your site. Disabling this logging functionality and removing the existing logs from the database can free up hundreds of megabytes.
Another aspect of running a website that can consume a lot of database storage is user-generated content such as reader comments on a blog post. At the very least you should ensure that no SPAM comments are published as are not helpful in the slightest and take up valuable storage space. An even better approach would be to consider using a service like DISQUS as it not only helps protect you against SPAM comments, it even stores all comments on its own servers so they are not taking up any space at all in your database.
Option 3: Upgrade to a Better Hosting Plan
The last option that you have at your disposal is to upgrade to a better hosting plan. The next tier of hosting will always offer you more storage for your databases and our premier plans like the Max Pack Plus and all of our Semi-Dedicated web servers will provide you with unlimited storage, thus dealing with the #1142 error once and for all.
If you are using one of our Virtual Private Server packages and you run into the “INSERT command denied to user” error, it is possible that your VPS has run out of space and there is simply no room for additional information to be stored. Once you confirm that the lack of storage is indeed the issue, you can purchase additional disk space for your VPS through our Control Panel.
Conclusion
When you are using a shared hosting server, you can solve the MySQL error #1142 “INSERT command denied to user” by making sure that your current database utilization does not exceed your database quota. This can be done by optimizing the database, deleting data, or just increasing your database quota. Sadly, some content management systems use different wording for the exact same error, so if your hosting plan limits the maximum size of your MySQL database, it is always a good idea to regularly check that you are not reaching your storage limit.
Keep reading
- How Do I Fix the “Can’t Connect to Local MySQL Server Through Socket” Error?
Я переустановил сервер под управлением MySQL. Я создал резервную копию базы данных с помощью MySQL Workbench. Теперь я пытаюсь импортировать дамп в базу данных через ту же программу, но получаю следующую ошибку:
ERROR 1142 (42000) at line 656: SELECT,LOCK TABL command denied to user 'root'@'MIKKOS' for table 'events_waits_summary_by_thread_by_event_name'
Я думал, что у root были полные привилегии. Я выполнил следующее, но та же ошибка появляется с предыдущим запросом после выполнения этого:
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' WITH GRANT OPTION
Он также появляется при локальном запуске (root@localhost).
Что делать?
2 ответы
Проверьте, какие базы данных MySQL Workbench включены в файл дампа. Я считаю, что по умолчанию он сбрасывает все, включая такие БД, как user
и performance_schema
. Это проблема, ваши таблицы грантов, вероятно, в порядке.
Удалите ненужные базы данных, особенно performance_schema
и MySQL, скорее всего, импортирует файл дампа без ошибок.
ответ дан 24 авг.
Вам необходимо восстановить внутреннюю структуру таблицы после переустановки более нового сервера MySQL. Для этого попробуйте:
REPAIR TABLE `events_waits_summary_by_thread_by_event_name`;
Было бы лучше удалить базу данных и восстановить ее из полного дампа базы данных mysql, если он у вас есть.
Создан 20 янв.
Не тот ответ, который вы ищете? Просмотрите другие вопросы с метками
mysql
mysqldump
mysql-workbench
mysql-error-1142
or задайте свой вопрос.
Сегодня при изучении mysql, операции с медовым соком, при повторном использовании mysql я обнаружил, что независимо от того, какая подкоманда, возникает ошибка
mysql> select user,password from mysql.user;
ERROR 1142 (42000): SELECT command denied to user ‘root’@‘localhost’ for table ‘user’
После прочтения сообщения об ошибке разрешения недостаточно. , , Нет разрешения, так что просто дайте ему разрешение
step01
Выйдите из базы данных и закройте службу mysql.
mysql> quit
Bye
[[email protected] ~]# /etc/init.d/mysqld stop
Shutting down MySQL.. SUCCESS!
step02
Запустите mysql в безопасном режиме, войдите в систему как пользователь root
[[email protected] ~]# mysqld_safe --skip-grant-tables &
[[email protected] ~]# mysql -uroot -p123 mysql
step03
Переключение базы данных и просмотр локальных прав пользователя root в табличной информации
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
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
[[email protected] ~]# /etc/init.d/mysqld restart
Shutting down MySQL.. SUCCESS!
Starting MySQL.. SUCCESS!
[[email protected] ~]# 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 userG;
*************************** 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)