把SQL的显示结果输出到文本中

MySQL查询结果有三种方法输出到文本中

  1. 直接执行命令

    1
    > select name from table  into outfile '/tmp/test.txt';

    在目录/tmp/下会产生文件test.txt

    报错:ERROR 1 (HY000): Can't create/write to file '/data/test.xls' (Errcode: 13)

    mysql没有写权限

  2. 查询时自动写入文件

    1
    2
    > pager cat > /tmp/test.txt ;
    PAGER set to 'cat > /tmp/test.txt'

    之后的所有查询结果都自动写入/tmp/test.txt',并前后覆盖

  3. 直接在bash下执行

    1
    # mysql -h 127.0.0.1 -u root -p dabase_name -P 3306 -e "select * from table"  > /tmp/test.txt

Comments

Your browser is out-of-date!

Update your browser to view this website correctly.&npsb;Update my browser now

×