479

When I run the following query I get an error:

SELECT
  `a`.`sl_id`                     AS `sl_id`,
  `a`.`quote_id`                  AS `quote_id`,
  `a`.`sl_date`                   AS `sl_date`,
  `a`.`sl_type`                   AS `sl_type`,
  `a`.`sl_status`                 AS `sl_status`,
  `b`.`client_id`                 AS `client_id`,
  `b`.`business`                  AS `business`,
  `b`.`affaire_type`              AS `affaire_type`,
  `b`.`quotation_date`            AS `quotation_date`,
  `b`.`total_sale_price_with_tax` AS `total_sale_price_with_tax`,
  `b`.`STATUS`                    AS `status`,
  `b`.`customer_name`             AS `customer_name`
FROM `tbl_supplier_list` `a`
  LEFT JOIN `view_quotes` `b`
    ON (`b`.`quote_id` = `a`.`quote_id`)
LIMIT 0, 30

The error message is:

#1449 - The user specified as a definer ('web2vi'@'%') does not exist

Why am I getting that error? How do I fix it?

8
  • 8
    Show us your SHOW CREATE VIEW 'view_quotes'
    – jordeu
    Apr 16, 2012 at 7:21
  • The error must be in where condition of view_quotes view.
    – Shell
    Dec 10, 2014 at 5:29
  • 1
    After thinking about this a moment and the simplest course of action was to add the missing account to the database and the error went away. No complicated procedure needed. If you can add the account then try that first. Dec 29, 2018 at 16:28
  • 1
    I had this issue simply as a trigger when inserting May 23, 2022 at 17:54
  • 1
    Why definer needs to be defined to do any simple db changes, who designs that stuff this way.
    – kenorb
    Mar 1 at 17:05

41 Answers 41

746

This commonly occurs when exporting views/triggers/procedures from one database or server to another as the user that created that object no longer exists.

You have two options:

1. Change the DEFINER

This is possibly easiest to do when initially importing your database objects, by removing any DEFINER statements from the dump.

Changing the definer later is a more little tricky:

How to change the definer for views

  1. Run this SQL to generate the necessary ALTER statements

    SELECT CONCAT("ALTER DEFINER=youruser@host VIEW ", table_name, " AS ", view_definition, ";") FROM information_schema.views WHERE table_schema='your-database-name';

  2. Copy and run the ALTER statements

How to change the definer for stored procedures

Example:

UPDATE `mysql`.`proc` p SET definer = 'user@%' WHERE definer='root@%'

Be careful, because this will change all the definers for all databases.

2. Create the missing user

If you've found following error while using MySQL database:

The user specified as a definer ('someuser'@'%') does not exist`

Then you can solve it by using following :

GRANT ALL ON *.* TO 'someuser'@'%' IDENTIFIED BY 'complex-password';
FLUSH PRIVILEGES;

MariaDb version:

GRANT ALL PRIVILEGES ON *.* TO 'someuser'@'%' IDENTIFIED BY 'complex-password';
FLUSH PRIVILEGES;

From http://www.lynnnayko.com/2010/07/mysql-user-specified-as-definer-root.html

This worked like a charm - you only have to change someuser to the name of the missing user. On a local dev server, you might typically just use root.

Also consider whether you actually need to grant the user ALL permissions or whether they could do with less.

18
  • 1
    . and grant option are not required.
    – helpse
    Jun 5, 2014 at 4:58
  • 5
    I think it's easier to add a meaningless users, because the next time you do a dbdump and import it, you wont need to do the views/procedures editing again
    – DarkMukke
    Oct 7, 2016 at 8:47
  • 1
    Thanks, I've just dropped the table with the problem, removed the DEFINER=`user`@`host` and re-imported it. Worked like a charm. :ok_hand: Mar 21, 2018 at 13:31
  • 1
    Almost complete: Part I needs similar stanza for triggers table.
    – Otheus
    Feb 28, 2020 at 18:32
  • 6
    As mentioned by @Otheus the answer is incomplete. DEFINER can be a part of not only VIEWS and ROUTINES, but also EVENTS and TRIGGERS. To see where the missing definer is used you may use this query: SELECT DEFINER,'events' FROM INFORMATION_SCHEMA.EVENTS union SELECT DEFINER,'routines' FROM INFORMATION_SCHEMA.ROUTINES union SELECT DEFINER,'triggers' FROM INFORMATION_SCHEMA.TRIGGERS union SELECT DEFINER, 'views' FROM INFORMATION_SCHEMA.VIEWS;
    – ualinker
    Jul 5, 2021 at 13:27
156

The user who originally created the SQL view or procedure has been deleted. If you recreate that user, it should address your error.

5
  • 4
    In addition you will need to grant at least the SELECT and EXECUTE privileges to the added user. I ran into this when I exported a DB backup from one server to another where the user that created the routines didn't exist on the test server.
    – drew010
    Dec 7, 2012 at 20:26
  • 7
    Thanks, this was helpful. Often, when migrating or deploying using mysqldump the user that created the VIEW, TRIGGER or PROCEDURE (the definer) may not be the same on the target system. In that case just recreating the procedure, trigger or view (DROP then re-CREATE) using a valid user on the target system should do the trick. Sep 3, 2013 at 15:57
  • 42
    you can also change who the definer is to an existing user: UPDATE mysql.proc SET definer = 'my_new_user@localhost' WHERE db = 'mydatatbase';
    – user9903
    Feb 24, 2014 at 17:03
  • 1
    Exactly in my case i had a table with trigger that was pointing to a DEFINER user that was deleted. Updating the trigger user solved the problem.
    – Miguel
    Sep 27, 2017 at 16:49
  • You also need to give permission to that user :) GRANT ALL ON *.* TO 'someuser'@'%' IDENTIFIED BY 'complex-password'; FLUSH PRIVILEGES;
    – Victor
    Nov 26, 2019 at 6:32
60

Follow these steps:

  1. Go to PHPMyAdmin
  2. Select Your Database
  3. Select your table
  4. On the top menu Click on 'Triggers'
  5. Click on 'Edit' to edit trigger
  6. Change definer from [user@localhost] to root@localhost

Hope it helps

6
  • 4
    This is the actual solution to the question, rather than creating user and grant permission. just change the definer. May 8, 2017 at 12:25
  • Is there any way to find all triggers in database ? Jul 16, 2019 at 15:21
  • 3
    Find all triggers: SHOW TRIGGERS Sep 11, 2019 at 9:38
  • From the command line 'show triggerss', from PhpMyAdmin select the database and then on the top right of navbar click on the triggers Nov 21, 2019 at 4:56
  • by this approach if u have multiple triggers u need to modify and update all those triggers better approach is to create the user and give the privileges and done
    – Sami Ullah
    Feb 6, 2022 at 5:42
53

I got the same error after updating mysql.

The error has been fixed after this command:

mysql_upgrade -u root

mysql_upgrade should be executed each time you upgrade MySQL. It checks all tables in all databases for incompatibilities with the current version of MySQL Server. If a table is found to have a possible incompatibility, it is checked. If any problems are found, the table is repaired. mysql_upgrade also upgrades the system tables so that you can take advantage of new privileges or capabilities that might have been added.

4
  • Not sure why this did not work for me, I had to manually remove all the triggers in mySQL workbench.
    – user752746
    Mar 12, 2019 at 20:45
  • When I ran the command, I got the below message on the console. The mysql_upgrade client is now deprecated. The actions executed by the upgrade client are now done by the server.
    – daydreamer
    Oct 9, 2020 at 13:26
  • Upgrading from MySQL 5.6 to MySQL 5.7.33, this command did the job and solved the issue ! Thanks for this solution. This is much simpler and reassuring than tampering with the db information schema. Too bad that (on Ubuntu 20.04) the package upgrade does not natively perform this command after each upgrade of MySQL binaries...
    – CuriousFab
    Jun 2, 2021 at 9:58
  • it is not advisable to run this on mariaDB, we have issue after running that
    – ITW
    Aug 6, 2021 at 3:08
41

Create the deleted user like this :

mysql> create user 'web2vi';

or

mysql> create user 'web2vi'@'%';
1
  • 3
    after create that missed user, encountered another error: ERROR 1142 (42000): TRIGGER command denied to user 'web2vi'@'%' for table 'foo' and should add this command grant all on *.* to 'web2vi'@'%' identified by '' after creating user
    – zhuguowei
    Feb 2, 2016 at 9:49
39

If the user exists, then:

mysql> flush privileges;
0
28

Solution is just a single line query as below :

grant all on *.* to 'ROOT'@'%' identified by 'PASSWORD' with grant option;

Replace ROOT with your mysql user name. Replace PASSWORD with your mysql password.

2
  • 3
    Be careful: MySQL users are case sensitive. Jan 8, 2019 at 17:34
  • 1
    I needed to flush privileges after this and it works. Thanks.
    – Victor
    Jun 4, 2020 at 9:11
19

Fixed by running this following comments.

grant all on *.* to 'web2vi'@'%' identified by 'root' with grant option;
FLUSH PRIVILEGES;

if you are getting some_other instead of web2vi then you have to change the name accordingly.

0
15

For future googlers: I got a similar message trying to update a table in a database that contained no views. After some digging, it turned out I had imported triggers on that table, and those were the things defined by the non-existant user. Dropping the triggers solved the problem.

3
  • 2
    Triggers was the issue, I updated the definer in the triggers section. no more issues.
    – Darius
    Sep 4, 2015 at 6:47
  • Thanks, it's very helpful. Also need to update views.
    – toxxxa
    Oct 31, 2015 at 17:54
  • Indeed very helpful :) I would never find that alone. Oct 11, 2016 at 7:16
12

quick fix to work around and dump the file:

mysqldump --single-transaction -u root -p xyz_live_db > xyz_live_db_bkup110116.sql
4
  • 2
    this does not work. the definer is contained in the dump.
    – phil294
    Sep 18, 2017 at 7:58
  • If you use mysqlpump with a "p" instead of a "d", you can use --skip-definer
    – Wouter
    Jan 21, 2019 at 10:32
  • @lyhong I don't have a detailed explanation, but apparently --single-transaction changes the way Lock Tables is implemented during a dump. Or something like that. I don't remember where I read it, but that helped me feel comfortable with "just throwing the flag in". I'm also uneasy with unexplained 'just do this' "answers". Either way, it worked for my case. Aug 24, 2019 at 19:08
  • The --single-transaction seems to resolve my issue
    – kamasuPaul
    Jul 18 at 7:50
11
grant all on *.* to 'username'@'%' identified by 'password' with grant option;

example:

grant all on *.* to 'web2vi'@'%' identified by 'password' with grant option;
2
  • If I grant all privileges to a 'user' @ 'all ips', then what about security??!! Feb 7, 2018 at 15:00
  • @MohsenAbasi This is an example for the development environment. This user can be the system administrator. The prod environment needs to be more careful. Feb 8, 2018 at 6:33
9

I had the same problem with root user ans it worked for me when I replaced

root@%

by

root@localhost

So, if the user 'web2vi' is allowed to connect from 'localhost', you can try:

web2vi@localhost

I'm connected remotely to the database.

0
8

The user 'web2vi' does not exist on your mysql server.

See http://dev.mysql.com/doc/refman/5.1/en/error-messages-server.html#error_er_no_such_user

If that user does exist, check what servers it can access from, although I would have thought that would be a different error (EG you might have web2vi@localhost, but you are accessing the db as web2vi@% (At anything)

0
7

Why am I getting that error? How do I fix it?

I spent a hour before found a decision for a problem like this. But, in my case, I ran this:

mysql> UPDATE `users` SET `somefield` = 1 WHERE `user_id` = 2;
ERROR 1449 (HY000): The user specified as a definer ('root'@'%') does not exist

If you really want to find the problem, just run this commands one by one:

SHOW PROCEDURE STATUS;
SHOW FUNCTION STATUS;
SHOW TRIGGERS;
SHOW FULL TABLES IN database_name WHERE TABLE_TYPE LIKE 'VIEW';

...and, after each of them, look for the field 'definer'.

In my case it was bearded old trigger, that somebody of developers forgot to delete.

7

This happened to me after moving the DB from one server to another server. Initially, the definer was using localhost and the user. On the new server we don't have that user, and host had also been changed. I took a back up of that particular table and removed all the triggers manually from phpmyadmin. After that it has been working fine for me.

4
  • Thanks for the tip, I was able to manually remove all the triggers in mySQL workbench.
    – user752746
    Mar 12, 2019 at 20:46
  • This was indeed a trigger problem for me, I had to remove and recreate them all
    – paul.ago
    Jun 28, 2019 at 16:25
  • is there any other solution than recreating triggers? i'm using test dumps sometimes twice a day. this would disrupt my main processes Sep 4, 2019 at 11:26
  • @TS Guhan did you re-add the triggers after you removed them manually?
    – MailBlade
    Apr 11, 2020 at 6:27
4

My 5 cents.

I had same error while I tried to select from a view.

However problem appears to be that this view, selected from another view that was restored from backup from different server.

and in fact, YES, user was invalid, but was not obvious where to from the first look.

4

I had your very same problem minutes ago, I ran into this issue after deleting an unused user from mysql.user table, but doing an alter view fixed it, here is a handy command that makes it very simple:

SELECT CONCAT("ALTER DEFINER=`youruser`@`host` VIEW ",
table_name," AS ", view_definition,";") FROM 
information_schema.views WHERE table_schema='databasename'

Mix this with the mysql command line (assuming *nix, not familiar with windows):

> echo above_query | mysql -uuser -p > alterView.sql
> mysql -uuser -ppass databasename < alterView.sql

Note: the command generates and extra SELECT CONCAT on the file, making mysql -uuser -ppass databasename < alterView.sql fail if you don't remove it.

Source: https://dba.stackexchange.com/questions/4129/modify-definer-on-many-views

4

Try to set your procedure as SECURITY INVOKER

Mysql default sets procedures security as "DEFINER" (CREATOR OF).. you must set the security to the "invoker".

4

You can change the definer for a specific database to an existing user:

UPDATE mysql.proc SET definer = 'existing_user@localhost' WHERE db = 'database_name';
3

From MySQL reference of CREATE VIEW:

The DEFINER and SQL SECURITY clauses specify the security context to be used when checking access privileges at view invocation time.

This user must exist and is always better to use 'localhost' as hostname. So I think that if you check that the user exists and change it to 'localhost' on create view you won't have this error.

3

The problem is clear - MySQL cannot find user specified as the definer.

I encountered this problem after synchronizing database model from development server, applying it to localhost, making changes to the model and then reapplying it to localhost. Apparently there was a view (I modified) defined and so I couldn't update my local version.

How to fix (easily):

Note: it involves deleting so it works just fine for views but make sure you have data backed-up if you try this on tables.

  1. Login to database as root (or whatever has enough power to make changes).
  2. Delete view, table or whatever you are having trouble with.
  3. Synchronize your new model - it will not complain about something that does not exist now. You may want to remove SQL SECURITY DEFINER part from the item definition you had problems with.

P.S. This is neither a proper nor best-all-around fix. I just posted it as a possible (and very simple) solution.

2
  • i am using toad, cn i delete and recreate using that only os should i login as rooy from terminal and then only do?? Apr 30, 2014 at 8:44
  • Went through all other answers, more errors to deal with with no time for it. Needed a very quick solution. At the end, I've removed all the useless triggers, don't need them anyway on the dev env (db imported from prod), and it worked. Why these stupid errors prevent user from doing any simple db updates. It's nonsense.
    – kenorb
    Mar 1 at 17:06
3

In my case, the table had a trigger with a DEFINER user that didn't exist.

1
  • 2
    right on the nail specially when the app is transfered from a server to another one
    – zardilior
    Mar 19, 2015 at 7:18
3

Your view, view_quotes may have been copied from a different database where web2vi is a valid user into a database where web2vi is not a valid user. Either add the web2vi user to the database or alter the view (normally removing the DEFINER='web2vi'@'%' part and executing the script will do the trick)

2

You can try this:

$ mysql -u root -p 
> grant all privileges on *.* to `root`@`%` identified by 'password'; 
> flush privileges;
2

For me, removing the '' from the DEFINER did the trick.
DEFINER = user@localhost

1

Go into the edit routine section and and at the bottom, change Security Type from Definer to Invoker.

2
  • 5
    Go to where? In which software?
    – kenorb
    Nov 15, 2013 at 9:42
  • @kenorb, in phpMyAdmin you can change MySQL stored routines (procedures and functions), e.g. Security Type.
    – Mikl
    Jul 23, 2015 at 18:21
1

One or several of your views where created/registered by another user. You'll have to check the owner of the view and:

  1. Recreate the user; as the other answers say. or
  2. Recreate the views that where created by the user 'web2vi' using ALTER VIEW

I had this problem once.

I was trying to migrate views, from BD1 to BD2, using SQLYog. SQLYog recreated the views in the other DataBase (DB2), but it kept the user of BD1 (they where different). Later I realized that the views I was using in my query were having the same error as you, even when I wasn't creating any view.

Hope this help.

1

If this is a stored procedure, you can do:

UPDATE `mysql`.`proc` SET definer = 'YournewDefiner' WHERE definer='OldDefinerShownBefore'

But this is not advised.

For me, better solution is to create the definer:

create user 'myuser' identified by 'mypass';
grant all on `mytable`.* to 'myuser' identified by 'mypass';
2
  • You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'grant all on 'mytable'.* to 'myuser' identified by 'mypass';' at line 1
    – Cerin
    Jun 27, 2014 at 17:37
  • @Cerin, Just change '' around mytable to ``. My answer aims to help people with this problem.. Think of reconsidering your downvote..
    – helpse
    Jul 9, 2014 at 21:17
1

when mysql.proc is empty, but system always notice "user@192.168.%" for table_name no exist,you just root in mysql command line and type:

CHECK TABLE `database`.`table_name` QUICK FAST MEDIUM CHANGED;
flush privileges;

over!

1

in my case I had a trigger on that table that I could not update data getting the same error.

MySQL error 1449: The user specified as a definer does not exist

the solution was to delete the triggers on that table and recreate them again, this fixed the issue, since the the trigger was made with another user from another server, and the user name changed on the new server after changing hosting company . that's my 2 cents

Not the answer you're looking for? Browse other questions tagged or ask your own question.