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.
- 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)
- 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
Run the following command to install the mysql-connector-python
package:
pip install mysql-connector-python
Make sure you have MySQL installed on your system and have a running MySQL server. You can install MySQL from here.
-
Clone this repository:
git clone https://github.com/yourusername/sql-editor-python.git
-
Navigate to the project directory:
cd sql-editor-python
-
Run the script:
python -m pip install requirements.txt
- Login: When you run the script, it will prompt you to enter the MySQL username and password.
- Database Selection: After successful login, the existing databases are displayed, and you can select one for further operations.
- Task Selection: The editor presents a list of SQL tasks that can be performed such as creating tables, inserting data, updating, deleting, etc.
- Custom Queries: You can also execute custom SQL queries directly via the "Run a custom SQL query" option.
- Exit: To exit the SQL Editor, select the Exit option from the menu.
- 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.
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...
This project is licensed under the MIT License. See the LICENSE file for details.