Search code examples
mysqlunity-game-enginegoserverdedicated-server

Mysql Access denied for user 'root'@'localhost' (using password: NO) When Running go run main.go


I'm trying to run a dedicated server on my machine, but MySQL(i believe) is giving me a password required error.

I'm trying to figure out the Dedicated Server Kit for Unity,

https://www.gamevanillawiki.com/ccg-kit/manual/dedicated-server-kit/

And I got all the steps figured out except the last one, which apparently means i'm supposed to run "go run main.go", but if i run it, i get the error in the title,

C:\ccg-kit-dedicated-server\dsk>go run main.go ERROR 2023/03/22 17:50:32 main.go:46: Error 1045: Access denied for user 'root'@'localhost' (using password: NO) exit status 1

The developer of the kit says the error is related to MySQL and won't help me, I have no clue on how to figure this out, when i run MySQL from the workbench i put in the password, the server is running, but it's like Go is trying to access the Mysql server without the password or something?

I can't even access MySQL from cmd, i even added it to my environment variables but it always gives me an unknown command error.

Does anyone know how to solve this? Sorry, my knowledge of MySQL, Go, and such servers is limited... I'm ready to throw in the towel and convert the project to Photon, but the issue is there's a LOT of code that would need changing from Mirror to Photon.


Solution

  • A page in the documentation (https://www.gamevanillawiki.com/dedicated-server-kit/demo-setup/) shows examples of the config.json that you are supposed to edit.

    One of the lines in that config file is the following:

    "db_connection_string": "root:@tcp(127.0.0.1:3306)/dsk",
    

    Go typically uses a db connection string format that follows this format (reference: https://github.com/go-sql-driver/mysql#dsn-data-source-name):

    <username>:<password>@<protocol>(<address>:<port>)/<schemaname>
    

    The example shown in the documentation page shows only root: for the username and password. So their example db connection string has no password.

    You need to edit this config.json file, and specify your MySQL user and add that user's password between : and @.

    The protocol, address, and port are probably correct. If you run your database on a different server than the server you run your Go application, then change the IP address.