| 1 | <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> |
| 2 | <html> |
| 3 | <head> |
| 4 | <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> |
| 5 | <title>Store 'mysql'</title> |
| 6 | <meta name="generator" content="DocBook XSL Stylesheets V1.76.1"> |
| 7 | <link rel="home" href="index.html" title="Redland RDF Library Manual"> |
| 8 | <link rel="up" href="redland-storage-modules.html" title="Storage Modules"> |
| 9 | <link rel="prev" href="redland-storage-module-file.html" title="Store 'file'"> |
| 10 | <link rel="next" href="redland-storage-module-postgresql.html" title="Store 'postgresql'"> |
| 11 | <meta name="generator" content="GTK-Doc V1.18 (XML mode)"> |
| 12 | <link rel="stylesheet" href="style.css" type="text/css"> |
| 13 | </head> |
| 14 | <body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"> |
| 15 | <table class="navigation" id="top" width="100%" summary="Navigation header" cellpadding="2" cellspacing="2"><tr valign="middle"> |
| 16 | <td><a accesskey="p" href="redland-storage-module-file.html"><img src="left.png" width="24" height="24" border="0" alt="Prev"></a></td> |
| 17 | <td><a accesskey="u" href="redland-storage-modules.html"><img src="up.png" width="24" height="24" border="0" alt="Up"></a></td> |
| 18 | <td><a accesskey="h" href="index.html"><img src="home.png" width="24" height="24" border="0" alt="Home"></a></td> |
| 19 | <th width="100%" align="center">Redland RDF Library Manual</th> |
| 20 | <td><a accesskey="n" href="redland-storage-module-postgresql.html"><img src="right.png" width="24" height="24" border="0" alt="Next"></a></td> |
| 21 | </tr></table> |
| 22 | <div class="section"> |
| 23 | <div class="titlepage"><div><div><h2 class="title" style="clear: both"> |
| 24 | <a name="redland-storage-module-mysql"></a>Store 'mysql'</h2></div></div></div> |
| 25 | <p>This module is compiled in when MySQL 3 or 4 is available. This |
| 26 | store provides storage using the |
| 27 | <a class="ulink" href="http://www.mysql.com/" target="_top">MySQL</a> |
| 28 | open source database including contexts. It was added in Redland |
| 29 | 0.9.15. It has however been tested with several million triples and |
| 30 | deployed.</p> |
| 31 | <p>There are several options required with the mysql storage |
| 32 | in order to connect to the database. These are:</p> |
| 33 | <div class="itemizedlist"><ul class="itemizedlist" type="disc"> |
| 34 | <li class="listitem"><p><code class="literal">host</code> for the database server hostname</p></li> |
| 35 | <li class="listitem"><p><code class="literal">port</code> for the database server port (defaults to the MySQL port 3306 if not given)</p></li> |
| 36 | <li class="listitem"><p><code class="literal">database</code> for the MySQL database name (not the storage name)</p></li> |
| 37 | <li class="listitem"><p><code class="literal">user</code> for the database server user name</p></li> |
| 38 | <li class="listitem"><p><code class="literal">password</code> for the database server password</p></li> |
| 39 | </ul></div> |
| 40 | <p>NOTE: Take care exposing the password as for example, program |
| 41 | arguments or environment variables. The rdfproc |
| 42 | utility can with help this by reading the password from standard |
| 43 | input. Inside programs, one way to prevent storing the password in a |
| 44 | string is to construct a Redland hash of the storage options such as |
| 45 | via <code class="literal">librdf_hash_from_string</code> and use |
| 46 | <code class="literal">librdf_new_storage_with_options</code> to create a storage. |
| 47 | The rdfproc utility source code demonstrates this. |
| 48 | </p> |
| 49 | <p>The storage name parameter given to the storage constructor |
| 50 | <code class="literal">librdf_new_storage</code> is used inside the mysql store to |
| 51 | allow multiple stores inside one MySQL database instance as |
| 52 | parameterised with the above options.</p> |
| 53 | <p>If boolean option <code class="literal">new</code> is given, any existing MySQL |
| 54 | database named by the storage option <code class="literal">database</code>, say |
| 55 | <span class="emphasis"><em>db</em></span> will be dropped and the appropriate new tables created. |
| 56 | The MySQL database <span class="emphasis"><em>db</em></span> must already exist, such as made with |
| 57 | the MySQL <code class="literal">create database </code><span class="emphasis"><em>db</em></span> command and the |
| 58 | appropriate privileges set so that the user and password work. |
| 59 | </p> |
| 60 | <p>If boolean option <code class="literal">reconnect</code> is given, MySQL |
| 61 | reconnection will be enabled so that if the database connection |
| 62 | is dropped, MySQL will attempt to reconnect. |
| 63 | </p> |
| 64 | <p>This store always provides contexts; the boolean storage option |
| 65 | <code class="literal">contexts</code> is not checked.</p> |
| 66 | <p>Examples:</p> |
| 67 | <pre class="programlisting"> |
| 68 | /* A new MySQL store */ |
| 69 | storage=librdf_new_storage(world, "mysql", "db1", |
| 70 | "new='yes',host='localhost',database='red',user='foo','password='bar'"); |
| 71 | |
| 72 | /* A different, existing MySQL store db2 in the same database as above */ |
| 73 | storage=librdf_new_storage(world, "mysql", "db2", |
| 74 | "host='localhost',database='red',user='foo','password='bar'"); |
| 75 | |
| 76 | /* An existing MySQL store on a different database server */ |
| 77 | storage=librdf_new_storage(world, "mysql", "db3", |
| 78 | "host='db.example.org',database='abc',user='baz','password='blah'"); |
| 79 | |
| 80 | /* Opening with an options hash */ |
| 81 | options=librdf_new_hash(world, NULL); |
| 82 | librdf_hash_from_string(options, |
| 83 | "host='db.example.org',database='abc',user='baz'"); |
| 84 | librdf_hash_put_strings(options, "password", user_password); |
| 85 | storage=librdf_new_storage_with_options(world, "mysql", "db4", options); |
| 86 | </pre> |
| 87 | <p>In PHP:</p> |
| 88 | <pre class="programlisting"> |
| 89 | # An existing store |
| 90 | $storage=librdf_new_storage($world, 'mysql', 'db4', |
| 91 | "host='127.0.0.1',database='xyz',user='foo',password='blah'"); |
| 92 | |
| 93 | </pre> |
| 94 | <p>Summary:</p> |
| 95 | <div class="itemizedlist"><ul class="itemizedlist" type="disc"> |
| 96 | <li class="listitem"><p>Persistent</p></li> |
| 97 | <li class="listitem"><p>Suitable for very large models</p></li> |
| 98 | <li class="listitem"><p>Indexed but not optimized</p></li> |
| 99 | <li class="listitem"><p>Smaller disk usage than BDB</p></li> |
| 100 | <li class="listitem"><p>Possibility of free text searching</p></li> |
| 101 | <li class="listitem"><p>Contexts always provided</p></li> |
| 102 | </ul></div> |
| 103 | </div> |
| 104 | <div class="footer"> |
| 105 | <hr> |
| 106 | Generated by GTK-Doc V1.18</div> |
| 107 | </body> |
| 108 | </html> |