# MySQL Table Backup

This guide provides detailed instructions on generating a CSV/XLSX file from a MySQL table, covering both Windows and Linux platforms.<br>

Follow the outlined steps to ensure successful execution and a secure backup.

## Objective

The objective of this guide is to help users export data from a MySQL table to a CSV file, which will be saved at a specified path on the client's machine. This process is vital for data portability, backup, and sharing.

## Prerequisites

Ensure the following requirements are met before proceeding:

* **MySQL Client**: Installed on the client machine.
* **Access Credentials**: Valid credentials for the MySQL server.
* **Database and Table Access**: Access to the specific database and table intended for backup.
* **User Permissions**: Adequate permissions to execute MySQL commands and queries.

## Steps for Windows

1. Navigate to MySQL's bin directory
   * Open the Command Prompt on your Windows system.
   * Change the directory to the location where MySQL is installed.

     ```bash
     cd C:\Program Files\MySQL\MySQL Server 8.0\bin
     ```

2. Run the MySQL Command
   * In the Command Prompt, execute the following command, replacing the placeholders with your specific details:

     ```bash
     mysql -u {user} -p -D {database_name} -e "SELECT {fields} FROM {tablename};" > C:\path\to\save\file.csv
     ```
   * Replace the following placeholders:
     * **{user}**: Your MySQL username.
     * **{database\_name}**: Name of the database.
     * **{tablename}**: Name of the table.
     * **{fields}**: Names of the fields to export, separated by commas.
   * **Example Command:**

     ```bash
     mysql -u root -p -D r63 -e "SELECT jobparmtype, jobparmkey, jobparmdescription, visible FROM jobparm;" > C:\Users\tejeswar\Downloads\jobparm.csv
     ```

     #### <br>

3. Enter MySQL Password
   * After executing the command, the system will prompt you to enter your MySQL password. Input the password and press **Enter**.<br>

4. CSV File Generation

   * If the password is correct and the command executes successfully, the selected data will be exported to the specified CSV file path:

     **Example path:**

     ```
     C:\Users\tejeswar\Downloads\jobparm.csv
     ```

5. View the CSV File
   * Navigate to the location where the CSV file is saved.\
     Open the file using a text editor (e.g., **Notepad**) or a spreadsheet program (e.g., **Microsoft Excel**) to verify the data.

## Steps for Linux

1. Navigate to MySQL's bin Directory (if needed)
   * Open the **Terminal** on your Linux system.
   * If required, navigate to MySQL’s bin directory:

     ```bash
     cd /usr/local/mysql/bin
     ```

2. Run the MySQL Command
   * Execute the following command, replacing the placeholders with actual values:

     ```bash
     mysql -u {user} -p -D {database_name} -e "SELECT {fields} FROM {tablename};" > /path/to/save/file.csv
     ```

     \
     **Example Command:**

     ```bash
     mysql -u root -p -D r63 -e "SELECT jobparmtype, jobparmkey, jobparmdescription, visible FROM jobparm;" > /home/username/jobparm.csv
     ```

     ####

3. Enter MySQL Password
   * The system will prompt you to enter the MySQL password for the **{user}**. Enter the password and press **Enter**.<br>

4. CSV File Generation
   * Upon successful execution, the data will be exported as a CSV file to the specified path:

     **Example path:**

     ```
     /home/username/jobparm.csv
     ```

5. View the CSV File
   * Open the file using any text editor (e.g., **nano, Vim**) or a spreadsheet application (e.g., **LibreOffice Calc, Excel**).

{% hint style="info" %}

* **Customization**:\
  Replace placeholders (**{user}, {database\_name}, {tablename}, {fields}**) with your specific MySQL credentials, database, table, and fields.
* **Permissions**:\
  Ensure the MySQL user has sufficient privileges to run the SELECT query and export the data.
* **Output Path**:\
  Verify the specified directory exists and has appropriate write permissions before exporting.
  {% endhint %}

***

Copyright © 2025, OvalEdge LLC, Peachtree Corners, GA, USA.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.ovaledge.com/release8.1/deployment-and-maintenance/backup/mysql-table-backup.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
