#mysql writes issue error while reads work fine

14 messages · Page 1 of 1 (latest)

vast tusk
#

hi. I have this DSN root:@tcp(localhost:3306)/foo?parseTime=True when using with github.com/go-sql-driver/mysql which works ok when selecting but when inserting, I get this error:
Error 1045 (28000): Access denied for user ''@'localhost' (using password: NO). how do I fix this?

astral urchin
#

You sure it's related to the type of operation? Or could it be because it is a different db instance (which doesn't have the proper DSN configured)

vast tusk
#

I'm not sure how that could be since I'm only using the DSN in one place. the one thing I can think of around the different db instance being a concern is that go endpoint is run as a serverless function. however, code-wise, it's being in just a single spot

#

and the code is db, err := sql.Open(dialect.MySQL, os.Getenv("MYSQL_DSN")) using entgo.io/ent/dialect/sql

astral urchin
#

and can you show some context of where you do the read/writes? and how this db instance gets there

vast tusk
#

oh weird. I just ran a select query and I'm getting the same issue now

astral urchin
#

In a way, that's good news I guess 😅
Can you verify that the os.Getenv call actually returns the correct DSN

vast tusk
#

I'm getting an empty string. I think this only started happening once I moved the hardcoded dsn into an envvar. I'm trying to access it using mysqlDsn := os.Getenv("MYSQL_DSN") and it's defined in .env.local

#

I was able to run inserts just fine, come to think of it, when the dsn was hardcoded before moving it. I reverted the change and it runs fine again. now I need to find how to access the envvar

astral urchin
#

Do you use something like godotenv?

#

otherwise, just MYSQL_DSN="..." go run [...]

vast tusk
#

I don't. I'm trying to work with go serverless functions in vercel: https://vercel.com/docs/projects/environment-variables , which looks like it doesn't recognize .env.local files for serverless functions but only for its frontend client

Vercel Documentation

Learn how to use Vercel Environment Variables, which are key-value pairs configured outside your source code that change depending on the environment.

astral urchin
#

Aha, sorry. I don't really have any experience with Vercel 🙂 But it looks like you're on the right track to fix it

vast tusk
#

that's counterintuitive and upsetting