zoukankan      html  css  js  c++  java
  • mysql File '/var/lib/mysql/txtdata/yz2014_1.txt' not found (Errcode: 13 "Permission denied")

    mysql中的LOAD DATA 导致 ERROR 13 解决办法
     
    mysql> LOAD DATA INFILE ‘/root/hello.txt’ INTO TABLE dbtest.pet(name); ———–>
    ERROR 13 (HY000): Can’t get stat of ‘/root/hello.txt’ (Errcode: 13) 第一步:我们通过mysql的客户端工具perror进行分析 shell> ./bin/perror 13
    OS error code  13:  Permission denied 得出是权限的问题 第二步我们查看mysql手册
    For security reasons, when reading text files located on the server, the files must
    either reside in the database directory or be readable by all. Also, to use LOAD DATA
    INFILE on server files, you must have the FILE privilege 也就是说有三个条件: 1.数据文件要在数据库目录 2.要能被读写
    3.使用这个命令的用户要有FILE权限 
    好了,最后,我们来修改下我们的命令: 方法1:
    mysql> LOAD DATA LOCAL INFILE '/root/hello.txt' INTO TABLE dbtest.pet(name); 方法2:
    第一步:移动文件到数据库目录
    shell>mv /root/hello.txt /usr/local/mysql/data/dbtest 第二步:
    mysql>LOAD  DATA INFILE '/usr/local/mysql/data/dbtest/hello.txt' INTO TABLE dbtest.pet(name); 表结构:
    mysql>DESCRIBE pet;
    +——-+————-+——+—–+———+—————-+
    | Field | Type        | Null | Key | Default | Extra          | +——-+————-+——+—–+———+—————-+
    | id    | int(10)     | NO   | PRI | NULL    | auto_increment | | name  | varchar(50) | YES  |     | NULL    |                | +——-+————-+——+—–+———+—————-+ 2 rows in set (0.00 sec)
    文章作者:佛福
    本文地址:http://www.liufofu.com/201204104.html
    版权所有 © 转载时必须以链接形式注明作者和原始出处!


    第二种:

    原因:没有安装

    安装 cmake 和 bison

    首先可以查看下是否安装了 cmake # rpm -qa |grep cmake

    [root@HBase ~]# cd
    [root@HBase ~]# yum install cmake
    已加载插件:fastestmirror, langpacks
    base                                                                                                     | 3.6 kB  00:00:00     
    epel                                                                                                     | 4.3 kB  00:00:00     
    extras                                                                                                   | 3.4 kB  00:00:00     
    mariadb                                                                                                  | 2.9 kB  00:00:00     
    updates                                                                                                  | 3.4 kB  00:00:00     
    Loading mirror speeds from cached hostfile
     * base: mirrors.yun-idc.com
     * epel: mirrors.aliyun.com
     * extras: mirrors.yun-idc.com
     * updates: mirrors.yun-idc.com
    正在解决依赖关系
    --> 正在检查事务
    ---> 软件包 cmake.x86_64.0.2.8.12.2-2.el7 将被 安装
    --> 解决依赖关系完成

    依赖关系解决

    ================================================================================================================================
     Package                     架构                         版本                                 源                          大小
    ================================================================================================================================
    正在安装:
     cmake                       x86_64                       2.8.12.2-2.el7                       base                       7.1 M

    事务概要
    ================================================================================================================================
    安装  1 软件包

    总下载量:7.1 M
    安装大小:27 M
    Is this ok [y/d/N]: y
    Downloading packages:
    cmake-2.8.12.2-2.el7.x86_64.rpm                                                                          | 7.1 MB  00:00:20     
    Running transaction check
    Running transaction test
    Transaction test succeeded
    Running transaction
      正在安装    : cmake-2.8.12.2-2.el7.x86_64                                                                                 1/1
      验证中      : cmake-2.8.12.2-2.el7.x86_64                                                                                 1/1

    已安装:
      cmake.x86_64 0:2.8.12.2-2.el7                                                                                                 

    完毕!

    [root@HBase ~]#yum install bison
    完毕!

    [root@HBase ~]# mysql
    Welcome to the MariaDB monitor.  Commands end with ; or g.
    Your MariaDB connection id is 4
    Server version: 10.0.28-MariaDB MariaDB Server

    Copyright (c) 2000, 2016, Oracle, MariaDB Corporation Ab and others.

    Type 'help;' or 'h' for help. Type 'c' to clear the current input statement.

    MariaDB [(none)]> use test
    Database changed
    MariaDB [test]> load data  infile '/var/lib/mysql/txtdata/yz2014_1.txt' into table express312 fields terminated by',' LINES TERMINATED BY ' ' (id,orderid,orderdate,ordercontent,sendaddress,sendname,sendphone,recvaddress,recvname,recvphone);
    ERROR 29 (HY000): File '/var/lib/mysql/txtdata/yz2014_1.txt' not found (Errcode: 13 "Permission denied")
    MariaDB [test]> exit
    Bye
    [root@HBase ~]# service mysqld stop
    Redirecting to /bin/systemctl stop  mysqld.service
    Failed to stop mysqld.service: Unit mysqld.service not loaded.
    [root@HBase ~]# service mysql stop
    Shutting down MySQL... SUCCESS!
    [root@HBase ~]# service mysql start
    Starting MySQL. SUCCESS!
    [root@HBase ~]# mysql
    Welcome to the MariaDB monitor.  Commands end with ; or g.
    Your MariaDB connection id is 3
    Server version: 10.0.28-MariaDB MariaDB Server

    Copyright (c) 2000, 2016, Oracle, MariaDB Corporation Ab and others.

    Type 'help;' or 'h' for help. Type 'c' to clear the current input statement.

    MariaDB [(none)]> load data  infile '/var/lib/mysql/txtdata/yz2014_1.txt' into table express312 fields terminated by',' LINES TERMINATED BY ' ' (id,orderid,orderdate,ordercontent,sendaddress,sendname,sendphone,recvaddress,recvname,recvphone);
    ERROR 1046 (3D000): No database selected
    MariaDB [(none)]> use test
    Database changed
    MariaDB [test]> load data  infile '/var/lib/mysql/txtdata/yz2014_1.txt' into table express312 fields terminated by',' LINES TERMINATED BY ' ' (id,orderid,orderdate,ordercontent,sendaddress,sendname,sendphone,recvaddress,recvname,recvphone);
    ERROR 29 (HY000): File '/var/lib/mysql/txtdata/yz2014_1.txt' not found (Errcode: 13 "Permission denied")
    MariaDB [test]> unlock tables;
    Query OK, 0 rows affected (0.00 sec)

    MariaDB [test]> set read_only=0;
    ERROR 1229 (HY000): Variable 'read_only' is a GLOBAL variable and should be set with SET GLOBAL
    MariaDB [test]> set global read_only=0;
    Query OK, 0 rows affected (0.00 sec)

    MariaDB [test]> load data local infile '/var/lib/mysql/txtdata/yz2014_1.txt' into table express312 fields terminated by',' LINES TERMINATED BY ' ' (id,orderid,orderdate,ordercontent,sendaddress,sendname,sendphone,recvaddress,recvname,recvphone);
    Query OK, 42988342 rows affected, 65535 warnings (23 min 2.45 sec)
    Records: 236735914  Deleted: 0  Skipped: 193747572  Warnings: 1786717883

    MariaDB [test]>

  • 相关阅读:
    Eclipse中web项目部署至Tomcat步骤
    解释Eclipse下Tomcat项目部署路径问题(.metadata.pluginsorg.eclipse.wst.server.core mp0wtpwebapps)
    JAVA_HOME环境变量失效的解决办法
    java 程序运行过程 简介
    深入研究Java类加载机制
    SPRING SECURITY JAVA配置:Web Security
    Spring mvc Security安全配置
    FastDateFormat
    Hibernate中Criteria的完整用法
    升级win10,提示(RAM)内存不足2G的解决的方法,亲測可行
  • 原文地址:https://www.cnblogs.com/miaoer/p/6272388.html
Copyright © 2011-2022 走看看