I’ve looked around but can not find a julia package that will let me pull an encrypted password which is stored in my linux gnome keyring. I use it for keeping scripts that connect to SQL servers, anonymous because I have to distribute them to several group members.
In R, the “keyringer” package has a “decrypt_gk_pw” function that can pull a stored password right from the gnome keyring. Is there anything analogous in Julia or would we have to build it?
https://rdrr.io/cran/keyringr/src/R/decrypt_gk_pw.R
invisible(system(paste("secret-tool lookup ", key_value_pairs, sep=""), intern=TRUE))
so:
> secret-tool store --label=mylabel db mydb user user1
Password:
> julia -e 'read(`secret-tool lookup db mydb user user1`, String) |> println'
blah
if you need it to go to your clipboard, you can replace the println with clipboard
This is my final solution, and it does work to hide the password, but anyone who knows Julia can simply remove the semicolon at the end, and it will appear, so not exactly what I wanted. I have to circulate this code to colleagues and others. The syntax for the ODBC connection is very specific with respect to “,” and “;” . Thx. J
con3 = ODBC.Connection(
"Driver=ODBC Driver 17 for SQL Server;
SERVER=66.66.66.66;
DATABASE=dbname;
UID=username;
PWD=$(read(`secret-tool lookup word1 word2 word3 word4`,String))");
Related
I am having a lot of problems with the coding of columns using sqldf and Rpostgree (when I do querys in datasets that contain letters of the Spanish language it converts them into strange characters), for this reason I want to move to MYSQL, but I find its documentation too confusing To use it with sqldf, I need to know how I can enter the parameters of my database to use sqldf with my previously configured database.
Example for Postgree:
options (sqldf.RPostgreSQL.user = "postgres",
sqldf.RPostgreSQL.password = "test",
sqldf.RPostgreSQL.dbname = "postgres",
sqldf.RPostgreSQL.host = "localhost",
sqldf.RPostgreSQL.port = 5432)
Someone knows how I can check the options of a specific package, in this case RMySQL.
Finally, after at least 3 hours of tortuous reading in multiple articles I could find a way to configure the mysql database to be used by sqldf and without dying in the attempt, I must warn you that this is the only way to work, since if you create a connection using RMySQL and then use the connection as a parameter in sqldf you will get multiple connection errors.
Create a my.cnf file
Here is everything necessary for it to work, it must be rs-dbi because this is the default testing environment used by sqldf to perform the queries, in addition, you must first install a mysql database using the old method of authentication, if you use encryption it will generate errors because sqldf drivers do not support it.
the local-infile parameters must be added to allow local data loading to the mysql database, otherwise it will generate errors.
[rs-dbi] user = root password = test port = 3310 default-character-set
= latin1 host = 127.0.0.1 database = test local-infile [mysql] local-infile [mysqld] local_infile = 1
Just sqldf (x = test_query, drv = "RMySQL")
enjoy. The coding of the selected databases must be taken into account as the default in rs-dbi to avoid coding errors when making queries.
The documentation is in ?sqldf . (You will need to refer to the MySQL documentation and RMySQL R package for details. This could vary depending on which version of MySQL you are using.) From ?sqldf:
On MySQL the database must pre-exist. Create a c:\my.ini or
%MYSQL_HOME%\my.ini file on Windows or a /etc/my.cnf file on UNIX to
contain information about the database. This file may specify the
username, password and port. The password can be omitted if one has
not been set. If using a standard port setup then the port can be
omitted as well. The database is taken from the dbname argument of the
sqldf command or if not set from getOption("sqldf.dbname") or if that
option is not set it is assumed to be "test". Note that MySQL does not
use the user, password, host and codeport arguments of sqldf. See
http://dev.mysql.com/doc/refman/5.6/en/option-files.html for
additional locations that the configuration files can be placed as
well as other information.
Also you could try using SQLite instead (which is the default back end and requires no installation). This works for me on Windows using the default SQLite backend.
library(sqldf)
d <- data.frame(x = "el perro saltó sobre el zorro perezoso")
sqldf("select * from d")
## x
## 1 el perro saltó sobre el zorro perezoso
In shell script I am hardcoding username and password to connect to db.
If the password field has $ followed by numeric value it is considering as the argument or parameter hence not connecting to db.
Please suggest how this can be resolved.
I cannot change the db password
Quote your password with single quotes.
For details, see your friendly manual - open a terminal and type man sh or man bash (if bash is the shell you're using).
The online Bash reference manual also has pages on quoting. (I found these with Google, literally within a second.)
Sorry but I am failing at a very simple task right now.
I have the following database information:
database name
hostname
port
SID
TNS
User ID
password
I want to build a connection with the RODBC package.
According to the results of my google search i should do
conn<-odbcConnect(dsn, uid=***, pwd=***)
what is "dsn"? is this even the right way?
dsn is Data Source Name, which is a shortcut you may define on your machine to store key information about the connection. How you set up a DSN varies depending on your operating system.
I write scripts that run on multiple machines, so rather than use a DSN, I use odbcDriverConnect, via something like
odbcDriverConnect(connection="driver=[driver]; server=[server]; database=[database]; uid = [User ID]; pwd = [password]")
You'll need to know your driver name to make this work. Where to find this will depend on your operating system, as well as the flavor of SQL you are using.
I am trying to connect R to Teradata and am not sure what the input items are to the RODBC::odbcDriverConnect(). There is a teradataR package, but it is only used with R versions 3 and under, which I neither have nor want to switch to. Below is a list of the input parameters to get ODBCDriverConnect to work. "Connection" I believe is most important. I need to get an address for a driver that I don't even know if I have. This is what I need most help with. How do I get a driver for Teradata to connect to R? IT at my work is not sure how to do this. Also, if anyone knows of another way to connect Teradata to R (some other package?), please let me know.
connection = ""
case
believeNRows = TRUE
colQuote, tabQuote = colQuote
interpretDot = TRUE
DBMSencoding = "",
rows_at_time = 100
readOnlyOptimize = FALSE
Thank you for your help!
I was able to connect R to Teradata using RODBC package. Here is how to do it if you are working on a pc and have a Teradata driver.
Set up DSN:
Go to: control panel-> administrative tools -> Data Sources (ODBC) -> User DSN tab -> click add-> select Teradata driver (or whatever driver you will be using. ie. could be sql) and press finish.
A box will pop up that needs to be filled in. The following fields need to be filled:
Name: Can be any name you would like. I chose TeraDataRConnection, for example.
Name or IP address (DBC name or address): Mine for example is: Databasename.companyname.com. I looked to see how Microsoft access was connected to the database and in doing that, found the DBC address.
Username: username that you use to connect to database.
Password: password use to connect to databases (if you don't put your password in here, you will have to manually type it into R every time you connect.
In R:
Download RODBC package
library(RODBC)
ch=odbcConnect("TeraDataRConnection", uid="USERNAME HERE",pwd="PASSWORD HERE")
If you want to confim you are connected, you can type in this code to see the tables:
ListOfTables=sqlTables(ch,tableType="TABLE")
That's it!
I am able to connect to Teradata and created a Shiny app which reads data from it.
Firstly we need to install RODBC package in our R. Prerequisite of it is R (≥ 4.0.0) version. No admin access is required to upgrade R even in enterprise laptops.
Follow below steps to successfully setup connection.
Create ODBC Data Sources to connect to Teradata. The connection should be either in 64bit or 32bit, depending on R software.
Use below code snippet to get the data into reactive variable
data <- reactive({
ch <- odbcConnect(dsn = "DSNName", uid = "username", pwd = "password")
sqlQuery(ch,paste('select * from emp ')
})
DSNName - Name of DSN connection created
You can use data() to display and use the value stored in it.
Enjoy!
I'm using RStudio and SVN repository to version control my R projects and files. Usually I fetch data from database at the beginning in these scripts. I'm using RODBC like this:
channel <- odbcConnect(mydbconn, uid = "", pwd = "")
Now, I don't want to store connection details, user id's and password's in these scripts because if these are hard coded, everyone who can access to SVN repo is able to see my passwords etc.
What is the best approach in these kind of cases? How can I prompt these details (connection, userid and password) when this script is run (e.g from RStudio or from the command line)?
If you want to prompt the user, you can use the [readline][1] method:
connection <- readline("Connection: ")
uid <- readline("User id: ")
cat("Password: ")
system("stty -echo")
password <- readline()
system("stty echo")
Note the little trick to avoid echoing the password to the screen.
Another option is to store those values in a configuration file (e.g. config.local) and insert load(config.local) in the script. Make sure that file is not versioned with svn propset svn:ignore "config.local . ". Alternatively, you can store that file in a directory which is not under the control of svn.