简体   繁体   English

与Sqoop不一致的结果

[英]Inconsistent result with Sqoop

Using Sqoop to get data from a MySQL database has inconsistent results whether it is run from the shell or from a python subprocess. 无论是从shell运行还是从python子进程运行,使用Sqoop从MySQL数据库获取数据都会产生不一致的结果。 However, I don't have this issue doing the same thing when accessing an Oracle db, even from the same python session. 但是,在访问Oracle数据库时,即使是在同一个python会话中,我也没有这个问题。

The following runs as expected from the shell: 以下从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 

However the exact same thing does not run from a python subprocess: 但是,完全相同的事情不会从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)

gives the following error: 给出以下错误:

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)

Is there something else I have to do to connect to a MySQL database using Sqoop through a python subprocess? 还有什么我需要通过python子进程使用Sqoop连接MySQL数据库吗?

Figured this out immediately after posting. 发布后立即计算出来。 Perhaps it can help someone else. 也许它可以帮助别人。

I needed to wrap the connection string in "" . 我需要将连接字符串包装在""

The following is a neater python representation. 以下是一个更整洁的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)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM