Ask To Apps
  • Home
  • WordPress
  • Elasticsearch
  • PHP
  • Linux
  • Website Peformance

Tag : load-data-infile

Export mysql query data in csv file using command line

22/04/2014 Article

We can easily export MySQL select query records into  CSV file using shell command. Following are couple of ways to do that.

  1. By using mysql command – LOAD DATA IN FILE
  2. By using “mysql” and “sed” command

 

Mysql Load data infile

Here is command for export data using mysql infile. Please keep in mind that, “filename.csv” file will generate it on mysql remote server not on the local server from you are running the command.watch movie Chasing Coral now

mysql --host=$HOST--user=$USER--password=$PASS $DBNAME -e "select * from tablename   INTO OUTFILE  '/tmp/filename.csv'  FIELDS TERMINATED BY ',' LINES TERMINATED BY '\n';"

Mysql and Sed Command.

It will fetch records using mysql select command and replace each TAB with COMMA(,) and put that replace comma seperate string into file named “filename.csv”. Please keep in mind that it will replace TAB from data returned query as well.

mysql --host=$HOST--user=$USER--password=$PASS $DBNAME -e "select   * from tablename" | sed 's/\t/,/g' > filename.csv

 

 

Categories: Linux, MySql

Tags: csv, load data infile, MySQL, mysql export

About Author:

Recent Posts

  • Install and configure logstash-forwarder
  • Redirect request on php script through squid proxy
  • Alerting for Elasticsearch : Log watcher in elasticsearch using ES Watcher
  • Detect face from image using python script with OpenCV
  • Change mysql root password on centos
  • Search part of word in elasticsearch using nGram – auto-complete search
  • Connect VPN on centos linux using command line
  • Custom river plugin in elasticsearch
  • Backup elasticsearch with snapshot and restore api
  • PHP code to exact keywords from text.

Tags

apache Apache Lucene cache Distributed Elastic Index Elasticsearch elasticsearch performance Git Clone Git Hub Git Hub Configuration Git Hub Installation grep Import Install MySQL JSON over HTTP Linux Linux Command Linux Commands Linux search local file lsyncd md5sum Multile Domain Multisite MySQL Open Source optimization performance php performance real time search remote file Remote Git Hub remote sync RESTful Scale Schema Free Search Engine Search Index Search keyword static cache Sub Domain sync Very fast Wordpress Wordpress multisite

Copyright Ask To Apps 2022 | Proudly powered by WordPress

facebook twitter google linkedin Email Rss