After reading a lot of tutorials, I found that they are very cumbersome , I have always tried to be concise
It took hours , Finally, a more perfect scheme is sorted out
System :debian9
vim /etc/mysql/mariadb.conf.d/50-server.cnf
Uncomment this line of code in the figure above
import pymysql
from openpyxl import Workbook
def outfile(db,table):
# link database
connection = pymysql.connect(host="",user="root",password="",database=db,charset="utf8",port=3306)
# Create executable sql The cursor of the statement
cursor = connection.cursor()
# Inquire about
sql = 'select * from {};'.format(table)
# perform
count = cursor.execute(sql)
# Get all the results
result = cursor.fetchall()
#print(result[0])
# obtain MySQL Data field name in
fields = cursor.description
# Create a excel
wb = Workbook()
# Create a sheet
sheet = wb.active
# Write the field information
headers = ['A1','B1','C1','D1']
for index,i in enumerate(fields):
sheet[headers[index]] = i[0]
# Get and write data segment information
for index,i in enumerate(result):
sheet.append(list(i))
print(' Saving the ' + str(index) + ' Column information ')
#wb.save(f"/storage/emulated/0/{table}.xlsx")
wb.save(f"C:/Users/Administrator/Desktop/{table}.xls")
db,table = input(" Please enter the database name and table name :").split(',')
outfile(db,table)
All kinds of pits that I met :
1. Local server mysql Of 3306 Port opening
2. Specify the configuration file port for intranet penetration 3306
3.pymysql.connect
Medium password
For the database password instead of root User's password
4. Because I am an intranet penetration pymysql.connect
Add port Parameter refers to the public network provided for intranet penetration ip Corresponding port