Use root privileges for a session/package?

Wondering if there’s a simple way to run a Julia session, or use a specific package, with root privilege?
Would like to use the ODBC.jl package as sudo/root.
Am using Julia v1.2 and Linux (Arch-based platform with Manjaro 18.1.2/5.3.8-3-MANJARO x86_64)

Noted that I can run a Julia session as root, but that the packages from my regular user are no longer available:

$ sudo julia
julia> using ODBC
ERROR: ArgumentError: Package ODBC not found in current path:
- Run `import Pkg; Pkg.add("ODBC")` to install the ODBC package.
julia> exit()

Was going to give up there, but then saw this comment from @ExpandingMan in the “Discussion: Plans for Julia as a general-purpose language” thread:

So, thinking could either:

  1. run as root, add packages needed for the query/processing. Just worried about corrupting my general environment or other unforeseen problems.
  2. use the ]dev optioned mentioned by ExpandingMan. I just haven’t done that before.

Suggestions, or am I just asking for more trouble with any of this?

ps - I admit this is a temporary hack and not my “real ‘root’ problem”, which I believe to be improper install and configuration of my MariaDB install and config in linux, with the MariaDB data directory pointing to my home user so the mysql user can’t access, but until I can understand and deal with that, am hoping for a short-term fix, as already have a Julia workflow with a number of queries and data processing work already done from when using Win environment.

Funny, it seems a number of people have this permissions issue out in the wild apart from my case here, with other interfaces (not Julia problems), as the error message is same and scenario similar.
Trying to use the /MySQLMariaDB DSN works from a shell using root, but not in my Julia session:


# not working yet, edit username / psswd; TODO figure out how to read this from a local file, ideally an encrypted one.
conn = ODBC.DSN("mariadb-dsn", "e", "XXXX")#update with your username and password. Can then edit and remove password after code block has run. 

errors with:

[ODBC] 08S01: [unixODBC][MySQL][ODBC 8.0(w) Driver]Can't connect to local MySQL server through socket '/tmp/mysql.sock' (13)

ODBC.ODBCError("ODBC.API.SQLConnect(dbc, connectionstring, username, password) failed; return code: -1 => SQL_ERROR")

 [1] #DSN#3(::Bool, ::Type{ODBC.DSN}, ::String, ::String, ::String) at /home/e/.julia/packages/ODBC/YEzHX/src/ODBC.jl:57
 [2] ODBC.DSN(::String, ::String, ::String) at /home/e/.julia/packages/ODBC/YEzHX/src/ODBC.jl:119
 [3] top-level scope at In[7]:1

And using a local MySQL command line client (tried a couple, I like mycli as it offers syntax highlighting and auto-suggest in a shell environment!). These clients:

$ sudo mycli -u root
$ sudo mariadb -u root
$ sudo mysql -u root 

all connect fine

~ >>> sudo mycli -u root                                                                                                 [2]
mysql 10.4.8-MariaDB
mysql root@localhost:(none)> exit                                                                                            

Also, the isql command line tool can connect:

~ >>> sudo isql -v mariadb-dsn                                                 
| Connected!                            |
| sql-statement                         |
| help [tablename]                      |
| quit                                  |
SQL> quit

BUT, running isql without root privilege give me the same error as within Julia the ODBC, hence, why I just want to get by for now running as root.

~ >>> isql -v mariadb-dsn                                                                                                   
[08S01][unixODBC][MySQL][ODBC 8.0(w) Driver]Can't connect to local MySQL server through socket '/tmp/mysql.sock' (13)
[ISQL]ERROR: Could not SQLConnect

There is an option in the sudoers file with visudo but it may lead to privilege escalation:

## Run X applications through sudo; HOME is used to find the
## .Xauthority file.  Note that other programs use HOME to find   
## configuration files and this may lead to privilege escalation!
# Defaults env_keep += "HOME"
1 Like

Hi @pontus I would have to brush off my mysql/mariadb knowledge. However I think you are correct and the permissions for your database access have not been set up properly.
I would have to make a test install on my laptop to figure it out.

1 Like

Thanks much! Just the sort of tip was looking for, will try that this evening.

Please, don’t spend one moment on my account! Appreciate you popping in with an opinion. Have a good one.

Thanks again @chakravala, I didn’t end up changing the sudoers file, but did learn about it and that knowledge was helpful in the final resolution. It was actually a 3-layered problem, from how I mounted the partition and entries to the /etc/fstab file, MariaDB config, database folder permissions, and finally within MariaDB the user rights and setting that up properly. Now all is resolved!!