python 3 ,ssh tunnel with sql query using panda not working
up vote
0
down vote
favorite
I have a problem getting result from mysql database using ssh connection.
The sql statement is correct but why dont i have any data in it ?
from sshtunnel import SSHTunnelForwarder
import MySQLdb as db
import pandas as pd
from pandas import DataFrame
# ssh variabler
host = "192.168.99.101"
localhost = "127.0.0.1"
ssh_username = "user"
ssh_password = "password"
ssh_private_key = '/path/to/key.pem'
# databas variabler
user = "user"
password = "password"
database = "database"
def query(q):
with SSHTunnelForwarder(
(host, 22),
ssh_username=ssh_username,
ssh_password = ssh_password,
remote_bind_address=(localhost, 3306)
) as server:
conn = db.connect(host=localhost,
port=server.local_bind_port,
user=user,
passwd=password,
db=database)
return pd.read_sql_query(q, conn)
begin ="""2018-01-03"""
end = """2018-01-04"""
#run sql query
sql = """select collection_type,sum(order_amount) from pz_orders where order_date between {} and {} and print = 'y' group by collection_type""".format(början,slut)
df = query(sql)
print(df)
What i get from return from print statement, It should return some numbers.
Empty DataFrame
Columns: [collection_type, sum(order_amount)]
Index:
python mysql pandas
add a comment |
up vote
0
down vote
favorite
I have a problem getting result from mysql database using ssh connection.
The sql statement is correct but why dont i have any data in it ?
from sshtunnel import SSHTunnelForwarder
import MySQLdb as db
import pandas as pd
from pandas import DataFrame
# ssh variabler
host = "192.168.99.101"
localhost = "127.0.0.1"
ssh_username = "user"
ssh_password = "password"
ssh_private_key = '/path/to/key.pem'
# databas variabler
user = "user"
password = "password"
database = "database"
def query(q):
with SSHTunnelForwarder(
(host, 22),
ssh_username=ssh_username,
ssh_password = ssh_password,
remote_bind_address=(localhost, 3306)
) as server:
conn = db.connect(host=localhost,
port=server.local_bind_port,
user=user,
passwd=password,
db=database)
return pd.read_sql_query(q, conn)
begin ="""2018-01-03"""
end = """2018-01-04"""
#run sql query
sql = """select collection_type,sum(order_amount) from pz_orders where order_date between {} and {} and print = 'y' group by collection_type""".format(början,slut)
df = query(sql)
print(df)
What i get from return from print statement, It should return some numbers.
Empty DataFrame
Columns: [collection_type, sum(order_amount)]
Index:
python mysql pandas
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I have a problem getting result from mysql database using ssh connection.
The sql statement is correct but why dont i have any data in it ?
from sshtunnel import SSHTunnelForwarder
import MySQLdb as db
import pandas as pd
from pandas import DataFrame
# ssh variabler
host = "192.168.99.101"
localhost = "127.0.0.1"
ssh_username = "user"
ssh_password = "password"
ssh_private_key = '/path/to/key.pem'
# databas variabler
user = "user"
password = "password"
database = "database"
def query(q):
with SSHTunnelForwarder(
(host, 22),
ssh_username=ssh_username,
ssh_password = ssh_password,
remote_bind_address=(localhost, 3306)
) as server:
conn = db.connect(host=localhost,
port=server.local_bind_port,
user=user,
passwd=password,
db=database)
return pd.read_sql_query(q, conn)
begin ="""2018-01-03"""
end = """2018-01-04"""
#run sql query
sql = """select collection_type,sum(order_amount) from pz_orders where order_date between {} and {} and print = 'y' group by collection_type""".format(början,slut)
df = query(sql)
print(df)
What i get from return from print statement, It should return some numbers.
Empty DataFrame
Columns: [collection_type, sum(order_amount)]
Index:
python mysql pandas
I have a problem getting result from mysql database using ssh connection.
The sql statement is correct but why dont i have any data in it ?
from sshtunnel import SSHTunnelForwarder
import MySQLdb as db
import pandas as pd
from pandas import DataFrame
# ssh variabler
host = "192.168.99.101"
localhost = "127.0.0.1"
ssh_username = "user"
ssh_password = "password"
ssh_private_key = '/path/to/key.pem'
# databas variabler
user = "user"
password = "password"
database = "database"
def query(q):
with SSHTunnelForwarder(
(host, 22),
ssh_username=ssh_username,
ssh_password = ssh_password,
remote_bind_address=(localhost, 3306)
) as server:
conn = db.connect(host=localhost,
port=server.local_bind_port,
user=user,
passwd=password,
db=database)
return pd.read_sql_query(q, conn)
begin ="""2018-01-03"""
end = """2018-01-04"""
#run sql query
sql = """select collection_type,sum(order_amount) from pz_orders where order_date between {} and {} and print = 'y' group by collection_type""".format(början,slut)
df = query(sql)
print(df)
What i get from return from print statement, It should return some numbers.
Empty DataFrame
Columns: [collection_type, sum(order_amount)]
Index:
python mysql pandas
python mysql pandas
asked Nov 19 at 11:48
landy
13
13
add a comment |
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53374005%2fpython-3-ssh-tunnel-with-sql-query-using-panda-not-working%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown