how to populate a table in MySQL from and existing csv file 1

how to populate a table in MySQL from and existing csv file

loaddata localinfile’YouCSVFileName.csv’into table ReplacewithT fields terminated by’,’enclosed by’"’;

Here is what the above code is Doing:
1. We are using the mysql.connector library to connect to the database.
2. We are using the mysql.connector.connect() method to connect to the database.
3. We are using the cursor() method to create a cursor object.
4. We are using the execute() method to execute the SQL query.
5. We are using the fetchall() method to fetch all the rows.
6. We are using the for loop to iterate over the rows.
7. We are using the print() method to print the rows.

Similar Posts