zoukankan      html  css  js  c++  java
  • csv impor export with mysql

    server-side:
    SELECT id,tutorialId,tutorialName,ucreatelink,structureVersion FROM base_course
    INTO OUTFILE '/tmp/orders.csv'
    FIELDS TERMINATED BY ','
    ENCLOSED BY '"'
    LINES TERMINATED BY ' '

    client side:
    mysql -uucauser -p'Key!go003' -hucampus-prd-cluster.cluster-cmtmrzrxlu53.rds.cn-northwest-1.amazonaws.com.cn --database=ucampus --default-character-set=utf8mb4 --batch --raw < /tmp/demo_sql_query.sql > /tmp/demo_csv_export.tsv


    mysql -udemo_user -p -h127.0.0.1 --port=3306
    --default-character-set=utf8mb4 --database=demo_database
    --batch --raw < /tmp/demo_sql_query.sql > /tmp/demo_csv_export.tsv


    For completeness you could convert to csv (but be careful because tabs could be inside field values - e.g. text fields)

    tr ' ' ',' < file.tsv > file.csv

    If you have PHP set up on the server, you can use mysql2csv to export an (actually valid) CSV file for an abitrary mysql query. See my answer at MySQL - SELECT * INTO OUTFILE LOCAL ? for a little more context/info.

    I tried to maintain the option names from mysql so it should be sufficient to provide the --file and --query options:

    ./mysql2csv --file="/tmp/result.csv" --query='SELECT 1 as foo, 2 as bar;' --user="username" --password="password"
    "Install" mysql2csv via

    wget https://gist.githubusercontent.com/paslandau/37bf787eab1b84fc7ae679d1823cf401/raw/29a48bb0a43f6750858e1ddec054d3552f3cbc45/mysql2csv -O mysql2csv -q && (sha256sum mysql2csv | cmp <(echo "b109535b29733bd596ecc8608e008732e617e97906f119c66dd7cf6ab2865a65 mysql2csv") || (echo "ERROR comparing hash, Found:" ;sha256sum mysql2csv) ) && chmod +x mysql2csv


    server-side:
    LOAD DATA INFILE 'c:/tmp/discounts.csv'
    INTO TABLE discounts
    FIELDS TERMINATED BY ','
    ENCLOSED BY '"'
    LINES TERMINATED BY ' '
    IGNORE 1 ROWS;

    local

    LOAD DATA LOCAL INFILE 'c:/tmp/discounts.csv'
    INTO TABLE discounts
    FIELDS TERMINATED BY ','
    ENCLOSED BY '"'
    LINES TERMINATED BY ' '
    IGNORE 1 ROWS;

  • 相关阅读:
    hibernate之初学复合主键
    hibernate之初学增删改查
    hibernate之配置文件帮助文档
    hibernate之初学项目搭建
    Python调用OpenCV读显写
    C++写入txt
    C++逐词读取txt
    C++逐行读取txt
    C#调用C++系列二:传结构体
    C#调用C++系列一:简单传值
  • 原文地址:https://www.cnblogs.com/SZLLQ2000/p/10782203.html
Copyright © 2011-2022 走看看