<?xml version="1.0" encoding="utf-8"?><!DOCTYPE article  PUBLIC '-//OASIS//DTD DocBook XML V4.4//EN'  'http://www.docbook.org/xml/4.4/docbookx.dtd'><article><articleinfo><title>DaemonAdmin/MySQL</title><revhistory><revision><revnumber>35</revnumber><date>2012-04-23 04:19:38</date><authorinitials>ClintonEbadi</authorinitials></revision><revision><revnumber>34</revnumber><date>2011-04-23 16:31:37</date><authorinitials>AdamChlipala</authorinitials><revremark>spam</revremark></revision><revision><revnumber>33</revnumber><date>2011-04-23 00:08:19</date><authorinitials>ec2-122-248-244-127.ap-southeast-1.compute.amazonaws.com</authorinitials><revremark>BcENfl  &lt;a href=&quot;http://vilivwwawkml.com/&quot;&gt;vilivwwawkml&lt;/a&gt;</revremark></revision><revision><revnumber>32</revnumber><date>2011-04-21 19:34:40</date><authorinitials>200.35.177.233</authorinitials><revremark>TYVM you've solved all my porblmes</revremark></revision><revision><revnumber>31</revnumber><date>2009-09-09 20:13:34</date><authorinitials>ClintonEbadi</authorinitials><revremark>Revert to revision 29.</revremark></revision><revision><revnumber>30</revnumber><date>2009-09-09 18:20:34</date><authorinitials>93.174.94.59</authorinitials><revremark>9IbICC increasing fuel use (and thus increasing operating costs and environmental impacts). To, [[http://ukazurenet.com/members/qantas_2D00_airline/default.aspx|qantas airline]]agement Sciences, the J</revremark></revision><revision><revnumber>29</revnumber><date>2008-07-07 04:28:18</date><authorinitials>localhost</authorinitials><revremark>converted to 1.6 markup</revremark></revision><revision><revnumber>28</revnumber><date>2007-12-02 22:14:08</date><authorinitials>AdamChlipala</authorinitials><revremark>Answer question</revremark></revision><revision><revnumber>27</revnumber><date>2007-11-29 14:38:38</date><authorinitials>RyanMikulovsky</authorinitials><revremark>add comment requesting info on mysql drop</revremark></revision><revision><revnumber>26</revnumber><date>2007-02-10 21:18:23</date><authorinitials>AdamChlipala</authorinitials><revremark>Progress on dbtool</revremark></revision><revision><revnumber>25</revnumber><date>2007-02-10 20:04:01</date><authorinitials>212.91.114.4</authorinitials></revision><revision><revnumber>24</revnumber><date>2007-02-10 19:55:34</date><authorinitials>212.91.114.4</authorinitials></revision><revision><revnumber>23</revnumber><date>2007-02-10 19:42:10</date><authorinitials>212.91.114.4</authorinitials></revision><revision><revnumber>22</revnumber><date>2007-02-10 19:33:18</date><authorinitials>212.91.114.4</authorinitials></revision><revision><revnumber>21</revnumber><date>2007-02-10 19:20:11</date><authorinitials>212.91.114.4</authorinitials></revision><revision><revnumber>20</revnumber><date>2007-02-10 18:09:11</date><authorinitials>212.91.114.4</authorinitials></revision><revision><revnumber>19</revnumber><date>2007-02-05 16:54:52</date><authorinitials>ChristopherClausen</authorinitials><revremark>added steps for system:backup ACLs and change from root.cell to common.databases</revremark></revision><revision><revnumber>18</revnumber><date>2007-02-05 15:00:01</date><authorinitials>213.147.110.16</authorinitials></revision><revision><revnumber>17</revnumber><date>2007-02-05 14:59:34</date><authorinitials>213.147.110.16</authorinitials></revision><revision><revnumber>16</revnumber><date>2007-02-05 14:52:48</date><authorinitials>213.147.110.16</authorinitials></revision><revision><revnumber>15</revnumber><date>2007-02-05 14:51:19</date><authorinitials>213.147.110.16</authorinitials></revision><revision><revnumber>14</revnumber><date>2007-02-05 14:47:34</date><authorinitials>213.147.110.16</authorinitials></revision><revision><revnumber>13</revnumber><date>2007-02-05 14:44:06</date><authorinitials>213.147.110.16</authorinitials></revision><revision><revnumber>12</revnumber><date>2007-02-04 00:18:41</date><authorinitials>212.91.114.169</authorinitials></revision><revision><revnumber>11</revnumber><date>2007-02-03 23:41:12</date><authorinitials>212.91.114.169</authorinitials></revision><revision><revnumber>10</revnumber><date>2007-02-03 23:24:16</date><authorinitials>212.91.114.169</authorinitials></revision><revision><revnumber>9</revnumber><date>2007-02-03 23:19:02</date><authorinitials>212.91.114.169</authorinitials></revision><revision><revnumber>8</revnumber><date>2007-02-03 23:11:55</date><authorinitials>212.91.114.169</authorinitials></revision><revision><revnumber>7</revnumber><date>2007-01-30 00:31:16</date><authorinitials>212.91.113.206</authorinitials></revision><revision><revnumber>6</revnumber><date>2007-01-30 00:27:17</date><authorinitials>212.91.113.206</authorinitials><revremark>1.</revremark></revision><revision><revnumber>5</revnumber><date>2007-01-10 13:51:32</date><authorinitials>JustinLeitgeb</authorinitials><revremark>Added note about network permissions.</revremark></revision><revision><revnumber>4</revnumber><date>2007-01-06 18:07:03</date><authorinitials>JustinLeitgeb</authorinitials></revision><revision><revnumber>3</revnumber><date>2007-01-06 17:48:44</date><authorinitials>JustinLeitgeb</authorinitials></revision><revision><revnumber>2</revnumber><date>2007-01-06 17:31:13</date><authorinitials>JustinLeitgeb</authorinitials></revision><revision><revnumber>1</revnumber><date>2007-01-06 16:45:22</date><authorinitials>JustinLeitgeb</authorinitials></revision></revhistory></articleinfo><para>Because we wanted to have version 5 of MySQL running on our stable server, we used the <ulink url="http://dotdeb.org"/> package.  For this reason there should be mirrors from dotdeb.org listed in the file <emphasis>/etc/apt/sources.list</emphasis> on deleuze. </para><section><title>Configuration details</title><para>my.cnf file modified to leave a port open over the network, default is local pipe only. </para></section><section><title>Progress</title><para>As of Sat Jan  6 12:29:23 EST 2007, the MySQL 5.0 daemon and client libraries have been installed on deleuze.  I also installed the mysql-common and mysql-client 5.0 packages on mire which should will allow for users to connect back to the main DB server. </para></section><section><title>To Do</title><para>The new dbtool implemented as part of <ulink url="https://wiki.hcoop.net/DaemonAdmin/MySQL/DomTool#">DomTool</ulink> can now be used to create MySQL users and databases and the associated AFS directories. We still need to figure out how to allow users to drop tables from their databases without letting them drop the databases themselves. Since users retain permissions on a database even after it's dropped, the user could drop his database and recreate it on the partition where /var/lib/mysql lives, instead of in AFS. </para><para>We also need to work out exactly what hostname mask to use in creating users and granting them privileges. </para><para><emphasis role="strong"> Bugzilla says this isn't an issue anymore.  dbtool runs mysql-fixperms now right?  Or must a user tell dbtool to do this? -- <ulink url="https://wiki.hcoop.net/DaemonAdmin/MySQL/RyanMikulovsky#">RyanMikulovsky</ulink> </emphasis> </para><para><emphasis role="strong">No, dbtool doesn't run mysql-fixperms.  We would never have created that script if it were possible to set up a database ahead of time so that these problems wouldn't apply to it.  mysql-fixperms needs to do things to particular tables, and dbtool isn't run on table creation.  --<ulink url="https://wiki.hcoop.net/DaemonAdmin/MySQL/AdamChlipala#">AdamChlipala</ulink></emphasis> </para></section><section><title>Steps to perform</title><section><title>Logical steps</title><orderedlist numeration="arabic"><listitem><para>Create user's database volume in AFS, if one isn't there already </para></listitem><listitem><para>Create directory structure with proper permission within the AFS volume (the sole existence of the directory is enough for MySQL to consider it a database, even if just an empty one). NOTE: If we stick to existing behavior on fyodor, requested database name should be prefixed with USERNAME_ . </para></listitem><listitem><para>Create a symbolic link in /var/lib/mysql/ that points to the database </para></listitem><listitem><para>Grant the user rights on the new DB </para></listitem></orderedlist><para>And, in terms of command line, the steps are: </para></section><section><title>Initialize DB space for any DB</title><para>You need to perform this as any user who has AFS admin permissions: </para><orderedlist numeration="arabic"><listitem><para>$dir = /afs/hcoop.net/common/.databases/<emphasis role="strong">USERNAME</emphasis> </para></listitem></orderedlist><para><emphasis role="strong">If  vos examine db.USER  says there's no volume created:</emphasis> </para><orderedlist numeration="arabic"><listitem><para>vos create  -server afs -partition a -name db.<emphasis role="strong">USERNAME</emphasis> -maxquota 5000 </para></listitem></orderedlist><para><emphasis role="strong">If db.USER volume is there, but $dir is not present (volume isn't mounted):</emphasis> </para><orderedlist numeration="arabic"><listitem><para>fs mkmount -dir /afs/hcoop.net/common/.databases/<emphasis role="strong">USERNAME</emphasis> -vol db.<emphasis role="strong">USERNAME</emphasis> -rw </para></listitem><listitem><para>vos release common.databases </para></listitem></orderedlist><para><emphasis role="strong">And this can be done always:</emphasis> </para><orderedlist numeration="arabic"><listitem><para>fs setacl -dir $dir -acl databases l </para></listitem><listitem><para>fs setacl -dir $dir -acl system:backup rl </para></listitem></orderedlist></section><section><title>Database creation routine when the db space has been initialized</title><para>You need to perform this as any user who has AFS admin permissions: </para><orderedlist numeration="arabic"><listitem><para>$dir = /afs/hcoop.net/common/databases/<emphasis role="strong">USERNAME</emphasis>/mysql </para></listitem><listitem><para>mkdir -p $dir </para></listitem><listitem><para>fs setacl -dir $dir -acl mysql lid </para></listitem><listitem><para>fs setacl -dir $dir -acl databases none    # (keep out other databases, just in case) </para></listitem><listitem><para>fs setacl -dir $dir -acl system:backup rl  # (should be inherited from parent dir) </para></listitem><listitem><para>sudo mkdir $dir/<emphasis role="strong">DBNAME</emphasis> || exit  # (Must not exist) </para></listitem><listitem><para>sudo chown mysql:mysql $dir/<emphasis role="strong">DBNAME</emphasis> </para></listitem><listitem><para>sudo chmod 770 $dir/<emphasis role="strong">DBNAME</emphasis> # (Just for visual impression) </para></listitem><listitem><para>sudo ln -sf $dir/<emphasis role="strong">DBNAME</emphasis> /var/lib/mysql/<emphasis role="strong">DBNAME</emphasis> </para></listitem><listitem><para>fs setacl -dir $dir/<emphasis role="strong">DBNAME</emphasis>/ -acl mysql all </para></listitem></orderedlist><para>Now, about users and granting permissions to the database, I would like to see users being able create new users and passwords and their privileges (to their databases) themselves. This would allow fine-grained tuning of what service uses which DB username/pw, and what access rights it has. Maybe a list of users/passwords, or an appropriate support ticket would be cool. </para><para>So anyway, the procedure for creating a user and giving privileges, executed on behalf of the admin user (domtool2), which can be specified as   <emphasis role="strong">sudo -H mysql -e &quot;&lt;COMMAND HERE&gt;&quot; mysql</emphasis>: </para><orderedlist numeration="arabic"><listitem><para>CREATE USER <emphasis role="strong">'USERNAME</emphasis>'@<emphasis role="strong">'HOSTNAME</emphasis>' IDENTIFIED BY <emphasis role="strong">'PASSWORD</emphasis>'; </para></listitem><listitem><para>GRANT SELECT,INSERT,UPDATE,DELETE,INDEX,ALTER,CREATE VIEW,SHOW VIEW,GRANT OPTION ON   <emphasis role="strong">DBNAME.*</emphasis>   TO <emphasis role="strong">USERNAME</emphasis>@'%.hcoop.net'; </para></listitem><listitem><para>FLUSH PRIVILEGES; </para></listitem></orderedlist><para>(Thing to note here: Wildcard '%' can be used in hostname part, for things like '%.hcoop.net'.) </para><para>There are two other things related to users, one is changing password and the other is deleting users. These simply map to mysql SET PASSWORD and DROP USER commands, if you go to implement them. </para><para>And one last thing; mysql is listening both on localhost and network interfaces (deleuze external IP). Maybe we want to restrict it to run on just one of them. Or if not, if it will run on both, then the access rule ( USERNAME@'%.hcoop.net' ) has to be duplicated in a way (for USERNAME@localhost), OR the users will always have to specify mysql host &quot;deleuze&quot; instead of &quot;localhost&quot;. Another solution to this is that we don't try to be clever at all, but simply let users make sure the hostname part in their support ticket will match the interface they'll be using to connect. </para><!--rule (<hr>) is not applicable to DocBook--><para> <ulink url="https://wiki.hcoop.net/DaemonAdmin/MySQL/CategorySystemAdministration#">CategorySystemAdministration</ulink> <ulink url="https://wiki.hcoop.net/DaemonAdmin/MySQL/CategoryNeedsWork#">CategoryNeedsWork</ulink> <ulink url="https://wiki.hcoop.net/DaemonAdmin/MySQL/CategoryOutdated#">CategoryOutdated</ulink> </para></section></section></article>