This script helps to create a MySQL database, add tables, and columns interactively. It is designed to be used with the MySQL connector for Python (mysql-connector-python).
- Python 3.x
- The MySQL connector for Python (
mysql-connector-python)
You can install the MySQL connector using pip:
pip install mysql-connector-python-
Running the script: Run the script using Python:
python main_fr.py python main.py
Depending on your preference, choose
main.pyfor English andmain_fr.pyfor French. -
Database Connection: The script will prompt you to enter the connection information for the MySQL database (username, password, host).
-
List Databases: You will have the option to list existing databases on the MySQL server.
-
Create Database: The script will prompt you to enter the name of the database to create. If the database already exists, it will be used.
-
List Tables: You will have the option to list existing tables in the selected database.
-
Create Table: The script will prompt you to enter the name of the table to create. An
idcolumn with auto-increment will be added as the primary key. -
Add Columns: You can add as many columns as you want to the table. The script supports the following column types:
VARCHAR: You will be prompted to enter the length of the column.BOOLEAN: You will be prompted to enter the default value of the column.INT,FLOAT,TIMESTAMP: These types are accepted directly without additional input.(The program does not support more values to avoid unnecessary errors.)
-
Closing the connection: Once all operations are completed, the connection to the database will be closed automatically.
Do you want to list the databases? (y/n): y
# List of databases:
> database1
> database2
Enter the name of the database: testdb
# Database created successfully!
Do you want to list the tables? (y/n): y
# List of tables:
> table1
> table2
Enter the name of the table: users
# Table created successfully!
# Column id added with auto-increment as primary key
Do you want to add another column? (y/n): y
Enter the name of the column: name
Enter the type of the column (VARCHAR, BOOLEAN, INT, FLOAT, TIMESTAMP): VARCHAR
Enter the length of the column: 255
# Column name:VARCHAR(255) created successfully!
Do you want to add another column? (y/n): n
# Connection to the database closed successfully!- This script will overwrite any existing database with the same name. Make sure to back up your data before running this script.
- The script is designed to be used in a development environment. Use it with caution in a production environment.
- NEY_Twix
This project is licensed under the MIT License. See the LICENSE file for more details.