zoukankan      html  css  js  c++  java
  • mysql中FILE权限

    FILE权限指的是对服务器主机上文件的访问,数据库用户拥有FILE权限才可以执行select into outfile,load data infile操作。

    参考文章:http://blog.itpub.net/27126919/viewspace-2125131/

    测试select into outfile操作

    root用户上执行

    mysql> CREATE USER 'filetest'@'localhost' IDENTIFIED BY123456'
    FILE权限是对所有数据库文件而言的,因此数据库只能写成*.*,而不是某一个数据库 mysql> grant file on test3.* to 'filetest'@'localhost'; ERROR 1221 (HY000): Incorrect usage of DB GRANT and GLOBAL PRIVILEGES //赋予FILE权限 mysql> grant file on *.* to 'filetest'@'localhost'; Query OK, 0 rows affected (0.00 sec) //赋予select权限 grant select on test3.* to 'filetest'@'localhost'; //刷新信息 flush privileges;

    filetest用户上执行

    use test3;
    mysql> select * from test2 into outfile 'd:/test.txt'
        -> ;
    ERROR 1290 (HY000): The MySQL server is running with the --secure-file-priv opti
    on so it cannot execute this statement
    
    //即使有了file权限,输出目录路径应该secure_file_priv一致
    mysql> show variables like '%sec%'
        -> ;
    +--------------------------+----------+
    | Variable_name            | Value    |
    +--------------------------+----------+
    | require_secure_transport | OFF      |
    | secure_auth              | ON       |
    | secure_file_priv         | e:	est |
    +--------------------------+----------+
    mysql> select * from test2 into outfile 'e:/test/test.txt';
    Query OK, 1 row affected (0.01 sec)

    测试load data infile操作:

    mysql> load data infile 'e:/test/test.txt' into table test2;
    ERROR 1142 (42000): INSERT command denied to user 'filetest'@'localhost' for table 'test2'
    //需要给filetest赋予insert权限
    
    root用户上执行:
    mysql> grant insert on test3.* to 'filetest'@'localhost';
    flush privileges;
    
    filetest用户:
    //infile的目录也要与secure_file_priv一致
    mysql> load data infile 'e:/test/test.txt' into table test2;
    Query OK, 1 row affected (0.07 sec)
    Records: 1  Deleted: 0  Skipped: 0  Warnings: 0
  • 相关阅读:
    深度优先和广度优先
    水管工游戏(深度优先)
    炸弹人
    广度优先(迷宫找人)
    System.Data.Entity.Core.MetadataException: 无法加载指定的无数据资源
    Element Cascader 级联选择器 单选操作优化
    Windows服务 ProjectInstaller 获取 路径
    Quartz.NET ScheduledFireTimeUtc 当超过1分钟时出现的问题。
    记录:一个SQL SERVER奇怪的问题。
    log4.net 配置
  • 原文地址:https://www.cnblogs.com/darange/p/10508714.html
Copyright © 2011-2022 走看看