bodhilogic

bodhilogic

Can't connect using a non-root user

I want to establish a ‘web-safe’ user for my MySQL database (i.e. one that only has select, create, update and delete permissions).

If I drop my web-safe user from the database, I get this error which is totally expected because I have no such user in the database:

[error] MyXQL.Connection (#PID<0.287.0>) failed to connect: ** (MyXQL.Error) (1045) (ER_ACCESS_DENIED_ERROR) Access denied for user 'web'@'localhost' (using password: YES)

If I then go and create the ‘web-safe’ user in the database, even assigning the user with full grant privileges, I get a new error:

[error] MyXQL.Connection (#PID<0.275.0>) failed to connect: ** (MyXQL.Error) (1045) (ER_ACCESS_DENIED_ERROR) Access denied for user 'root'@'localhost' (using password: YES)

Say wha???

Why, now that it has the web@localhost user defined, is it attempting to connect using the root@localhost user?

My repo.ex file is the only place any connection information is established and I am definitely not attempting to use the root database user for any of my queries (i.e. override my connection settings).

If I have my app deliberately specify the root@localhost user for it’s connection information, then all works well but that totally defeats the purpose and reason for wanting to use a ‘web-safe’ database user.

Please help… I want to get this app deployed ASAP.
Thanks for your time and troubles.

Most Liked

bodhilogic

bodhilogic

OMG! You are going to shoot me!!!

I was about to place the start MyXQL under my application’s supervision tree and I found this:

  use Application

  def start(_type, _args) do
    # List all child processes to be supervised
    children = [
      {MyXQL, username: "root", name: :myxql},
      ...

I totally beg your forgiveness and thank you again for all your help!

cmkarlsson

cmkarlsson

That is the wrong conclusion. MyXQL should work with any user and you should definitely not use root to login into MySQL. There is some other error here.

Start from the very beginning, it is a very good place to start.
How about testing MyXQL directly:

$ iex -S mix
iex(1)>  {:ok, pid} = MyXQL.start_link([username: "web", password: "something", database: "yourdb", hostname: "localhost"])
{:ok, #PID<0.186.0>}
iex(2)> MyXQL.query(pid, "SELECT count(*) FROM your_table")
{:ok,
 %MyXQL.Result{
   columns: ["count(*)"],
   connection_id: 30,
   last_insert_id: nil,
   num_rows: 1,
   num_warnings: 0,
   rows: [[516]]
 }}

This cuts out anything but MyXQL and tests the parameters directly. I just tested this with a new mix repo (elixir 1.9.1 and erlang 22.1) MyXQL 0.3.0 and MySQL 5.7.28.

Dependency tree of the test repo (because MyXQL depends on DBConnection))

xyxy
└── myxql ~> 0.3.0 (Hex package)
    ├── db_connection ~> 2.0 (Hex package)
    │   └── connection ~> 1.0.2 (Hex package)
    └── decimal ~> 1.6 (Hex package)
wojtekmach

wojtekmach

Hex Core Team

I don’t think that’s a fair characterisation. A lot of work went through testing myxql against different combinations of authentication methods, server defaults, ssl, and more, and all that is done through authenticating as different users.

Yes, that’s a very good suggestion. I got caught up thinking it might be configuration issue, but the issue can be something else. In v0.3.0 there’s a bug fix for mysql_native_password authentication (under certain circumstances) and that can be a culprit too.

cmkarlsson

cmkarlsson

Classic! (we’ve all been there)

Where Next?

Popular in Questions Top

LegitStack
I’m hoping you guys can give me some general advice and perhaps code examples if you’re feeling up to it. I’m very interested in Elixir,...
New
joaquinalcerro
Hi there, I am working with Ecto-Postgresql and I need to call all of the records from a specific table but the table has 40,000 record...
New
itssasanka
Hi all, Trying to get some more clarity over utc_datetime and naive_datetime for Ecto: https://hexdocs.pm/ecto/Ecto.Schema.html#module-...
New
Werner
Hi, I’m using Ubuntu 18.04 and after updating to OTP-24.0 yesterday i have this warning when I run “mix local.hex”: 14:57:30.512 [warn] ...
New
Jim
As a follow up to my earlier question: I have the code compiling and running but not getting a successful login from the rest server. ...
New
makeitrein
Hey all, just started picking up Elixir last week and am writing a scraper as a learning project. Baby step #1 is extracting the number ...
New
kostonstyle
Hi all I want to have a unix time, from the current time plus 1 hour. DateTime.now + 1 hour How to get it in elixir? Thanks
New
jc00ke
Expanding on this topic: https://forum.elixirforum.net/t/map-typespec-question/19217 Let’s say I have a map with required and optional k...
New
jay1
Why is it that the mnesia database isn’t the most preferred database for use in Elixir/Phoenix?
New
lanycrost
Hi everyone! I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
New

Other popular topics Top

quazar
How to set Jason to encode all fields in ecto schema, I don’t care about security and implementing only is taking long list of attributes...
New
chrismccord
This release brings a number of exciting features, including integration with the new Phoenix LiveDashboard and Phoenix LiveView. There h...
New
nsuchy
Hi. I’ve noticed that Windows Powershell has it’s own IEX command and you cannot access Elixir’s IEX due to the conflict. This isn’t a cr...
New
lk-geimfari
What is most correct way to open, read and parse JSON file with poison? For example if we have example.json file in root of some projec...
New
freewebwithme
Using vs code and installed ElixirLS: support and debugger. And I got an error popped up on start up says Failed to run ‘elixir’ comma...
New
mcarvalho
What is the difference between System.get_env and Application.get_env? For example, what are best practices to use one versus another.
New
minhajuddin
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
New
AstonJ
by Lance Halvorsen Elixir and Phoenix are generating tremendous excitement as an unbeatable platform for building modern web application...
460 27162 124
New
aesmail
Hello guys, I have finally made it. I created an admin interface for a framework. It’s been on my todo list for years and with the curre...
New
joeerl
Hello again - after a longish gap I’ve decided I really must dig into Elixir and see what’s been happening here - so I have a few questio...
New

We're in Beta

About us Mission Statement