适当的MySQL数据库连接字符串是什么?

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

what is proper mysql database connection string

问题

我正在使用以下连接字符串:

> mysql://root:root@newserver/metro

其中:
> 用户名:root

> 密码:root

> 服务器:newserver

> 数据库:metro

出现以下错误:
> 2017/08/19 06:10:02 default addr for network 'newserver' unknown

这是MySQL服务器日志:

> 重定向到/bin/systemctl status mysqld.service
● mysqld.service - MySQL Community Server
已加载:已加载 (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
活动的:自从 Fri 2017-08-18 17:14:59 UTC; 12h ago
进程:23510 ExecStartPost=/usr/bin/mysql-systemd-start post (code=exited, status=0/SUCCESS)
进程:23447 ExecStartPre=/usr/bin/mysql-systemd-start pre (code=exited, status=0/SUCCESS)
主 PID:23509 (mysqld_safe)
CGroup:/system.slice/mysqld.service
├─23509 /bin/sh /usr/bin/mysqld_safe --basedir=/usr
└─23676 /usr/sbin/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib64/mysql/plugin --log-error=/var/log/mysqld.log --pid-file=/var/run/...

> Aug 18 17:14:58 newserver mysql-systemd-start[23447]: 通过在 http://shop.mysql.com 购买支持/许可证来支持MySQL
Aug 18 17:14:58 newserver mysql-systemd-start[23447]: 注意:未创建新的默认配置文件。
Aug 18 17:14:58 newserver mysql-systemd-start[23447]: 请确保您的配置文件是最新的
Aug 18 17:14:58 newserver mysql-systemd-start[23447]: 警告:系统上存在默认配置文件/etc/my.cnf
Aug 18 17:14:58 newserver mysql-systemd-start[23447]: MySQL服务器将默认读取此文件
Aug 18 17:14:58 newserver mysql-systemd-start[23447]: 如果您不想使用它,请删除它或在启动服务器时使用--defaults-file参数来使用mysqld_safe
Aug 18 17:14:58 newserver mysqld_safe[23509]: 170818 17:14:58 mysqld_safe Logging to '/var/log/mysqld.log'.
Aug 18 17:14:58 newserver mysqld_safe[23509]: 170818 17:14:58 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
Aug 18 17:14:59 newserver systemd[1]: 已启动 MySQL Community Server。

以下是/etc/hosts的内容:

> 172.31.43.60 newserver

这个配置是在单台机器上,我正在尝试使用Golang程序进行访问。

这是相同的URL:

https://github.com/utronframework/tutorials/blob/master/create_todo_list_application_with_utron.md

文件名是config/app.json

这是我的app.json文件:

{
    "app_name": "utron web app",
    "base_url": "http://localhost:8090",
    "port": 8090,
    "verbose": false,
    "static_dir": "static",
    "view_dir": "views",
    "database": "mysql",
    "database_conn": "mysql://root:root@newserver/metro",
    "automigrate": true
}

请提供建议。

英文:

i am using following connection string :

> mysql://root:root@newserver/metro

where
> username: root

> password: root

> server : newserver

> database: metro

getting following error :
> 2017/08/19 06:10:02 default addr for network 'newserver' unknown

here are mysql server logs :

> Redirecting to /bin/systemctl status mysqld.service
● mysqld.service - MySQL Community Server
Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
Active: active (running) since Fri 2017-08-18 17:14:59 UTC; 12h ago
Process: 23510 ExecStartPost=/usr/bin/mysql-systemd-start post (code=exited, status=0/SUCCESS)
Process: 23447 ExecStartPre=/usr/bin/mysql-systemd-start pre (code=exited, status=0/SUCCESS)
Main PID: 23509 (mysqld_safe)
CGroup: /system.slice/mysqld.service
├─23509 /bin/sh /usr/bin/mysqld_safe --basedir=/usr
└─23676 /usr/sbin/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib64/mysql/plugin --log-error=/var/log/mysqld.log --pid-file=/var/run/...

> Aug 18 17:14:58 newserver mysql-systemd-start[23447]: Support MySQL by buying support/licenses at http://shop.mysql.com
Aug 18 17:14:58 newserver mysql-systemd-start[23447]: Note: new default config file not created.
Aug 18 17:14:58 newserver mysql-systemd-start[23447]: Please make sure your config file is current
Aug 18 17:14:58 newserver mysql-systemd-start[23447]: WARNING: Default config file /etc/my.cnf exists on the system
Aug 18 17:14:58 newserver mysql-systemd-start[23447]: This file will be read by default by the MySQL server
Aug 18 17:14:58 newserver mysql-systemd-start[23447]: If you do not want to use this, either remove it, or use the
Aug 18 17:14:58 newserver mysql-systemd-start[23447]: --defaults-file argument to mysqld_safe when starting the server
Aug 18 17:14:58 newserver mysqld_safe[23509]: 170818 17:14:58 mysqld_safe Logging to '/var/log/mysqld.log'.
Aug 18 17:14:58 newserver mysqld_safe[23509]: 170818 17:14:58 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
Aug 18 17:14:59 newserver systemd[1]: Started MySQL Community Server.

following are the contents of /etc/hosts

> 172.31.43.60 newserver

this configuration is there on single machine and i am trying to access using golang program.

here is the url for the same :

https://github.com/utronframework/tutorials/blob/master/create_todo_list_application_with_utron.md

the filename is config/app.json

here is my app.json file

{
    "app_name": "utron web app",
    "base_url": "http://localhost:8090",
    "port": 8090,
    "verbose": false,
    "static_dir": "static",
    "view_dir": "views",
    "database": "mysql",
    "database_conn": "mysql://root:root@newserver/metro",
    "automigrate": true

}

please suggest

答案1

得分: 2

我对Go没有任何了解,但是我可以阅读文档,文档建议你使用以下内容:

root:root@tcp(newserver)/metro

或者可能是:

mysql://root:root@tcp(newserver)/metro
英文:

I have no clue about Go, but I can read the documentation, which suggests that you need to use this:

root:root@tcp(newserver)/metro

Or possibly:

mysql://root:root@tcp(newserver)/metro

huangapple
  • 本文由 发表于 2017年8月19日 14:16:14
  • 转载请务必保留本文链接:https://go.coder-hub.com/45768347.html
匿名

发表评论

匿名网友

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

确定