GithubHelp home page GithubHelp logo

sqlite_to_mysql's Introduction

Convert SQLite Tables to MySQL

This script converts all the tables from a SQLite database to a MySQL database.

To run this project, you will need to have Python and pip installed on your system. Once you have these prerequisites, you can install the dependencies by running the following command in the root directory of the project:

pip install -r requirements.txt

This will install all the packages listed in your requirements.txt file. Once the dependencies are installed, you should be able to run your code successfully.

The script takes the following command-line arguments:

--sqlite-db: the path to the SQLite database file
--mysql-user: the MySQL username
--mysql-password: the MySQL password
--mysql-host: the MySQL host
--mysql-port: the MySQL port, default 3306
--mysql-database: the MySQL database name

The script uses SQLAlchemy, an open-source SQL toolkit, to connect to both the SQLite and MySQL databases. It then:

  • Gets the list of tables in the SQLite database
  • Iterates through the tables in the SQLite database
  • Drops the MySQL table if it already exists
  • Loads the data for the current SQLite table into a pandas DataFrame
  • Removes the "index" column from the DataFrame
  • Generates the CREATE TABLE statement for the MySQL table using pandas
  • Escapes the table and column names in the CREATE TABLE statement
  • Executes the CREATE TABLE statement in the MySQL database
  • Writes the data from the DataFrame to the MySQL table using the to_sql method

To use this script, simply provide the necessary command-line arguments and run it using Python. You can use the following command:

python sqlite_to_mysql.py --sqlite-db /path/to/database/new_database.db --mysql-user username --mysql-password password --mysql-host host --mysql-port port --mysql-database database

Make sure to replace the placeholders /path/to/database/new_database.db, username, password, host, port and database with the actual values for your SQLite database file, MySQL username, MySQL password, MySQL host, and MySQL database name, respectively.

Before running the script, make sure that the MySQL database already exists. You can create the database using the MySQL command-line client or a MySQL management tool like PHPMyAdmin.

sqlite_to_mysql's People

Contributors

imam-db avatar

Stargazers

Roman avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.