MySQL 远程连接到 clearDB heroku 数据库
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9822313/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Remote connect to clearDB heroku database
提问by roman
How can i perform a remote connect to ClearDB MySQL database on heroku using for example MySQL Query Browser. Where to get url, port, login and password?
我如何使用例如 MySQL 查询浏览器在 heroku 上执行到 ClearDB MySQL 数据库的远程连接。从哪里获取 url、端口、登录名和密码?
回答by Abbas
In heroku website, go to My Apps and select the app on which you have installed ClearDB.
在 heroku 网站中,转到我的应用程序并选择您已安装 ClearDB 的应用程序。
On the top corner click on Addonsand then select ClearDB MySQL Database.
Once there, click on your database and choose the 'Endpoint Information' tab. There you see your username/password. The URL to the database can be acquired by running
heroku config --app <YOUR-APP-NAME>
in the command line.
在顶角单击Addons,然后选择ClearDB MySQL Database。在那里,单击您的数据库并选择“端点信息”选项卡。在那里你会看到你的用户名/密码。可以通过heroku config --app <YOUR-APP-NAME>
在命令行中运行来获取数据库的 URL
。
In my case, it was something like: mysql://user:pass@us-cdbr-east.cleardb.com/DATABASE
?reconnect=true
What you need is this part: us-cdbr-east.cleardb.com
就我而言,它类似于:mysql://user: [email protected]/ DATABASE
?reconnect=true 你需要的是这部分:us-cdbr-east.cleardb.com
回答by Andrei
You run heroku config to get the CLEARDB_DATABASE_URL
and it should be something of this format:
你运行 heroku config 来获取它CLEARDB_DATABASE_URL
,它应该是这种格式:
CLEARDB_DATABASE_URL => mysql://[username]:[password]@[host]/[database name]?reconnect=true
So basically you just look at your own url and get all you want from there. That's how i set up mysql workbench.
所以基本上你只要看看你自己的网址,然后从那里得到你想要的一切。这就是我设置mysql工作台的方式。
回答by Developine
Paste this command in terminal
将此命令粘贴到终端中
heroku config | grep CLEARDB_DATABASE_URL
After this you will get Database URL. e.g this is your cleardb database URL.
在此之后,您将获得数据库 URL。例如,这是您的 cleardb 数据库 URL。
'mysql://b0600ea495asds:9cd2b111@us-cdbr-hirone-west-
06.cleardb.net/heroku_4a1dc3673c4114d?reconnect=true'
Than this will be your database credentials. (Extracted from Above URL)
这将是您的数据库凭据。(摘自上述网址)
USER NAME = b0600ea495asds
用户名 = b0600ea495asds
PASSWORD = 9cd2b111
密码 = 9cd2b111
HOST = us-cdbr-hirone-west- 06.cleardb.net
HOST = us-cdbr-hirone-west-06.cleardb.net
DATABASE NAME = heroku_4a1dc3673c4114d
数据库名称 = heroku_4a1dc3673c4114d
回答by lito
I did a video explaining how to connect to MySql using NodeJS on a Heroku server, take a look:
我做了一个视频,解释了如何在 Heroku 服务器上使用 NodeJS 连接到 MySql,请看:
http://www.youtube.com/watch?v=2OGHdii_42s
http://www.youtube.com/watch?v=2OGHdii_42s
This is the code in case you want to see:
这是您想查看的代码:
https://github.com/mescalito/MySql-NodeJS-Heroku
https://github.com/mescalito/MySql-NodeJS-Heroku
Here is part of the code:
这是代码的一部分:
var express = require("express");
var mysql = require('mysql');
var app = express();
app.use(express.logger());
var connection = mysql.createConnection({
host : 'us-cdbr-east-04.cleardb.com',
user : 'b6d6c6e874',
password : 'b3f7###',
database : 'heroku_1daa39da0'
});
connection.connect();
app.get('/', function(request, response) {
connection.query('SELECT * from t_users', function(err, rows, fields) {
if (err) {
console.log('error: ', err);
throw err;
}
response.send(['Hello World!!!! HOLA MUNDO!!!!', rows]);
});
});
var port = process.env.PORT || 5000;
app.listen(port, function() {
console.log("Listening on " + port);
});
CHeers! MAGIC: http://makegif.com/g9yv.gif
干杯!魔术:http: //makegif.com/g9yv.gif
回答by Jordan Schuetz
If you are using mySQL workbench, follow this schema. Go to Heroku > Your Applications Settings > Config Vars, and show the long URL. That url includes your username, password, the URL of the database and the default schema. Paste all of the information as follows below, and you will be able to successfully connect to the database. There was no real explaination on how to connect to ClearDB using mySQL workbench on this thread, so hopefully this helps someone who was struggling.
如果您使用的是 mySQL 工作台,请遵循此模式。转到Heroku > Your Applications Settings > Config Vars,并显示长 URL。该 url 包括您的用户名、密码、数据库的 URL 和默认架构。将所有信息如下粘贴,即可成功连接数据库。在这个线程上没有关于如何使用 mySQL 工作台连接到 ClearDB 的真正解释,所以希望这可以帮助那些正在挣扎的人。
回答by user3805474
Paste this inside terminal:
将其粘贴到终端中:
heroku config | grep CLEARDB_DATABASE_URL
回答by Sébastien Saunier
You can use this one-liner to connect to your MySQL database in your terminal.
您可以使用此单行连接到终端中的 MySQL 数据库。
$(ruby -e 'require "uri"; uri = URI.parse(ARGV[0]); puts "mysql -u#{uri.user} -p#{uri.password} -h#{uri.host} -D#{uri.path.gsub("/", "")}"' `heroku config:get CLEARDB_DATABASE_URL`)
回答by user2364424
Go to your app on heroku and click to the 'settings' tab. Then click the button on the second option that says 'reveal config vars'.
转到您在 heroku 上的应用程序,然后单击“设置”选项卡。然后单击第二个选项上显示“显示配置变量”的按钮。
You should find, listed under the CLEARDB_DATABASE_URL variable, something like this...
你应该发现,列在 CLEARDB_DATABASE_URL 变量下,像这样......
mysql://[username]:[password]@[host]/[database name]?reconnect=true
mysql://[用户名]:[密码]@[主机]/[数据库名]?reconnect=true
So the [host portion] is your host. The [database name] portion is your db name, of course.
所以[主机部分]是你的主机。当然,[database name] 部分是您的数据库名称。
You still need your username and password. Go back to the 'overview' tab in heroku. Go to the ClearDB add-on in your installed add-ons section. Click the database you want to access (probably only 1 option there). Click the 'system information' tab. You should see your username and password.
您仍然需要您的用户名和密码。返回到 heroku 中的“概览”选项卡。转到已安装的附加组件部分中的 ClearDB 附加组件。单击要访问的数据库(可能只有 1 个选项)。单击“系统信息”选项卡。您应该会看到您的用户名和密码。
that should be all you need to access your database. I use sequel pro. I just plugged that info (name, host, into the 'standard' tab and I was good to go.
这应该是您访问数据库所需的全部内容。我使用续集专业版。我只是将这些信息(姓名、主机、到“标准”选项卡中,我很高兴去。
回答by GiantCoder
All of this worked perfectly for me. Using heroku config | grep, as described above and then simply adding another entry into my config.inc.php for use by phpMyAdmin and I can access my cleardb database remotely. It saves me having to have SQL locally and using postgres with Heroku.
所有这些对我来说都非常有效。使用 heroku 配置 | grep,如上所述,然后简单地在我的 config.inc.php 中添加另一个条目供 phpMyAdmin 使用,我可以远程访问我的 cleardb 数据库。它使我不必在本地拥有 SQL 并在 Heroku 中使用 postgres。
回答by Neil Middleton
All the details will be in the database URL which can be found in heroku config
. Assuming you can connect to ClearDB directly (I've never tried), these should be all you need...
所有详细信息都将在数据库 URL 中,可以在heroku config
. 假设您可以直接连接到 ClearDB(我从未尝试过),这些应该就是您所需要的......