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:
- run as root, add packages needed for the query/processing. Just worried about corrupting my general environment or other unforeseen problems.
- 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:
Julia:
# 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")
Stacktrace:
[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
Goodbye!
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