77 lines
2.5 KiB
Plaintext
77 lines
2.5 KiB
Plaintext
{
|
|
"cells": [
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 1,
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"name": "stderr",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"c:\\Users\\admin\\.conda\\envs\\F6processing\\lib\\site-packages\\numpy\\_distributor_init.py:30: UserWarning: loaded more than 1 DLL from .libs:\n",
|
|
"c:\\Users\\admin\\.conda\\envs\\F6processing\\lib\\site-packages\\numpy\\.libs\\libopenblas.EL2C6PLE4ZYW3ECEVIV3OXXGRN2NRFM2.gfortran-win_amd64.dll\n",
|
|
"c:\\Users\\admin\\.conda\\envs\\F6processing\\lib\\site-packages\\numpy\\.libs\\libopenblas64__v0.3.21-gcc_10_3_0.dll\n",
|
|
" warnings.warn(\"loaded more than 1 DLL from .libs:\"\n",
|
|
"<ipython-input-1-f4a815216608>:26: UserWarning: Pandas requires version '1.4.3' or newer of 'xlsxwriter' (version '1.3.8' currently installed).\n",
|
|
" rpt_customized_ht_real_sales_detail.to_excel(r'C:\\Users\\admin\\Desktop\\rpt_customized_ht_real_sales_detail.xlsx')\n"
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"import mysql.connector\n",
|
|
"import pandas as pd\n",
|
|
"# 创建连接\n",
|
|
"cnx = mysql.connector.connect(\n",
|
|
" host=\"rm-uf6r230vbtxf5gdz63o.mysql.rds.aliyuncs.com\",\n",
|
|
" user=\"ro_yida\",\n",
|
|
" password=\"j39+2t@rR$F&71\",\n",
|
|
" database=\"f6custom\"\n",
|
|
")\n",
|
|
"\n",
|
|
"# 创建游标\n",
|
|
"cursor = cnx.cursor()\n",
|
|
"\n",
|
|
"# 执行SQL查询\n",
|
|
"sql = \"SELECT * FROM rpt_customized_ht_real_sales_detail WHERE finish_day = '2023-11-01'\"\n",
|
|
"cursor.execute(sql)\n",
|
|
"# 获取结果集的每一行\n",
|
|
"rows = cursor.fetchall()\n",
|
|
"# 获取所有字段名\n",
|
|
"all_fields = cursor.description\n",
|
|
"#执行结果转化为dataframe\n",
|
|
"col = []\n",
|
|
"for i in all_fields:\n",
|
|
" col.append(i[0])\n",
|
|
"rpt_customized_ht_real_sales_detail = pd.DataFrame(list(rows),columns=col)\n",
|
|
"rpt_customized_ht_real_sales_detail.to_excel(r'C:\\Users\\admin\\Desktop\\rpt_customized_ht_real_sales_detail.xlsx')\n",
|
|
"\n",
|
|
"# 关闭游标和连接\n",
|
|
"cursor.close()\n",
|
|
"cnx.close()"
|
|
]
|
|
}
|
|
],
|
|
"metadata": {
|
|
"kernelspec": {
|
|
"display_name": "F6processing",
|
|
"language": "python",
|
|
"name": "python3"
|
|
},
|
|
"language_info": {
|
|
"codemirror_mode": {
|
|
"name": "ipython",
|
|
"version": 3
|
|
},
|
|
"file_extension": ".py",
|
|
"mimetype": "text/x-python",
|
|
"name": "python",
|
|
"nbconvert_exporter": "python",
|
|
"pygments_lexer": "ipython3",
|
|
"version": "3.9.4"
|
|
}
|
|
},
|
|
"nbformat": 4,
|
|
"nbformat_minor": 2
|
|
}
|