ERROR 1356 (HY000): View ‘mysql.user’ references invalid table(s) or column(s) or function(s) or def

I needed to change the hostname on mysql database logins because the application server name was changed. I ran the following command:

MariaDB [mysql]>  update user set host='app1.example.com' where Host='app2.example.com';
ERROR 1356 (HY000): View 'mysql.user' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them

Starting with the MariaDB-10.4+ the mysql.user is a view rather than a table.

Always check the official documentation and use SET PASSWORD or ALTER USER to manage user authentication.

If you need to execute massive command rename user, for example because you have change hostname to application server, this script can help you :

An example output :

select user,host from user where host='app1.example.com';
+-----------+-----------------+
| User      | Host            |
+-----------+-----------------+
| USER1     | app1.example.com|
| USER2     | app1.example.com|
| USER3     | app1.example.com|
| USER4     | app1.example.com|
| USER5     | app1.example.com|
+-----------+-----------------+

We need to change Host from app1.example.com to app10.example.com and theoretically you have to run 5 rename user commands, but thanks to this script the command will be generated without writing “by hand”.

SELECT CONCAT('RENAME USER \'', user, '\'@\'',host, '\' TO \'', user, '\'@\'app2.example.com\';'  ) from mysql.`user` u where host='app1.example.com';
|+-----------+-----------------+-----------------+-----------------+--------------+
|RENAME USER 'USER1'@'app1.example.com' TO 'USER1'@'app2.example.com';            |
|RENAME USER 'USER2'@'app1.example.com' TO 'USER2'@'app2.example.com';            |
|RENAME USER 'USER3'@'app1.example.com' TO 'USER3'@'app2.example.com';            |
|RENAME USER 'USER4'@'app1.example.com' TO 'USER4'@'app2.example.com';            |
|RENAME USER 'USER5'@'app1.example.com' TO 'USER5'@'app2.example.com';            |
+-----------+-----------------+-----------------+-----------------+---------------+

Copy the output and execute.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值