12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- #!/usr/bin/env python3
- # -*- coding: utf-8 -*-
- import pymysql
- # MySQL连接配置
- host = '47.98.212.223'
- user = '6636'
- password = 'Mt7DiMvk7W_2'
- database = 'db-tm'
- # 要查找的字符串
- search_string = 'timichat.net'
- # 要写入的txt文件路径
- output_file = 'output10.txt'
- # 跟踪已写入的字符串
- written_strings = set()
- # 连接到MySQL数据库
- connection = pymysql.connect(
- host=host, user=user, password=password, database=database)
- try:
- with connection.cursor() as cursor:
- # 获取所有表名
- cursor.execute("SHOW TABLES")
- tables = cursor.fetchall()
- # 遍历每个表
- for table in tables:
- table_name = table[0]
- # if table_name == "tb_release_config":
- print("123")
- # 查询表中所有字段
- cursor.execute(f"SELECT * FROM `{table_name}`")
- rows = cursor.fetchall()
- # 遍历每一行数据
- for row in rows:
- for value in row:
- if isinstance(value, str) and search_string in value and len(value) < 150000 and value not in written_strings:
- # 写入符合条件的字符串到txt文件
- with open(output_file, 'a') as file:
- file.write(value + '\n')
- # 将写入的字符串添加到集合中
- written_strings.add(value)
- print("查询完成并写入到txt文件。")
- finally:
- connection.close()
|