R how to select the database I connect? - mysql

I have both MySQL and MariaDB on my computer, originally I only used MySQL, but recently I have a program using MariaDB. so I used the following script to extract the data
library(RMariaDB)
# export table from mySQL
database <- "movesdb20201105"
mydb = DBI::dbConnect(RMariaDB::MariaDB(), user='moves', password='moves', #actually from RMySQL
dbname = database, host= "localhost")
rs_tmp = DBI::dbSendQuery(mydb, "SELECT * FROM emissionratebyage")
but I look into the connection, it connects to MySQL not MraiaDB, how can I fix this?
Thanks

MariaDB is the successor of MySQL. Maybe just a wrong label?
Also try unloading the MySQL library.

Related

How to connect to a remote database server using Python?

I am trying to connect to a remote database server that is installed on CentOS 7 in VMware from windows using python, but I am unable to connect to it. I am using mysql.connector to access the database.Please help me solve the problem.
import mysql.connector
mydb = mysql.connector.connect(host="192.168.136.129", user="root", passwd="root", database="test", port=3306)
mycr = mydb.cursor()
mycr.execute("CREATE TABLE cat (name VARCHAR(25));")
Don't use root user there might be some permission issue.
Try creating a new user and access it.

Use Workbench for SQL database saved on Local PC ( Desktop)

I'm struggling to use the Workbench software for a database saved on my desktop. I do normally work with SQL server online but in our case the client sent us directly the local file.
Do you know how if it is possible?
Thanks
NC
create a new database
create database database_name
import the '.sql' file provided to you into it
mysql -u username -p database_name < path/to/database_file.sql
the database will be visible then.
you can use the workbench gui instead. ensure you have created a new database first then import.

how to connect R to mysql? do we need to install mysql on local host separately?

How to connect R to mysql? Do we need to install mysql on local host separately? When I try to connect it says
"Error in .local(drv, ...) : Failed to connect to database: Error:
Can't connect to MySQL server on 'localhost' (0)".
What does it mean? I am using R on windows by the way.
You don't show your R code in the post so it is hard to "fix" what might be wrong. Instead I'll just show you some code that works.
To access a mysql database you can use the RMySQL package. For this to work your mysql server must accept remote requests and you must specify the
address (for example the IP address where the server is running)
the username
the password
the database name
Your mysql server should be set up to accept non-local requests unless it's already running locally on the machine where you run R.
library(RMySQL)
mydb = dbConnect(MySQL(), user="username", password="PASSword",
dbname="dbname", host="192.168.13.15")
then you can submit queries in standard SQL language.
indata <- dbGetQuery(mydb, "select * from students")
You do not need a sql client for the R code to work, but if you cannot get it to run within R then you should try to see if you can log onto the server using a manual client. If that is not possible your server is not setup to allow the logins.

Why am I getting unicode values back from SQLTables?

I'm trying to make a connection via ODBC from a Python program running on Ubuntu to a MySQL box on the same machine. (I'm using ODBC instead of DB-API because I'm going to be using different database engines and I want a consistent way of getting to the system catalog, like SQLTables.)
But when I connect to my MySQL database and run SQLTables, I get this for my first row:
(u'\U0067007a\U005f0061\U00690062\U006c006c\U006e0069\U005f0067\U00750061\U006f0074\U0061006d\U00690074\U006e006f\U0063005f\U00630063',
u'', u'\U00750061\U00680074\U0067005f\U006f0072\U00700075',
u'\U00410054\U004c0042', u'')
Clearly these are unicode values, but they look like they are for really high codepoints, and sure enough, I can't encode them into ASCII. All my table names should be ASCII.
Is there some setting that I'm missing or have wrong that is causing this?
my odbc.ini is:
[ODBC Data Sources]
mu = MySQL
[mu]
Description = MySQL Database Test
Driver = MySQL
Server = localhost
Database = ccc2
Port = 3306
My odbcinst.ini is
[MySQL]
Description = ODBC for MySQL
Driver = /usr/lib/odbc/libmyodbc.so
FileUsage = 1
Found it. I needed to specify Charset=UTF8 in my connection paramters, like so:
[ODBC Data Sources]
mu = MySQL
[mu]
Description = MySQL Database Test
Driver = MySQL
Server = localhost
Database = ccc2
Port = 3306
Charset = UTF8

import the data to db in mysql

I have sql data in .sql format. and I need to import it to the MySql database. What are all the steps should I take.
Thanks in advance.
Your .sql file only contains a lot of SQL queries.
The simplest way to import your file is to execute those SQL queries, with the mysql command-line tool :
mysql --user=USER --password=PASSWORD --host=HOST DB_NAME < your_sql_file.sql
This will send all the content of your_sql_file.sql to the mysql program, which will execute it -- and, so, import your data.
Of course, you'll have to replace the upper-case USER, PASSWORD, HOST, and DB_NAME with your real connection informations.
Are you using any software to connect with mysql? If yes, then there should be opion for importing data. Try that.