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

huangapple go评论124阅读模式
英文:

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

问题

我正在尝试在我的机器上运行一个专用服务器,但是MySQL(我相信)给我一个需要密码的错误。

我正在尝试弄清楚Unity的专用服务器套件,

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

我已经弄清楚了所有的步骤,除了最后一步,显然我应该运行"go run main.go",但是如果我运行它,我会得到标题中的错误,

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

套件的开发者说这个错误与MySQL有关,不会帮助我,我不知道如何解决这个问题,当我从工作台运行MySQL时,我输入密码,服务器正在运行,但好像Go在尝试访问MySQL服务器时没有密码或其他什么?

我甚至无法从命令提示符访问MySQL,我甚至将其添加到我的环境变量中,但它总是给我一个未知命令错误。

有人知道如何解决这个问题吗?对不起,我对MySQL、Go和这样的服务器的了解有限...我准备放弃并将项目转换为Photon,但问题是需要从Mirror更改大量的代码。

英文:

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.

答案1

得分: 2

在文档的一个页面(https://www.gamevanillawiki.com/dedicated-server-kit/demo-setup/)中展示了你需要编辑的config.json的示例。

在该配置文件中的一行是以下内容:

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

Go通常使用的数据库连接字符串格式遵循以下格式(参考:https://github.com/go-sql-driver/mysql#dsn-data-source-name):

<用户名>:<密码>@<协议>(<地址>:<端口>)/<数据库名>

文档页面中显示的示例只使用了root:作为用户名和密码。因此,他们的示例数据库连接字符串没有密码。

你需要编辑这个config.json文件,并在:@之间指定你的MySQL用户并添加该用户的密码。

协议、地址和端口可能是正确的。如果你的数据库运行在与Go应用程序运行的服务器不同的服务器上,则需要更改IP地址。

英文:

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:

&quot;db_connection_string&quot;: &quot;root:@tcp(127.0.0.1:3306)/dsk&quot;,

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

&lt;username&gt;:&lt;password&gt;@&lt;protocol&gt;(&lt;address&gt;:&lt;port&gt;)/&lt;schemaname&gt;

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.

huangapple
  • 本文由 发表于 2023年3月24日 22:47:12
  • 转载请务必保留本文链接:https://go.coder-hub.com/75835094.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定