This script allows you to automatically create a table in your MySQL database and populate it using data from a CSV file.
-
Dependencies:
- Python 3.x
mysql-connector-python
Install the required module using:
pip install mysql-connector-python
-
Configuration:
Before running the script, make sure to modify the
config
dictionary in the script:config = { 'user': 'YOUR USER NAME', 'password': 'YOUR PASSWORD', 'host': 'YOUR HOST', 'database': 'YOUR DATABASE NAME' }
-
CSV File:
Ensure that your CSV file is formatted correctly to match the table structure defined in the script. Update the file path and encoding format in this line:
with open('PATH/YOURFILE.csv', 'r',encoding='YOUR FILE FORMAT', errors='replace') as file:
Simply run the script using:
python your_script_name.py
- Make sure to have a backup of your database before running the script, especially if you are working in a production environment.
- Handle your credentials securely. Consider using environment variables or secrets management tools instead of hardcoding them in the script.
- The script will automatically drop the table named
rowdyT1
if it exists and create a new one. - Errors encountered during the insertion of rows from the CSV will be printed to the console.
Feel free to fork this repository, make changes, and submit Pull Requests. For major changes, please open an issue first to discuss what you'd like to change.
If you find any bugs or would like to suggest new features, please open an issue. Feedback is always welcome!
This project is licensed under the MIT License - see the LICENSE.md file for details.