1. 头文件 import psycopg2 2. 数据库连接 2.1. 本地数据库连接 connect = sqlite3.connect(file_name) connect.load_extension('mod_spatialite') cursor = connect.cursor() 2.2. 远程数据库连接 connect = psycopg2.connect(database=database, user=user, password=password, host=host, port=port) cursor = connect.cursor() 3. 执行命令 cursor.execute(sql) result = cursor.fetchall() 4. 获取所有表名 4.1. 本地数据库 sql = "select name from sqlite_master where type='table' order by name" 4.2. 远程数据库 sql = "SELECT table_name FROM information_schema.tables"