Ruby on Rails Database.yml 文件的正确 MySQL 配置
我有这样的配置:
development:
adapter: mysql2
encoding: utf8
database: my_db_name
username: root
password: my_password
host: mysql://127.0.0.1:3306
并且我收到此错误:
Unknown MySQL server host 'mysql://127.0.0.1:3306' (1)
是否有一些明显的事情表明我做错了?
I have this configuration:
development:
adapter: mysql2
encoding: utf8
database: my_db_name
username: root
password: my_password
host: mysql://127.0.0.1:3306
And I am getting this error:
Unknown MySQL server host 'mysql://127.0.0.1:3306' (1)
Is there something obvious that I am doing incorrectly?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
您应该将主机与端口号分开。
你可以有一些东西,比如:
You should separate the host from the port number.
You could have something, like:
你也可以这样做:
You also can do like this:
使用“utf8mb4”作为编码来覆盖所有unicode(包括表情符号)
(参考1)
(参考文献2)
Use 'utf8mb4' as encoding to cover all unicode (including emojis)
(Reference1)
(Reference2)
如果你可以有一个空的 config/database.yml 文件,然后定义 ENV['DATABASE_URL'] 变量,那么它将适用
于 Heroku:
heroku config:set
DATABASE_URL='mysql://root:[电子邮件受保护]/my_db_name'
If you can have an empty config/database.yml file then define ENV['DATABASE_URL'] variable, then It will work
for Heroku:
heroku config:set
DATABASE_URL='mysql://root:[email protected]/my_db_name'
如果您有多个数据库用于测试和开发,这可能会有所帮助
If you have multiple databases for testing and development this might help
这些答案都不适合我,我发现 Werner Bihl 的答案解决了问题。
出现“无法连接为 Ruby on Rails 应用程序设置 mysql 数据库时,通过套接字“/var/run/mysqld/mysqld.sock”连接到本地 MySQL 服务器时出现错误
None of these anwers worked for me, I found Werner Bihl's answer that fixed the problem.
Getting "Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock'" error when setting up mysql database for Ruby on Rails app