MCPcopy Create free account
hub / github.com/aaPanel/BaoTa / database_menu

Method database_menu

script/btcli.py:1494–1583  ·  view source on GitHub ↗

数据库管理菜单

(self)

Source from the content-addressed store, hash-verified

1492 print(Colors.error("无效的选择"))
1493
1494 def database_menu(self):
1495 """数据库管理菜单"""
1496 while True:
1497 print("\n" + "-"*50)
1498 print(Colors.info(" 数据库管理"))
1499 print("-"*50)
1500 print(" 1. 显示数据库列表")
1501 print(" 2. 添加数据库")
1502 print(" 3. 删除数据库")
1503 print(" 4. 获取数据库密码")
1504 print(" 5. 获取root密码")
1505 print(" 0. 返回上级")
1506 print("-"*50)
1507
1508 choice = input("\n请选择操作 [0-3]: ").strip()
1509
1510 if choice == '1':
1511 self.db_mgr.list_databases()
1512 elif choice == '2':
1513 mysql_status = self.db_mgr.get_mysql_status()
1514 if not mysql_status:
1515 print(Colors.error("MySQL服务未启动,请先登录面板开启MySQL服务后再执行操作"))
1516 print(Colors.error("或手动执行 /etc/init.d/mysqld start 启动后再尝试"))
1517 continue
1518 print(Colors.info("\n=== 添加数据库 ==="))
1519 db_name = input("数据库名 (必填): ").strip()
1520 if not db_name:
1521 print(Colors.error("数据库名不能为空"))
1522 continue
1523
1524 db_user = input(f"数据库用户名 (默认: {db_name}): ").strip() or db_name
1525
1526 default_password = public.GetRandomString(16)
1527 password = input(f"数据库密码 (留空自动生成: {default_password}) : ").strip() or default_password
1528
1529 print("\n字符编码选择:")
1530 print(" 1. utf8mb4 (推荐,支持emoji)")
1531 print(" 2. utf8")
1532 print(" 3. gbk")
1533 print(" 4. latin1")
1534 coding_choice = input("编码 (默认: 1): ").strip() or "1"
1535 codeing_map = {"1": "utf8mb4", "2": "utf8", "3": "gbk", "4": "latin1"}
1536 codeing = codeing_map.get(coding_choice, "utf8mb4")
1537
1538 address = input("访问权限 (默认: 127.0.0.1, 本地访问): ").strip() or "127.0.0.1"
1539 ps = input("备注 (默认: 数据库名): ").strip() or db_name
1540
1541 # 构造参数
1542 kwargs = {
1543 'db_user': db_user,
1544 'codeing': codeing,
1545 'address': address,
1546 'ps': ps,
1547 }
1548 print(db_name, password, kwargs)
1549 self.db_mgr.add_database(db_name, password, **kwargs)
1550
1551 elif choice == '3':

Callers 1

show_main_menuMethod · 0.95

Calls 10

get_database_passwordMethod · 0.80
infoMethod · 0.45
list_databasesMethod · 0.45
get_mysql_statusMethod · 0.45
errorMethod · 0.45
getMethod · 0.45
add_databaseMethod · 0.45
delete_databaseMethod · 0.45
getKeyMethod · 0.45
successMethod · 0.45

Tested by

no test coverage detected