Linux上用于Json数据处理并导入Mysql的几个有用Python脚本

本文介绍了如何在Linux环境中使用Python处理Json数据,并将其导入到MySQL数据库。首先展示了目录结构和MySQL-python库的安装步骤,然后提供了一系列Python脚本,包括读取目录下特定文件、过滤并导入Json数据到数据库。这些脚本涉及Json数据的解析、数据库连接和数据插入操作。
摘要由CSDN通过智能技术生成
1、环境目录结构
[root@localhost python_dir]# pwd
/root/python_dir
[root@localhost python_dir]# ls -lGR
.:
total 5148
-rw-r--r--. 1 root     604 Dec 17 11:24 db.py
-rw-r--r--. 1 root     886 Dec 17 11:54 db.pyc
-rw-r--r--. 1 root     137 Dec 18 03:26 dirfilefilter_print.py
-rwxr-xr-x. 1 root    1123 Dec 18 06:54 json2mysql_python_arrayastext.py
-rwxr-xr-x. 1 root     925 Dec 18 03:39 json2mysql_python_dirfilefilter.py
-rwxrwxrwx. 1 root     939 Dec 18 02:21 json2mysql_python_recordasarray.py
-rw-r--r--. 1 root 2100077 Dec 18 01:54 json_array.json
-rw-r--r--. 1 root 1998167 Dec 18 02:01 json_array.txt
-rw-r--r--. 1 root    5150 Dec 18 06:05 test1.txt
-rw-r--r--. 1 root    7708 Dec 18 02:39 test2.txt
-rw-r--r--. 1 root    7708 Dec 17 11:11 test3.txt
-rw-r--r--. 1 root 1120389 Dec 17 13:22 test_big.json

2、MySQL-python的安装
安装过程:
[root@Master ~]# yum install MySQL-python
Loaded plugins: refresh-packagekit, security
base                                                                                                                                                                                                                                                   | 3.7 kB     00:00     
epel                                                                                                                                                                                                                                                   | 4.3 kB     00:00     
epel/primary_db                                                                                                                                                                                                                                        | 5.7 MB     00:05     
extras                                                                                                                                                                                                                                                 | 3.4 kB     00:00     
updates                                                                                                                                                                                                                                                | 3.4 kB     00:00     
updates/primary_db                                                                                                                                                                                                                                     | 3.2 MB     00:03     
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package MySQL-python.x86_64 0:1.2.3-0.3.c1.1.el6 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

==============================================================================================================================================================================================================================================================================
 Package                                                            Arch                                                         Version                                                                     Repository                                                  Size
==============================================================================================================================================================================================================================================================================
Installing:
 MySQL-python                                                       x86_64                                                       1.2.3-0.3.c1.1.el6                                                          base                                                        86 k

Transaction Summary
==============================================================================================================================================================================================================================================================================
Install       1 Package(s)

Total download size: 86 k
Installed size: 246 k
Is this ok [y/N]: y
Downloading Packages:
MySQL-python-1.2.3-0.3.c1.1.el6.x86_64.rpm                                                                                                                                                                                                             |  86 kB     00:00     
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
  Installing : MySQL-python-1.2.3-0.3.c1.1.el6.x86_64                                                                                                                                                                                                                     1/1 
Unable to connect to dbus
  Verifying  : MySQL-python-1.2.3-0.3.c1.1.el6.x86_64                                                                                                                                                                  
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值