Why database connection requires permissions to 'mysql' table?

Hi Folks!

First - thank you for this great language. Coming from the Ruby world, it is really easy to grasp.

To get more practical in learning I decided to get hands on with the Amber framework. However, I wasn’t able to set up a database until I gave the mysql app user permissions (it seems only SELECT is required) to mysql table.

Is there any particular reason for that?

(I use Granite and crystal-lang/crystal-mysql for the start)

Many thanks

Hey @borowskiio! Welcome!

The most likely reason for it that I can think of is to get the table metadata so it can confirm that the columns your app expects and are are the types your app expects them to be when the model is loaded. And I don’t think it happens at runtime — I think it’s a compile-time thing. If that’s true, you may be able to get away with running the build as a different MySQL user so your app won’t have access to that table at runtime.

I’m not 100% certain about any of this, though, and I can’t find in the Granite code where it tries to access this table. I’m mainly basing this on the idea that Rails does something similar when each model file is loaded into memory so it can add the accessor methods to the class.

It’s probably something that happens in the MySQL or base database driver shards.

What failure message were you getting? MySQL permission issue perhaps? Can you create a database manually using that mysql user?

Thanks for your replies. Let me quickly clarify:

  • I set up an amber project
  • Changed the settings for mysql as per the guides with database_url being:

mysql://myuser:mypassword@localhost/mydb_development

  • tried to run amber db create to no avail with the following error:

image

So to get through this, besides the usual permissions for that user:

I needed to add:

image

I’m only asking as I’m curious to why would that be as when using ActiveRecord, it never needed permissions databases other than specified. As you suggest it will be probably crystal-lang/crystal-mysql thus I’m reaching out here as it’s build by Crystal team.

Not a huge deal - pure curiosity though :) I just like to fully understand the tools I’m using inside out.

Thanks again for your prompt answers.

Ahh so you had to add “select” permission for your user. Yeah Amber probably queries first to see if the table already exists or if some metadata exists denoting it was already created, best take it up with them :slight_smile:

That’s correct :) Will stick to conventions then, thanks.