线上库新建账号以后给select权限,但是 select into outfile导出查询结果的时候直接报错:

select * from user into outfile '/tmp/user.csv';  
ERROR 1045 (28000): Access denied for user cha@'192.168.%' (using password: YES)

赋予file权限

(root@localhost) [mysql]>grant file on test.* to cha@'192.168.%';  
ERROR 1221 (HY000): Incorrect usage of DB GRANT and GLOBAL PRIVILEGES  --提示该权限是global,必须使用*.* 方式
(root@localhost) [mysql]>grant file on *.* to cha@'192.168.%'; 
Query OK, 0 rows affected (0.00 sec) 

再次执行查询导出成功:

select * from user into outfile '/tmp/user.csv';  
Query OK, 300 rows affected (0.01 sec)  
带符号 * 的表示必填项