Programming Basics SQL HTML CSS JavaScript React Python C++ Java JavaFX Swing Problem Solving English English Conversations Computer Fundamentals Linux Learn Typing

كيفية نقل البيانات من SQLite3 إلى MySQL و العكس؟

السلام عليكم،

أحاول أن أنقل قواعد البيانات المحفوظة في SQLite3 إلى MySQL و العكس.

الأمر نجح عند النقل من MySQL إلى SQLite3 باستخدام الكود التالي.

def convert_to_sqlite3():
try:
# Connect to MySQL database
mysql_engine = create_engine(f'mysql+mysqlconnector://root:{hashed_password1}@localhost/color_group')
query = "SELECT * FROM color_numbers"
df = pd.read_sql(query, con=mysql_engine)
# Connect to SQLite3 database
sqlite_conn = sqlite3.connect('your_database_name.db')
# Write the data into SQLite3 database
df.to_sql('color_numbers', sqlite_conn, if_exists='replace', index=False)
# Close the connections
#mysql_engine.close()
sqlite_conn.close()
except Exception as e:
la.configure(text=f"{e}")
def convert_to_sqlite3(): try: # Connect to MySQL database mysql_engine = create_engine(f'mysql+mysqlconnector://root:{hashed_password1}@localhost/color_group') query = "SELECT * FROM color_numbers" df = pd.read_sql(query, con=mysql_engine) # Connect to SQLite3 database sqlite_conn = sqlite3.connect('your_database_name.db') # Write the data into SQLite3 database df.to_sql('color_numbers', sqlite_conn, if_exists='replace', index=False) # Close the connections #mysql_engine.close() sqlite_conn.close() except Exception as e: la.configure(text=f"{e}")

الأمر فشل عند النقل من SQLite3 إلى MySQL باستخدام الكود التالي.

def convert_sqlite_to_mysql():
try:
# Connect to SQLite3 database
sqlite_conn = sqlite3.connect('your_database_name.db')
# Read data from SQLite3 database
sqlite_df = pd.read_sql("SELECT * FROM color_numbers", con=sqlite_conn)
# Close the SQLite3 connection
sqlite_conn.close()
mysql_engine = create_engine(f'mysql+mysqlconnector://root:{hashed_password1}@localhost/color_group?charset=utf8mb4')
# Write data into MySQL database
sqlite_df.to_sql('color_numbers', con=mysql_engine, if_exists='replace', index=False, chunksize=500)
# Close the MySQL engine connection
# mysql_engine.dispose() # Uncomment this if you want to explicitly close the connection, though it's not strictly necessary
la.configure(text="Data successfully converted to MySQL.")
except Exception as e:
la.configure(text=f"Error: {e}")
print(e)
def convert_sqlite_to_mysql(): try: # Connect to SQLite3 database sqlite_conn = sqlite3.connect('your_database_name.db') # Read data from SQLite3 database sqlite_df = pd.read_sql("SELECT * FROM color_numbers", con=sqlite_conn) # Close the SQLite3 connection sqlite_conn.close() mysql_engine = create_engine(f'mysql+mysqlconnector://root:{hashed_password1}@localhost/color_group?charset=utf8mb4') # Write data into MySQL database sqlite_df.to_sql('color_numbers', con=mysql_engine, if_exists='replace', index=False, chunksize=500) # Close the MySQL engine connection # mysql_engine.dispose() # Uncomment this if you want to explicitly close the connection, though it's not strictly necessary la.configure(text="Data successfully converted to MySQL.") except Exception as e: la.configure(text=f"Error: {e}") print(e)

فيما يلي الخطأ الذي يظهر:

(mysql.connector.errors.DatabaseError) 1366 (HY000): Incorrect string value: '\x89PNG\x0D\x0A...' for column 'image' at row 1
[SQL: INSERlanguage:java
T INTO color_numbers (id, id_name, ingred1, ingred2, ....etc
(mysql.connector.errors.DatabaseError) 1366 (HY000): Incorrect string value: '\x89PNG\x0D\x0A...' for column 'image' at row 1 [SQL: INSERlanguage:java T INTO color_numbers (id, id_name, ingred1, ingred2, ....etc

تعليقات 2

أضف تعليق

يجب تسجيل الدخول حتى تتمكن من إضافة تعليق أو رد.