I get Error Code: 1143. SELECT command denied to user whenever I try to run an UPDATE query with a condition statement.
I have SELECT permissions on all tables in the database, and UPDATE permissions on certain fields in certain tables.
GRANT SELECT ON `Base`.* TO `php_role`;
GRANT UPDATE (`amount`) ON `Base`.`cart` TO `php_role`;
I am able to run the following SELECT query without any errors:
SELECT * FROM `cart` WHERE `subscription_id` = 0;
but when I try running an UPDATE query, I get the error:
UPDATE `cart` SET `amount` = 0 WHERE `subscription_id` = 0;
Even if I grant myself UPDATE permissions on the entire table, I still get the error.
The only I found to fix it, was by granting UPDATE permissions on the entire database.
Minimal Reproducible Example:
As Root, create the database, table, and user
CREATE DATABASE test_db;
USE test_db;
CREATE TABLE test(
p_id INT,
val INT,
PRIMARY KEY(p_id)
);
CREATE ROLE test_role;
CREATE USER test_user IDENTIFIED BY 'password';
GRANT SELECT ON test_db.* TO test_role;
GRANT INSERT ON test_db.* TO test_role;
GRANT UPDATE (val) ON test_db.test TO test_role;
GRANT test_role TO test_user;
SET DEFAULT ROLE test_role TO test_user;
As the newly created user, login and try running an UPDATE query
USE test_db;
UPDATE test SET val = 0 WHERE p_id = 0;
The UPDATE query results in the error, while the following query works fine:
SELECT * FROM test;
I need that my MySQL database makes a sum of some values in a specific coloumn. To do that I used trigger statement but MySQL gave me an error:
MySQL Error: #1142 - TRIGGER comand denied to user 'XXXXXX' for table wp_wpdatatable_8
the Trigger is below:
CREATE TRIGGER SumPliche AFTER INSERT ON wp_wpdatatable_8 FOR EACH ROW UPDATE wp_wpdatatable_8 SET sommapliche = tricipite + addome + soprailiaca + sottoscapolare + ascellare + pettorale + coscia
How can I do that?
thanks
It seems the issue here is with the permissions your user has on the database from which wp_wpdatatable_8.
To grant trigger permissions for a specific user and database, you may use the following command:
mysql> GRANT TRIGGER ON <DATABASE>.* TO <USER>#'<DATABASE HOST>';
Where
<DATABASE> refers to the database that contains the wp_wpdatatable_8 table.
<USER> the username that is trying to issue the CREATE TRIGGER command.
<DATABASE HOST> database host from where your user accesses the database. If you are running it locally, you can use localhost.
After flushing the privileges, creating the trigger should work normally.
For more information, check out the GRANT syntax on the MySQL.documentation
You lack the TRIGGER privilege on the database you are using.
I got this error when I did a test. Create a test user:
mysql> create user 'bill'#'localhost';
mysql> grant all privileges on test2.* to 'bill'#'localhost';
mysql> revoke trigger on test2.* from 'bill'#'localhost';
mysql> show grants for 'bill'#'localhost';
+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Grants for bill#localhost |
+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| GRANT USAGE ON *.* TO 'bill'#'localhost' IDENTIFIED BY PASSWORD '*29A1BB43D3B9EB42028B4566E4836353285B9395' |
| GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, REFERENCES, INDEX, ALTER, CREATE TEMPORARY TABLES, LOCK TABLES, EXECUTE, CREATE VIEW, SHOW VIEW, CREATE ROUTINE, ALTER ROUTINE, EVENT ON `test2`.* TO 'bill'#'localhost' |
+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
Now try creating a trigger as this user:
~ mysql -ubill -p
mysql> use test2
mysql> create table t ( i int);
mysql> create trigger tt before insert on t for each row set new.i = 42;
ERROR 1142 (42000): TRIGGER command denied to user 'bill'#'localhost' for table 't'
I also think your trigger might not do what you think it does, so it's just as well that you didn't create it.
CREATE TRIGGER SumPliche AFTER INSERT ON wp_wpdatatable_8
FOR EACH ROW
UPDATE wp_wpdatatable_8
SET sommapliche = tricipite + addome + soprailiaca + sottoscapolare + ascellare + pettorale + coscia
If I create this trigger in my test database (as a different user with TRIGGER privilege), and then try to insert a row:
mysql> insert into wp_wpdatatable_8 values (1, 1, 1, 1, 1, 1, 1, 1);
ERROR 1442 (HY000): Can't update table 'wp_wpdatatable_8' in
stored function/trigger because it is already used by statement which invoked
this stored function/trigger.
You probably want to set values only in the row you insert. If so, you would reference the current row being inserted with the NEW.* syntax:
CREATE TRIGGER SumPliche BEFORE INSERT ON wp_wpdatatable_8
FOR EACH ROW
SET NEW.sommapliche = NEW.tricipite + NEW.addome + NEW.soprailiaca
+ NEW.sottoscapolare + NEW.ascellare + NEW.pettorale + NEW.coscia;
Also you must use BEFORE INSERT if you want to change a value in the row before you insert it. If you use AFTER INSERT, it's too late.
Now it works:
mysql> insert into wp_wpdatatable_8 values (1, 1, 1, 1, 1, 1, 1, 1);
Query OK, 1 row affected (0.02 sec)
mysql> select * from wp_wpdatatable_8;
+-------------+-----------+--------+-------------+----------------+-----------+-----------+--------+
| sommapliche | tricipite | addome | soprailiaca | sottoscapolare | ascellare | pettorale | coscia |
+-------------+-----------+--------+-------------+----------------+-----------+-----------+--------+
| 7 | 1 | 1 | 1 | 1 | 1 | 1 | 1 |
+-------------+-----------+--------+-------------+----------------+-----------+-----------+--------+
if I use
GRANT TRIGGER ON wordpress-5478r34b.* TO '_sso_67c5vh1'#'10.3.157.568'
1064 - Syntax Error in SQL query near to '-5478r34b.* TO '_sso_67c5vh1'#'10.3.157.568'' linea 1
or
GRANT TRIGGER ON 'wordpress-3236c57b'.* TO '_sso_35fd3dc2'#'10.3.156.140'
1064 - Syntax Error in SQL query near to ''wordpress-5478r34b'.* TO '_sso_67c5vh1'#'10.3.157.568'' linea 1
or
GRANT TRIGGER ON 'wordpress'-'3236c57b'.* TO '_sso_35fd3dc2'#'10.3.156.140'
1064 - Syntax Error in SQL query near to ''wordpress'-'5478r34b'.* TO '_sso_67c5vh1'#'10.3.157.568'' linea 1
whatever I do, it gives me a syntax error.
In general, what I want to do is an automatic sum when I add new datas on my database. Is there something more simple way?
I want to remove a table, but when I execute DROP TABLE catalog_product_flat_1 I get:
ERROR 1051 (42S02): Unknown table 'catalog_product_flat_1'
When I run DROP VIEW catalog_product_flat_1 I get:
#1347 - 'magento.catalog_product_flat_1' is not VIEW
What am I missing?
I have a database function fn_relation_isModerator, only user api has access to this function. Now I want another user to have this permission (while keeping the previous permission as well).
I checked routine name and user by following query:
select routine_name, routine_type, definer from information_schema.ROUTINES where ROUTINE_SCHEMA = 'db_name';
Which resulted:
+-------------------------+---------------+----------+
| ROUTINE_NAME | ROUTINE_TYPE | DEFINER |
+-------------------------+---------------+----------+
| | | |
| fn_relation_isModerator | FUNCTION | api#% |
+-------------------------+---------------+----------+
Approach 1:
So I ran the following query to grant this permission:
GRANT EXECUTE ON PROCEDURE db_name.fn_relation_isModerator TO 'api_worker'#'%';
But it resulted in following error:
Error Code: 1305. PROCEDURE fn_relation_isModerator does not exist
Approach 2:
Query:
GRANT EXECUTE ON FUNCTION `db_name`.`fn_relation_isModerator` TO 'api_worker'#'%';
Error
Error Code: 1133. Can't find any matching row in the user table
Approach 3:
Query:
GRANT EXECUTE ON `db_name`.`fn_relation_isModerator` TO 'api_worker'#'%';
Error:
Error Code: 1144. Illegal GRANT/REVOKE command; please consult the
manual to see which privileges can be used
You have to use grant execute on the function (Approach 2):
GRANT EXECUTE ON FUNCTION `db_name`.`fn_relation_isModerator` TO 'api_workers'#'%';
As explained in the comments by OP, there was a typo in user, it should be api_workers instead of api_worker.
All approaches failed due to the use of non-existent user.
I am trying to copy from 1 table to another table on different database.
The SQL query dont seem to work:
INSERT INTO db1.table
SELECT T.number, T.dob, T.house_number FROM `db2.table2` as T;
I am getting an error saying:
ERROR 1146 (42S02): Table 'db2.table2' doesn't exist
If you insist on quoting the table name (not needed), it should be
FROM `db2`.`table2`
Could you try something like this:
select * into dbo.test2 from dbo.test1
CREATE TABLE recipes_new LIKE production.recipes;
INSERT recipes_new SELECT * FROM production.recipes;
Check out this link:
http://www.tech-recipes.com/rx/1487/copy-an-existing-mysql-table-to-a-new-table/