0

i want to move from SQLite database M, MySQL database. if i understood correctly, so i can do it with changing the engine:

engine = create_engine('sqlite:///foo.db', echo = False) 

to:

engine = create_engine('mysql://username:password@localhost/ db_name (the database name) ')
Warrior
  • 49
  • 1
  • 5
  • 1
    Yes, maybe it can be done like this. What happened when you tried it? – mkrieger1 May 09 '22 at 20:28
  • i get this error: "ModuleNotFoundError: No module named 'MySQLdb'", i dont know how to handel it. – Warrior May 09 '22 at 20:35
  • Does this answer your question? [ImportError: No module named MySQLdb](https://stackoverflow.com/questions/22252397/importerror-no-module-named-mysqldb) – mkrieger1 May 09 '22 at 20:45

1 Answers1

0
engine = create_engine("mysql+pymysql://user:pass@some_mariadb/dbname?charset=utf8mb4")

or

engine = create_engine("mariadb+pymysql://user:pass@some_mariadb/dbname?charset=utf8mb4")

sqlalchemy-mysql

pip install MySQL-python

On Ubuntu based systems:

apt-get install python-mysqldb

On RHEL/CentOS based systems:

yum install MySQL-python

On Windows: Unofficial Windows Binaries for Python Extension Packages

  • what will do "?charset=utf8mb4"? – Warrior May 13 '22 at 15:10
  • @Warrior A collation is a set of rules that defines how to compare and sort character strings. and its optional but my prefer is read https://docs.sqlalchemy.org/en/14/dialects/mysql.html it'll helpful – Ashkan Goleh Pour May 14 '22 at 03:56