Friday, June 27, 2025

Insert data csv ke Mysql

Here's a step-by-step guide to loading data from a CSV file on a server into a MySQL database:

Step 1: Prepare the CSV File
1. *Ensure the CSV file is in the correct format*: The CSV file should have the same structure as the MySQL table you want to import into.
2. *Upload the CSV file to the server*: Upload the CSV file to the server where your MySQL database is hosted.

Step 2: Connect to MySQL
1. *Use a MySQL client*: Use a MySQL client like phpMyAdmin, MySQL Workbench, or the MySQL command-line tool to connect to your MySQL database.
2. *Enter your database credentials*: Enter your database username, password, and database name to connect to your MySQL database.

Step 3: Use LOAD DATA INFILE
1. *Use the LOAD DATA INFILE statement*: Use the LOAD DATA INFILE statement to import data from the CSV file into your MySQL database.
2. *Specify the CSV file path*: Specify the path to the CSV file on the server.
3. *Specify the table and columns*: Specify the table and columns you want to import into.

Example SQL Query
LOAD DATA LOCAL INFILE '/path/to/your/file.csv'
INTO TABLE your_table
FIELDS TERMINATED BY ','
ENCLOSED BY '\"'
LINES TERMINATED BY '\n'
IGNORE 1 ROWS;

Considerations
- *File path*: Ensure the file path is correct and the MySQL server has permission to read the file.
- *Data types*: Ensure the data types in the CSV file match the data types in the MySQL table.
- *Error handling*: Check for errors during the import process and handle them accordingly.

Using phpMyAdmin
1. *Go to the Import tab*: Go to the Import tab in phpMyAdmin.
2. *Select the CSV file*: Select the CSV file you want to import.
3. *Specify the format*: Specify the format as CSV.
4. *Specify the table*: Specify the table you want to import into.
5. *Click Go*: Click the Go button to start the import process.

By following these steps, you can load data from a CSV file on a server into a MySQL database.
Insert data csv ke Mysql SocialTwist Tell-a-Friend

No comments: