- Trending Categories
- Data Structure
- Operating System
- C Programming
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
What kind of settings can we do to a CSV file by query while exporting the values from MySQL table into a CSV file?
As we know that CSV is a simple file format used to store tabular data, such as spreadsheet or database. While exporting the data from MySQL table to CSV file we can use FIELDS TERMINATED BY option to put the values of fields in different cells of CSV file. It can be illustrated with the help of the following example −
Suppose we are having following data from table ‘Student_info’ −
mysql> Select * from Student_info; +------+---------+------------+------------+ | id | Name | Address | Subject | +------+---------+------------+------------+ | 101 | YashPal | Amritsar | History | | 105 | Gaurav | Chandigarh | Literature | | 125 | Raman | Shimla | Computers | | 130 | Ram | Jhansi | Computers | | 132 | Shyam | Chandigarh | Economics | | 133 | Mohan | Delhi | Computers | +------+---------+------------+------------+ 6 rows in set (0.07 sec)
Suppose we want only two columns ‘id’ and ‘Name’ from the above table to be exported into a file then the following query can export the values of only ‘id’ and ‘name’ from ‘Student_info’ table into a file named ‘student2.csv’ −
mysql> Select id, Name from Student_info INTO OUTFILE 'C:/mysql/bin/mysql-files/student2.csv' FIELDS TERMINATED BY ‘,’; Query OK, 6 rows affected (0.07 sec)
The above query will create a file named ‘Student2.csv’ and export the values of columns ‘id’ and ‘name’ from ‘Student_info’ table into different cells of student2.csv file.
- What kind of settings can we do to a text file by query while exporting the values from MySQL table into a text file?
- How can we import data from .CSV file into MySQL table?
- How can we export all the data from MySQL table into a CSV file?
- How can we export some field(s) from MySQL table into a CSV file?
- Importing / Exporting CSV file in PowerShell
- How can we store any other value than N in CSV file if we export the data to CSV file from a table which contains a NULL value(s)?
- How MySQL evaluates if we export the data to CSV file from a table which contains a NULL value(s)?
- How to append data into a CSV file using PowerShell?
- Python Pandas- Create multiple CSV files from existing CSV file
- Write data from/to a .csv file in java
- How to read a CSV file and store the values into an array in C#?
- Writing data from database to .csv file
- Writing a Pandas DataFrame to CSV file
- How can we export all the data from MySQL table into a text file?
- Make a multiline plot from .CSV file in matplotlib