MySQL Export Table to CSV

I was recently assigned the task to export a MySQL table to a file in CSV format, so I was time to brush my Linux and MySQL skills..

After a little research I managed to get things done using the following command:

mysql -uroot -ptoor -e "SELECT * from tablename" databasename | sed 's/\t/","/g;s/^/"/;s/$/"/' > filename.csv

I am using the mysql tool to connect to the database "databasename" using root as username and toor as password. Pay attention here, the root is the MySQL root user, not the OS user!

After executing the query to get all the records from the table "tablename" I pipe the output to the sed utility to add the delimiters. In the last step, the output is redirected to the file we want to contain the table.

Popular posts from this blog

Domain Controller Machine Password Reset

Configuring a Certificate on Exchange Receive Connector

Running Multiple NGINX Ingress Controllers in AKS