MySQL Operational Error - mysql

I am trying to upload data into a MySQL database, but I am having trouble doing so. The error I receive when I try to run my code is 2003, Can't connect to MySQL server on 'db_host' ([Errno 11001] getaddrinfo failed). Does anyone know what this error means or how to fix it? I have included my code below.
import pymysql
import time
import good_morning as gm
DB_HOST = 'db_host'
DB_USER = 'db_user'
DB_PASS = 'db_pass'
DB_NAME = 'db_name'
conn = pymysql.connect(host=DB_HOST, user=DB_USER, passwd=DB_PASS, db=DB_NAME)
kr = gm.KeyRatiosDownloader()
fd = gm.FinancialsDownloader()
kr_frames = kr.download('AAPL', conn)
fd_frames = fd.FinancialsDownloader()

Related

How to import .DB file by connecting MYSQL in R

I have a .db file like "sakila"
library(RMySQL)
library(DBI)
mysqlconnection = dbConnect(MySQL(), user = 'root', password = '123456', dbname = 'sakila',host = 'localhost')
dbListTables(mysqlconnection)
It reports the error:
Error in .local(drv, ...) :
Failed to connect to database: Error: Unknown database 'sakila.db'
How do I fix it?
I hope to import the .db file in Mysql by using R.

Why do I get TCP/IP error when trying to create DB in my Lambda?

So I'm trying to deploy my Django project using lambda, with zappa. I'm using MySQL for DB engine. Now after doing some research, I realized that I needed to create a custom Django command to create DB, since I'm using MySQL. So I created crate_db command, zappa updated, then ran zappa manage dev create_db. Then I got this error: 2004 (HY000): Can't create TCP/IP socket (97)
below is my create_db.py file, for your information.
import sys
import logging
import mysql.connector
import os
from django.core.management.base import BaseCommand, CommandError
from django.conf import settings
rds_host = os.environ.get("MY HOST")
db_name = os.environ.get("")
user_name = os.environ.get("MY USERNAME")
password = os.environ.get("MY PASSWORD")
port = os.environ.get("3306")
logger = logging.getLogger()
logger.setLevel(logging.INFO)
class Command(BaseCommand):
help = 'Creates the initial database'
def handle(self, *args, **options):
print('Starting db creation')
try:
db = mysql.connector.connect(host=rds_host, user=user_name,
password=password, db="mysql", connect_timeout=10)
c = db.cursor()
print("connected to db server")
c.execute("""CREATE DATABASE bookcake_db;""")
c.execute("""GRANT ALL ON bookcake_db.* TO 'ryan'#'%'""")
c.close()
print("closed db connection")
except mysql.connector.Error as err:
logger.error("Something went wrong: {}".format(err))
sys.exit()
Any ideas? Thanks.

Error when connecting to MySQL database using mysql.connector

I am trying to connect to a MySQL database using mysql.connector:
import mysql.connector
mydb = mysql.connector.connect(
host="localhost",
user="user",
password="password",
database="database"
)
mycursor = mydb.cursor()
mycursor.execute("SELECT * FROM table")
myresult = mycursor.fetchone()
print(myresult)
I get this error message:
errno=2003, values=(self.get_address(), _strioerror(err)))
mysql.connector.errors.InterfaceError: 2003: Can't connect to MySQL server on'localhost:3306'(10061 No connection could be made because the target machine actively refused it)
Does this mean that there something wrong with the database credentials?

Is there any way that I can connect to my live database server and insert data into it?

I am facing problem while inserting data in my live database server. My current connection code is:
import pymysql
host="192.224.256.***"
user_name="user"
password= "pass"
database="checkDatabase"
try:
connection = pymysql.connect(host, user_name, password, database)
print("connection established")
except:
print("connection failed")
result is :: connection failed..
Is there any way that I can connect to my live database server and insert data into it?
You should connect like this :
connection = pymysql.connect(host='localhost', port=3306, user='user', passwd='password', db='database')
Or like this :
db_name = "database"
db = pymysql.connect("localhost", "user", "password", "db_name")
Eather way you need the quotes so you cant just add strings the way you did it.

AWS RDS: mysql_exceptions.OperationalError: (2003, "Can't connect to MySQL server on 'databasetest.us-east-1.rds.amazonaws.com' (110)")

I have this code below to connect to a rds instance.
But Im having this error:
_mysql_exceptions.OperationalError: (2003, "Can't connect to MySQL server on 'databaseTest.us-east-1.rds.amazonaws.com' (110)")
Do you see anything wrong with the code?
import boto.rds
import MySQLdb
instanceID = "databaseTest"
username = "root"
password = "pass"
getDBEndpoint = conn.get_all_dbinstances(instance_id=instanceID)[0].endpoint
dbEndpoint = getDBEndpoint[0]
conn = MySQLdb.connect(host=dbEndpoint,user=username,passwd=password, db = dbName, port = 3306)
I created the db instance like this:
db = conn.create_dbinstance(instanceID,dbSize,instanceType, username, password, port = instancePort, engine=dbEngine, db_name = dbName)