Skip to main content

Posts

Showing posts from August, 2024

MySQL Table Data Export And Send To Email

MySQL Data Downloader and Emailer This project connects to a MySQL database, downloads data from specified tables, stores it in CSV files, and sends them via email. Prerequisites Python 3.x MySQL Connector for Python Pandas SMTP access for sending emails Setup Clone the repository: Navigate to the project directory: Install the required Python packages: Code:  import mysql.connector import pandas as pd import os from datetime import datetime import smtplib from email.mime.multipart import MIMEMultipart from email.mime.base import MIMEBase from email.mime.text import MIMEText from email import encoders # Database connection details db_config = {     'host': 'xx.xx.xx.xx',  # Replace with your MySQL host     'user': 'xxxxxxxx',  # Replace with your MySQL username     'password': 'xxxxxxxx',  # Replace with your MySQL password     'database': 'xxxxxxxx'  # Replace with your database name } # List of table names to query table...

MySQL Database connection with python using sqlalchemy

import pandas as pd import pymysql from sqlalchemy import create_engine import urllib.parse username = 'xxxxxxxxx' password = 'xxxxxxxxx' password_encoded = urllib.parse.quote(password) server = 'XX.XX.XX.XX' port = xxxx database = '' conn_string = f'mysql+pymysql://{username}:{password_encoded}@{server}:{port}/{database}' sql_query = ('select *'             ' from Phone_cloud.call_files_New'             ' limit 100;'             ) engine = create_engine(conn_string) df = pd.read_sql(sql_query, con=engine) df