anyongjin / mysql_ibd

import data from ibd files for mysql
MIT License
30 stars 5 forks source link

sql file has tabs and spaces which does not work well while executing #22

Closed demirciberkan closed 1 month ago

demirciberkan commented 1 month ago

here is an example output

Error executing script: (1064, "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'CREATE TABLE temp (\n\tid int NOT NULL AUTO_INCREMENT,\n\tt double NOT NULL,\n\t' at line 2")

may you fix the code start from line 163. Below you may find the working one

with open(sql_path, "r") as outputfile:
            db_config = config["connection_info"]
            connection = pymysql.connect(**db_config)
            cursor = connection.cursor()

            sql_script = outputfile.read()  # Read the entire content of the SQL file
            sql_commands = sql_script.split(';')  # Split commands by semicolon

            for command in sql_commands:
                command = command.strip()  # Remove leading/trailing whitespace
                if command:  # Ensure the command is not empty
                    try:
                        cursor.execute(command)  # Execute each command
                    except pymysql.MySQLError as e:
                        print(f"Error executing command: {command} - {e}")

            connection.commit()  # Commit all changes
            cursor.close()
            connection.close()
anyongjin commented 1 month ago

Thanks for your suggestion. I adopted your code and modified it. I can't test it as I don't have MySQL installed locally, Please pull the latest code to check whether it works.

demirciberkan commented 1 month ago

Works great thank you