Hi

I have a linux server with mysql installed.There is some data in mysql tables.
Also.I have a .csv file (not from the aforementioned database)
I need to compare the data in the database nad the .csv and print out the difference.

I tried writing a shell script for that but I was unsuccessful.

I need to ask if there's any way I can export the data from mysql tables to .csv file format and use the diff command to see the comparison of the generated file and the file I had initially.

~thanks

Unless your CSV file came from a MySQL database with the same structure it is likely that you will need to write a transform to get the data in a format that is what you expect. Although, if you are going to that length you might as well just write the comparison function as well.

Hello,

I would import the CSV file into the MySQL database as a different table. For example if the table in the current database is customers then make the import table customers1. Then use sql queries to compare the two tables. This type of query is what MySQL is designed for.

MySQL has an import function called mysqlimport that can be run form the command line and is designed to import text files like csv files. If you have any type of GUI interface (like phpmyadmin or mysqlworkbench ) most of them have built in options to load a csv file.

The a query to find matching records or records in table1 not in table2 is easy to write.

Hope this helps.

thanks
I found one ..

mysql -uexampleuser -pletmein exampledb -B -e "select * from `person`;" | sed 's/\t/","/g;s/^/"/;s/$/"/;s/\n//g' > filename.csv

but before select statement could begin,I need to write another statement
use xyz;

how do I induce this ( use xyz; ) in the shell code ???? .. piping isnt helping

~thanks

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.