How to import .DB file by connecting MYSQL in R - mysql

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.

Related

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?

How to connect to sql database located locally in r shiny

I am trying to connect to SQL database located in the same directory as in my app.R file but I get the following error if I try to connect.
con <- dbConnect(RMySQL::MySQL(), dbname = "super_data")
Error in .local(drv, ...) :
Failed to connect to database: Error: Can't connect to MySQL server on 'localhost' (0)
mydb = dbConnect(MySQL(), user='root', password='', dbname='super_data.sql', host='localhost')
Error in .local(drv, ...) :
Failed to connect to database: Error: Can't connect to MySQL server on 'localhost' (0)
Try with the following code:
conn <- RMySQL::dbConnect(RMySQL::MySQL(),
user = "root",
password = "mypassword",
dbname = "mydatabase",
host = "127.0.0.1", # Instead of localhost
port = 3306) # Default MySQL port
Hope this can help

MySQL Operational Error

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()

RMySQL does not work as part of a script

When I run
library(RMySQL)
mydb = dbConnect(MySQL(), user = "XX", password = "XX", dbname = "XX", host = "XX")
on the R console it works,
however when I put save it as a yy.R file and run it as R CMD BATCH yy.R, or as source("yy.R") it says
Error in mysqlNewConnection(drv, ...) :
RS-DBI driver: (Failed to connect to database: Error: Can't connect to MySQL server on 'XX' (111)
)
Calls: dbConnect -> dbConnect -> mysqlNewConnection -> .Call
Execution halted
could I check if RMySQL only runs on the console? Thanks!
Perhaps you can specify the driver with RMySQL::MySQL(), this works for me in scripts.

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)