与Sqoop不一致的结果

问题描述 投票:0回答:1

无论是从shell运行还是从python子进程运行,使用Sqoop从MySQL数据库获取数据都会产生不一致的结果。但是,在访问Oracle数据库时,即使是在同一个python会话中,我也没有这个问题。

以下从shell运行:

export username="user1"

URI="jdbc:mysql://$host/dbname"
URI="${URI}?verifyServerCertificate=false"
URI="${URI}&useSSL=true"
URI="${URI}&requireSSL=false"

## List Tables
sqoop list-tables  \
    --connect ${URI} \
    --username ${username} \
    --password-file password.file 

但是,完全相同的事情不会从python子进程运行:

import subprocess

## List Tables
subprocess.Popen(
    'sqoop list-tables --connect jdbc:mysql://$host/dbname?verifyServerCertificate=false&useSSL=true&requireSSL=false --username user1 --password-file password.file',
shell=True)

给出以下错误:

ERROR [main] manager.CatalogQueryManager (LoggingUtils.java:logAll(43)) - Failed to list tables
java.sql.SQLException: Access denied for user ''@'100.100.100.100' (using password: NO)

还有什么我需要通过python子进程使用Sqoop连接MySQL数据库吗?

python python-2.7 shell hdfs sqoop
1个回答
0
投票

发布后立即计算出来。也许它可以帮助别人。

我需要在""中包装连接字符串。

以下是一个更整洁的python表示。

import subprocess

with open('lbaDevUsername.file', 'r') as f:
    username = f.read()

URI = "jdbc:mysql://$host/dbname"
URI = "{}?verifyServerCertificate=false".format(URI)
URI = "{}&useSSL=true".format(URI)
URI = "{}&requireSSL=false".format(URI)

## List Tables
subprocess.Popen("""
sqoop list-tables \
--connect "{}" \
--username {} \
--password-file password.file 
""".format(URI, username), shell=True)
© www.soinside.com 2019 - 2024. All rights reserved.