5
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
6
<title>Juju Documentation</title>
7
<script src="/wp-content/themes/ubuntu/library/js/all-yui.js"></script>
8
<link href="https://fonts.googleapis.com/css?family=Ubuntu:400,300,300italic,400italic,700,700italic|Ubuntu+Mono" rel="stylesheet" type="text/css">
9
<link rel="stylesheet" type="text/css" media="screen" href="https://juju.ubuntu.com/wp-content/themes/juju-website/css/reset.css">
10
<link rel="shortcut icon" href="//assets.ubuntu.com/sites/ubuntu/latest/u/img/favicon.ico" />
11
<link rel="stylesheet" type="text/css" media="screen" href="//assets.ubuntu.com/sites/guidelines/css/latest/ubuntu-styles.css" />
12
<link rel="stylesheet" type="text/css" media="screen" href="//assets.ubuntu.com/sites/ubuntu/latest/u/css/global.css" />
13
<link rel="stylesheet" type="text/css" media="screen" href="https://juju.ubuntu.com/wp-content/themes/juju-website/css/960.css">
14
<link rel="stylesheet" type="text/css" media="screen" href="https://juju.ubuntu.com/wp-content/themes/juju-website/css/home-new.css">
15
<link rel="stylesheet" id="stacktack-css" href="https://juju.ubuntu.com/wp-content/plugins/stacktack/css/stacktack.min.css?ver=3.4.2" type="text/css" media="all">
16
<link href="./css/main.css" rel="stylesheet" type="text/css">
19
<script type="text/javascript" src="//html5shim.googlecode.com/svn/trunk/html5.js"></script>
25
<body class="resources">
28
<header class="banner global" role="banner">
29
<nav role="navigation" class="nav-primary nav-right">
31
<a class="logo-ubuntu" href="https://juju.ubuntu.com/">
32
<img width="118" height="27" src="//assets.ubuntu.com/sites/ubuntu/latest/u/img/logo.png" alt="Juju logo" />
37
<li class="accessibility-aid"><a accesskey="s" href="#main-content">Jump to content</a></li>
38
<li class="page_item page-item-8"><a href="https://juju.ubuntu.com/charms/">Charms</a></li>
39
<li class="page_item page-item-10"><a href="https://juju.ubuntu.com/features/">Features</a></li>
40
<li class="page_item page-item-12"><a href="https://juju.ubuntu.com/deployment/">Deploy</a></li>
41
<li class="page_item page-item-14"><a href="https://juju.ubuntu.com/resources/">Resources</a></li>
42
<li class="page_item page-item-16"><a href="https://juju.ubuntu.com/community/">Community</a></li>
43
<li class="page_item page-item-18"><a href="https://juju.ubuntu.com/download/">Install Juju</a></li>
46
<form class="search-form" method="get" id="searchform" action="https://juju.ubuntu.com/">
47
<label class="off-left" for="s">Search:</label>
48
<input class="form-text" type="text" value="" name="s" id="s" />
49
<button class="off-left form-submit" type="submit" id="searchsubmit">Search</button>
57
<div id="main-content" class="inner-wrapper" role="main">
58
<div class="row no-border">
59
<div class="header-navigation-secondary"></div>
60
<h2 class="pagetitle">Juju documentation</h2>
62
<section id="content" class="container-12">
63
<div class="grid-12 doc-container">
64
<div id="navlinks" class="grid-3 doc-navigation">LINKS</div>
65
<div class="grid-9 doc-content">
68
<section id="mysql-interface">
69
<h1>mysql interface</h1>
71
<p>The mysql interface is provided by the mysql charm, and is required by a number of charms currently in the Charm Store and elsewhere which would like to use or actually require a MySQL database.
74
<h2>Hook Implementation: relation-joined</h2>
78
<p>When the mysql charm is notified of a “relation joined” event, it creates a database. String values are generated for the credentials needed to authenticate a connection to this database: the database name, a username and password. The mysql charm will also check the instance’s hostname and pass that value too, as well as a string containing “True” or “False” to indicate whether this unit is a slave.
80
<p>A charm joining this relationship will typically have a relationship-joined hook which will wait to see when the mysql charm has set one of the expected values (all values are set simultaneously, so the availability of one indicates that all are available).
86
<p>Upon relation joined, mysql sets the following:</p>
87
<ul> <li>database (string)</li>
88
<li>user (string)</li>
89
<li>password (string)</li>
90
<li>host (string)</li>
91
<li>slave (string)</li></ul>
93
<p>The corresponding <code>relation-joined</code> hook in any charm connecting to the mysql charm should fetch any or all of these values.
95
<h3 id="mysql-interface-example">Reference examples:</h3>
97
<p>Implementation in <code>bash</code>:</p>
98
<pre class="prettyprint lang-bash">#!/bin/sh
99
# db-relation-joined example
101
set -ex # -x for verbose logging to juju debug-log
102
juju-log "Joining database at $JUJU_REMOTE_UNIT"
103
hostname=`unit-get public-address`
104
juju-log "from host: $hostname"
106
# Check to see if 'database' has been set, and loop until it is
107
database=`relation-get database`
108
if [ -z "$database" ] ; then
111
# retrieve the remaining values which have been set by the mysql charm
112
user=`relation-get user`
113
password=`relation-get password`
114
host=`relation-get private-address`
115
slave=`relation-get slave`
117
# do something with these values
118
juju-log "Database acquired"
119
juju-log "database: $database username: $user host: $host"
125
Other relation hooks</h2>
127
<p>The only other hook actually implemented for this interface by the mysql charm is relation-broken. This does not actually interact with connected charms using the interface, but performs some housekeeping for the mysql charm.
128
However, this does not mean that other event driven hooks should not be created for requirer charms to do whatever they may need.</p>
139
<footer class="global clearfix" role="contentinfo">
140
<nav role="navigation">
141
<div class="footer-a">
142
<div class="clearfix">
145
<h2><a href="/">Juju</a></h2>
147
<li><a href="/charms">Charms</a></li>
148
<li><a href="/features">Features</a></li>
149
<li><a href="/deployment">Deployment</a></li>
153
<h2><a href="/resources">Resources</a></h2>
155
<li><a href="/resources/juju-overview/">Overview</a></li>
156
<li><a href="/docs/">Documentation</a></li>
157
<li><a href="/resources/the-juju-gui/">The Juju web UI</a></li>
158
<li><a href="/docs/authors-charm-store.html">The charm store</a></li>
159
<li><a href="/docs/getting-started.html#test">Tutorial</a></li>
160
<li><a href="/resources/videos/">Videos</a></li>
161
<li><a href="/resources/easy-tasks-for-new-developers/">Easy tasks for new developers</a></li>
165
<h2><a href="/community">Community</a></h2>
167
<li><a href="/community/blog/">Juju Blog</a></li>
168
<li><a href="/events/">Events</a></li>
169
<li><a href="/community/weekly-charm-meeting/">Weekly charm meeting</a></li>
170
<li><a href="/community/charmers/">Charmers</a></li>
171
<li><a href="/docs/authors-charm-writing.html">Write a charm</a></li>
172
<li><a href="/docs/contributing.html">Help with documentation</a></li>
173
<li><a href="https://bugs.launchpad.net/juju-website/+filebug">File a bug</a></li> <li><a href="/labs/">Juju Labs</a></li>
177
<h2><a href="https://jujucharms.com/sidebar/">Try Juju</a></h2>
179
<li><a href="https://jujucharms.com/">Charm store</a></li>
180
<li><a href="/download/">Download Juju</a></li>
187
<div class="legal clearfix">
188
<p>© 2013 Canonical Ltd. Ubuntu and Canonical are registered trademarks of <a href="http://canonical.com">Canonical Ltd</a>.</p>
194
<script src="//google-code-prettify.googlecode.com/svn/loader/run_prettify.js?skin=sunburst"></script>
195
<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>
196
<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jqueryui/1.8.14/jquery-ui.min.js"></script>
197
<script src="//d38yea5fb4e2oh.cloudfront.net/jquery.stacktack.min.js"></script>
198
<script type="text/javascript" src="//code.jquery.com/jquery-1.9.1.js"></script>
199
<script type="text/javascript" src="./js/main.js"></script>
200
<script type="text/javascript" src="./js/jquery.details.js"></script>
201
<script src="//assets.ubuntu.com/sites/ubuntu/latest/u/js/core.js"></script>
202
<script src="//assets.ubuntu.com/sites/ubuntu/latest/u/js/global.js"></script>
203
<!-- google analytics -->
205
var _gaq = _gaq || [];
206
_gaq.push(['_setAccount', 'UA-1018242-41']);
207
_gaq.push(['_trackPageview']);
210
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
211
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
212
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);