Skip to content

coder-abhishektiwari/sql-editor-python

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 

Repository files navigation


SQL Editor - Python-Based SQL Command Line Interface

A Python-based SQL editor that allows users to interact with MySQL databases through a command-line interface. This program helps users perform various SQL operations such as creating databases, tables, inserting data, querying, and more—all via an interactive menu.

Features

  • Login to MySQL server using username and password
  • View existing databases and select a database for operations
  • Perform database operations: Create, Drop, and Use databases
  • Table management: Create, Show, Drop tables, Insert, Update, and Delete records
  • Execute complex SQL queries like conditional SELECT, JOINs, GROUP BY, and more
  • Custom SQL query execution for dynamic queries
  • Error handling: Prompts users when incorrect credentials are entered
  • Secure login with password input hidden (if preferred)

Setup and Installation

Prerequisites

  • Python 3.x installed on your system
  • MySQL installed and running on your system
  • mysql-connector-python library installed to interact with MySQL from Python

Install MySQL Connector

Run the following command to install the mysql-connector-python package:

pip install mysql-connector-python

MySQL Setup

Make sure you have MySQL installed on your system and have a running MySQL server. You can install MySQL from here.

Project Setup

  1. Clone this repository:

    git clone https://github.com/yourusername/sql-editor-python.git
  2. Navigate to the project directory:

    cd sql-editor-python
  3. Run the script:

    python -m pip install requirements.txt

Usage

  1. Login: When you run the script, it will prompt you to enter the MySQL username and password.
  2. Database Selection: After successful login, the existing databases are displayed, and you can select one for further operations.
  3. Task Selection: The editor presents a list of SQL tasks that can be performed such as creating tables, inserting data, updating, deleting, etc.
  4. Custom Queries: You can also execute custom SQL queries directly via the "Run a custom SQL query" option.
  5. Exit: To exit the SQL Editor, select the Exit option from the menu.

Menu Options

  • Show Tables: Display all tables within the selected database.
  • Create Table: Create a new table by providing column definitions.
  • Insert Data: Insert data into an existing table by specifying column names and values.
  • Update Data: Update records in a table using the SET clause.
  • Delete Data: Remove specific records from a table based on conditions.
  • Drop Table: Permanently delete a table from the database.
  • Select Data: Perform SELECT queries with optional conditions.
  • Group By Queries: Run GROUP BY queries to group records.
  • Join Tables: Perform JOIN queries to combine rows from two or more tables.
  • Run Custom SQL Queries: Execute any valid SQL command directly from the command line.
  • Exit: Exit the SQL editor safely.

Example Usage

WELCOME TO SQL EDITOR
Enter username: root
Enter password: ********
Logged in successfully!

Existing databases:
1. test_db
2. sample_db
3. my_database

Select a database by number: 1
Using database 'test_db'.

Choose an option:
  1. Show tables
  2. Create a new table
  3. Insert data into a table
  4. Update data in a table
  5. Delete data from a table
  6. Drop a table
  7. Select data (conditional query)
  8. Group by query
  9. Join tables
  10. Run a custom SQL query
  11. Exit

Choose any from this: 1
Showing tables in the database...

License

This project is licensed under the MIT License. See the LICENSE file for details.


About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages