<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Ideas.... &#187; MySQL</title>
	<atom:link href="http://rosalynmetz.com/ideas/tag/mysql/feed/" rel="self" type="application/rss+xml" />
	<link>http://rosalynmetz.com/ideas</link>
	<description>a blog for me to record thoughts and ideas</description>
	<lastBuildDate>Mon, 19 Jul 2010 16:27:30 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
<atom:link rel="hub" href="http://pubsubhubbub.appspot.com"/><atom:link rel="hub" href="http://superfeedr.com/hubbub"/>		<item>
		<title>Migrating MDID2 to a New Windows Server</title>
		<link>http://rosalynmetz.com/ideas/2010/01/25/migrating-mdid2-to-a-new-windows-server/</link>
		<comments>http://rosalynmetz.com/ideas/2010/01/25/migrating-mdid2-to-a-new-windows-server/#comments</comments>
		<pubDate>Mon, 25 Jan 2010 20:33:16 +0000</pubDate>
		<dc:creator>Rosalyn Metz</dc:creator>
				<category><![CDATA[Work]]></category>
		<category><![CDATA[MDID2]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[Windows Server 2003]]></category>

		<guid isPermaLink="false">http://rosalynmetz.com/ideas/?p=819</guid>
		<description><![CDATA[I just migrated MDID from a Windows Server to a new Windows Server.  It wasn&#8217;t as easy to figure out as you might think.  The MDID wiki doesn&#8217;t have directions on how to do this, so here are my directions. First I always recommend keeping up the old installation while you&#8217;re migrating and not taking [...]]]></description>
			<content:encoded><![CDATA[<p>I just migrated MDID from a Windows Server to a new Windows Server.  It wasn&#8217;t as easy to figure out as you might think.  The <a href="http://mdid.org/mdidwiki/">MDID wiki</a> doesn&#8217;t have directions on how to do this, so here are my directions.</p>
<p>First I always recommend keeping up the old installation while you&#8217;re migrating and not taking it down for at least a week or two (perhaps even longer if you&#8217;re paranoid).  That way if you need to, you can always go back.</p>
<p>Here are the steps that I followed:</p>
<ol>
<li>I installed a blank MDID2 to make sure that I had everything I needed on the server to make MDID2 work.  When installing MySQL I made sure that it was the same version as the old server to ensure that MySQL weirdness didn&#8217;t interfere with the installation.  For instructions on installing MDID2, I used the <a href="http://mdid.org/mdidwiki/index.php?title=Installing_MDID2">MDID wiki&#8217;s instructions</a>.  I actually ran the system and had our Visual Resources Curator test things out to see if it worked like he expected a fresh MDID would work (because lets face it, I don&#8217;t know nearly as much about the system as he does).</li>
<li>Once our Visual Resources Curator gave me the thumbs up I mounted, as a network drive, the directory on the old server that had the MDID2 files and images.  I then copied ALL of the files over to the new directory on the new server.  I then went home for the night&#8230;because that&#8217;s going to take a while.</li>
<li>The next morning go into the config.xml file (found at the root level of mdid2) and change the information in the file so that it&#8217;s settings match  your new servers configuration.  Most likely all you&#8217;ll need to do is  change the location of the image files or the username and password of the database, but you should check over the  rest of the file just to be safe.</li>
<li>Create a mysqldump of the old database using: <code>mysqldump -u mdid2 -p -q mdid2 &gt; mdid2export.sql</code> I then moved the dump over to the new server.  Keep in mind that your MySQL command may be different if:
<ul>
<li>you don&#8217;t use passwords</li>
<li>have a different MySQL user set to run mdid2</li>
<li>your mdid2 user doesn&#8217;t have privileges to do this type of command.</li>
</ul>
</li>
<li>Once I got the dump onto the new server I opened the dump file in notepad and did a find replace.  In my case on the old server mdid was on the d drive and on the new server it was going to be on the c drive.  So I had notepad go through the file and find all instances of <code>d:\\mdid2\\</code> and replace it with <code>c:\\mdid2\\</code>.  Again this may be different for you, depending on how your installation is set up.  Once this started I went to go get myself some tea, because this was going to take a bit (although not as long as moving all those files over).</li>
<li>Now that the database file has been &#8220;fixed&#8221; you&#8217;re ready to import the database.
<ol>
<li>Go into MySQL&#8217;s commandline and drop the existing mdid2 database: <code>drop database mdid2;</code></li>
<li>Recreate the mdid2 database: <code>create database mdid2;</code> The reason you just destroyed and recreated the database was because the database has structure and data attached to it based on the work you did in step 1, you want to overwrite that.</li>
<li>import the mysql database by going to Window&#8217;s commandline and doing: <code>mysql -u mdid2 -p mdid2 &lt; mdid2export.sql</code></li>
</ol>
</li>
<li>This step is key to avoiding any indexing weirdness you may see.  Trust me, I did these steps multiple times before finally figuring this out (thanks to the mdid listserv).  You&#8217;ll need to go in and delete all instances of the _ftindex directory in the image directory.  Go through <em>each and every directory in the mdid2/image directory</em> to get rid of this folder.  If you don&#8217;t you&#8217;ll find some weirdness in the indexing of data.  Don&#8217;t worry this directory will be rebuilt once you start up mdid2.</li>
<li>Start up IIS and wait a bit for the full text index to finish up.  If you want, you can log in to your newly migrated MDID2 and click background transactions to see if the indexing process is still running (it should be the second thing in the list).</li>
<li>Last but certainly not least, have your Visual Resources Curator check the system over and give their stamp of approval.  Without that, you might as well be dead in the water.</li>
</ol>
<p>Like I stated above, this is the process that I followed.  Everyone&#8217;s systems are set up differently, but hopefully this can act as a guide of sorts to whatever poor schmuck needs to do something similar (ie me&#8230;so I don&#8217;t forget like I always seem to).</p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save">Share/Save</a> </p>]]></content:encoded>
			<wfw:commentRss>http://rosalynmetz.com/ideas/2010/01/25/migrating-mdid2-to-a-new-windows-server/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Why Moodle Keeps Going Down</title>
		<link>http://rosalynmetz.com/ideas/2009/09/02/why-moodle-keeps-going-down/</link>
		<comments>http://rosalynmetz.com/ideas/2009/09/02/why-moodle-keeps-going-down/#comments</comments>
		<pubDate>Wed, 02 Sep 2009 05:35:22 +0000</pubDate>
		<dc:creator>Rosalyn Metz</dc:creator>
				<category><![CDATA[Work]]></category>
		<category><![CDATA[Moodle]]></category>
		<category><![CDATA[MySQL]]></category>

		<guid isPermaLink="false">http://rosalynmetz.com/ideas/?p=690</guid>
		<description><![CDATA[For those of you that aren&#8217;t Systems Administrators, here is the reason you don&#8217;t want to be.  At 12:30am when things go down, you have to wake up and figure out why.  And here I am writing a blog post about it.  Luckily its not 4am.  That was totally worse (I say this now&#8230;let&#8217;s see [...]]]></description>
			<content:encoded><![CDATA[<p>For those of you that aren&#8217;t Systems Administrators, here is the reason you don&#8217;t want to be.  At 12:30am when things go down, you have to wake up and figure out why.  And here I am writing a blog post about it.  Luckily its not 4am.  That was totally worse (I say this now&#8230;let&#8217;s see how long it takes me to figure this stuff out).</p>
<p>So I got my text message at 12:30am.  It confused me but then I woke up a bit.  It was a good thing I wrote the notes I did in my previous post, because trust me, I could have never come up with that stuff on my own right now.</p>
<p>First thing I did was run top.  CPU was at 100.1% (way to work hard server) for the mysqld process.  Second thing I did was check the slow query log.  There were actually a few slow queries, the first ones are still puzzling me.  Basically these were checking a table that had a whole lot of rows of data, the data didn&#8217;t need to be stored in those tables, i removed the data, and I stopped logging that data in the tables.  I probably won&#8217;t see those queries ever again. But this doesn&#8217;t really matter, those queries weren&#8217;t the ones hanging up the system, they were only take 11 t0 17 seconds to run.</p>
<p>I did see the last query that ran though, and this seems to be part of the problem, but not the query that was actually causing mysqld to hang. This query was:</p>
<blockquote><p>INSERT INTO stats_daily (stattype, timeend, courseid, roleid, stat1, stat2)</p>
<p>SELECT &#8216;enrolments&#8217;, timeend, courseid, roleid, COUNT(DISTINCT userid), 0<br />
FROM (<br />
SELECT 1251691200 AS timeend, pl.courseid, pl.roleid, pl.userid<br />
FROM (<br />
SELECT DISTINCT ra.roleid, ra.userid, c.id as courseid<br />
FROM role_assignments ra JOIN context ctx<br />
ON ctx.id = ra.contextid<br />
CROSS JOIN course c<br />
JOIN role_capabilities rc<br />
ON rc.roleid = ra.roleid LEFT OUTER JOIN course_categories cc1<br />
ON cc1.id = c.category<br />
WHERE ((rc.capability = &#8216;moodle/course:view&#8217; )<br />
AND rc.permission = 1 AND rc.contextid = 1<br />
AND (ctx.contextlevel = 10<br />
OR (c.id = ctx.instanceid AND ctx.contextlevel = 50) OR (cc1.id = ctx.instanceid AND ctx.contextlevel = 40)))<br />
) pl<br />
) inline_view<br />
GROUP BY timeend, courseid, roleid;</p></blockquote>
<p>This query took a total of 41 seconds to execute.  I&#8217;m assuming that the next query after this was the one that brought the house down.  I saw the beginning of this when I went into mysql and did a show processlist:</p>
<blockquote><p>+&#8212;&#8212;-+&#8212;&#8212;&#8212;&#8212;+&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;&#8211;+&#8212;&#8212;&#8212;+&#8212;&#8212;+&#8212;&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;+<br />
| Id    | User       | Host      | db     | Command | Time | State        | Info                                                                                                 |<br />
+&#8212;&#8212;-+&#8212;&#8212;&#8212;&#8212;+&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;&#8211;+&#8212;&#8212;&#8212;+&#8212;&#8212;+&#8212;&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;+<br />
| 45654 | moodleuser | localhost | moodle | Query   | 1776 | Sending data | UPDATE stats_daily<br />
SET stat2 = (SELECT COUNT(DISTINCT ra.userid)<br />
|</p></blockquote>
<p>The full query finally showed up in my query log once I killed the process.  Here it is in case you&#8217;re curious:</p>
<blockquote><p>090902  0:01:29      45654 Query       UPDATE stats_daily<br />
SET stat2 = (SELECT COUNT(DISTINCT ra.userid)<br />
FROM role_assignments ra JOIN context ctx<br />
ON ctx.id = ra.contextid<br />
CROSS JOIN course c<br />
JOIN role_capabilities rc<br />
ON rc.roleid = ra.roleid LEFT OUTER JOIN course_categories cc1<br />
ON cc1.id = c.category<br />
WHERE ra.roleid = stats_daily.roleid AND<br />
c.id = stats_daily.courseid AND<br />
((rc.capability = &#8216;moodle/course:view&#8217; )<br />
AND rc.permission = 1 AND rc.contextid = 1<br />
AND (ctx.contextlevel = 10<br />
OR (c.id = ctx.instanceid AND ctx.contextlevel = 50) OR (cc1.id = ctx.instanceid AND ctx.contextlevel = 40))) AND<br />
EXISTS (SELECT &#8216;x&#8217;<br />
FROM log l<br />
WHERE l.course = stats_daily.courseid AND<br />
l.userid = ra.userid AND l.time &gt;= 1251604800  AND l.time  &lt; 1251691200))<br />
WHERE stats_daily.stattype = &#8216;enrolments&#8217; AND<br />
stats_daily.timeend = 1251691200 AND<br />
stats_daily.courseid IN<br />
(SELECT DISTINCT l.course<br />
FROM log l<br />
WHERE l.time &gt;= 1251604800  AND l.time  &lt; 1251691200)</p></blockquote>
<p>I also saw a whole bunch of other queries locked, waiting for this query to run.  I thought that perhaps switching the tables over to InnoDB rather than MyISAM might help alleviate the problem, but the truth is this appears to be a &#8220;the query is just ridiculous&#8221; problem rather than a &#8220;InnoDB is better at performance&#8221; problem.</p>
<p>So at anyrate I looked around and it seems this is a problem with the stats that Moodle keeps about itself.  Apparently in version 1.6 people had this problem a lot (because stats was new).  Basically I enabled stats because someone thought it was a good idea and I didn&#8217;t bother to consider how resource intensive this process could be (note to self: be a better sys admin and read documentation when someone thinks something might be useful).  I changed some settings in the stats configuration page and hope that this reduces the load and processing time of the stats query.  We&#8217;ll see if this fixes my problem.</p>
<p>Also, the amount of time I spent on this right now totally makes up for leaving work an hour and a half early to go meet my brother in law the electrician so he could replace outlets and light fixtures (my $12 sconces from lowes look quite lovely).</p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save">Share/Save</a> </p>]]></content:encoded>
			<wfw:commentRss>http://rosalynmetz.com/ideas/2009/09/02/why-moodle-keeps-going-down/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Moodle&#8217;s MySQL Keeps Going Down</title>
		<link>http://rosalynmetz.com/ideas/2009/08/31/moodles-mysql-keeps-going-down/</link>
		<comments>http://rosalynmetz.com/ideas/2009/08/31/moodles-mysql-keeps-going-down/#comments</comments>
		<pubDate>Mon, 31 Aug 2009 20:38:28 +0000</pubDate>
		<dc:creator>Rosalyn Metz</dc:creator>
				<category><![CDATA[Work]]></category>
		<category><![CDATA[Moodle]]></category>
		<category><![CDATA[MySQL]]></category>

		<guid isPermaLink="false">http://rosalynmetz.com/ideas/?p=687</guid>
		<description><![CDATA[If you&#8217;re not interested in Moodle or troubleshooting MySQL problems, than you probably don&#8217;t want to read this post.  I however wanted to write some notes for myself and need it to be portable.  Since that&#8217;s technically the purpose of this blog, I figured I should put it here. Recently Nagios started informing me that [...]]]></description>
			<content:encoded><![CDATA[<p>If you&#8217;re not interested in Moodle or troubleshooting MySQL problems, than you probably don&#8217;t want to read this post.  I however wanted to write some notes for myself and need it to be portable.  Since that&#8217;s technically the purpose of this blog, I figured I should put it here.</p>
<p>Recently Nagios started informing me that HTTPS was going down infrequently (but started to become more frequent).</p>
<blockquote><p><em>***** Nagios  *****<br />
Notification Type: PROBLEM<br />
Service: HTTPS<br />
Host: Moodle Server<br />
Address: 123.456.78.912<br />
State: CRITICAL<br />
Date/Time: Fri Aug 28 01:06:50 EDT 2009<br />
Additional Info:<br />
CRITICAL &#8211; Socket timeout after 10 seconds</em></p></blockquote>
<p>What was strange was that HTTP wasn&#8217;t going down.  I felt like Nagios was lying to me so I figured I would have to wake up late at night (early in the morning?) and catch it lying to me.  To do this I decided I&#8217;d try to figure out if my cellphone had an <a href="http://www.tech-recipes.com/rx/939/sms_email_cingular_nextel_sprint_tmobile_verizon_virgin/">email to associate to text messaging</a>.  Mine wasn&#8217;t working so I had to talk to Sprint about it.</p>
<p>In the mean time though, it was still going down.  Luckily last night at 4am I randomly woke up. I ran downstairs (imagine kid at Christmas&#8230;but like a reverse Christmas) and fired up the laptop.  Sure enough when I went to the Moodle homepage I saw this:</p>
<blockquote><p><em>Error: Database connection failed.</em></p>
<p><em> It is possible that the database is overloaded or otherwise not running properly.</em></p>
<p><em> The site administrator should also check that the database details have been correctly specified in config.php</em></p></blockquote>
<p>Now in hindsight, there were so many things I could have done at this point.  But it was 4am and my house was freezing so I made some mistakes.  The first thing I did was restart Apache.  It appeared to be running and the restart didn&#8217;t throw any errors, but it didn&#8217;t fix the problem either.  Next I &#8220;turned off SSL&#8221;.  I was able to get to the error page without the HTTPS so I determined at this point that Nagios clearly was lying to me, something else was wrong (p.s. i am thankful to Nagios for telling me that something was wrong).  So then I decided that maybe it was a database problem.  I went into MySQL and was able to access the Moodle database and do a &#8220;show tables;&#8221;.  So I thought at that point I should restart MySQL, in hindsight there are so many other things I should have done first, but I will document those below.  A restart of MySQL fixed the issue.</p>
<p>So what will I do next time (and yes&#8230;there will be a next time):</p>
<p style="padding-left: 30px;"><em><strong>1) run top on the server:</strong></em> See if MySQL is hogging the CPU.  This could lead you to a number of options.</p>
<p style="padding-left: 30px;"><em><strong>2) </strong></em><em><strong>check the mysql-slow-queries.log:</strong></em> I set up the <a href="http://dev.mysql.com/doc/refman/5.0/en/slow-query-log.html">mysql option log-slow-queries</a>.  this in conjunction with the <a href="http://dev.mysql.com/doc/refman/5.0/en/server-system-variables.html#sysvar_long_query_time">long-query-time option</a> will log any query that takes over a certain amount of time (default is 10s).</p>
<p style="padding-left: 30px;"><em><strong>3) </strong></em><em><strong>show mysql processlist:</strong></em> If you haven&#8217;t set up the log slow queries option this might also be helpful in determining what mysql is doing.  Here is a brief explaination of <a href="http://dev.mysql.com/doc/refman/5.0/en/show-processlist.html">show processlist</a> and its companion of <a href="http://dev.mysql.com/doc/refman/5.0/en/kill.html">kill &lt;processid&gt;</a>.  I also found this handy script that you could set up as part of a cron to <a href="http://forge.mysql.com/tools/tool.php?id=228">kill any runaway processes</a>.</p>
<p style="padding-left: 30px;"><em><strong>4) </strong></em><em><strong>query is poorly written:</strong></em> I&#8217;ve found a number of reports that MySQL queries are poorly written in Moodle and that these can cause the CPU usage to top out at %100 which causes Moodle to be unusable.  Below are a few Moodle Tracker reports of this:</p>
<blockquote>
<ul style="padding-left: 30px;">
<li><a href="http://tracker.moodle.org/browse/MDL-14911">http://tracker.moodle.org/browse/MDL-14911</a></li>
<li><a href="http://tracker.moodle.org/browse/MDL-19584">http://tracker.moodle.org/browse/MDL-19584</a></li>
<li><a href="http://tracker.moodle.org/browse/MDL-17051">http://tracker.moodle.org/browse/MDL-17051</a></li>
<li><a href="http://tracker.moodle.org/browse/MDL-10848">http://tracker.moodle.org/browse/MDL-10848</a></li>
</ul>
</blockquote>
<p style="padding-left: 30px;">To see if this is the case with your Moodle use the slow query logging (or just the plain old query logging) with a backup of your database to see if you can replicate the problem somewhere else.  If you can the problem is probably the query and maybe you can figure out a way to rewrite the query (or get it rewritten) to see if that fixes the problem.</p>
<p style="padding-left: 30px;"><em><strong>5) check your persistent db connection:</strong></em> Check to see if you have persistent database connections set up in the Moodle config.php file and in the php.ini file.  If you do, turn it off and see if this solves the problem.  it may be that your connections aren&#8217;t closing and they are killing your database regularly.</p>
<p style="padding-left: 30px;"><em><strong>6) check your max connections:</strong></em> Are the maximum number of Apache connections greater than your maximum number of MySQL connections?  If so that <a href="http://moodle.org/mod/forum/discuss.php?d=30603#p370708">might be a problem</a>.  Basically users could get to the website but then when they go to request something in the database they can&#8217;t because the # of connections are taken up.  I have a feeling though that this may be a completely different error than what I was experiencing (people&#8230;including myself&#8230;really need to take screenshots or document errors better).</p>
<p style="padding-left: 30px;"><em><strong>7) check your MySQL performance:</strong></em> Perhaps you haven&#8217;t configured Moodle right.  Take a look at these <a href="http://docs.moodle.org/en/Performance#MySQL_performance">performance tuning tips</a> to see if you can get it working better.</p>
<p style="padding-left: 30px;"><em><strong>8) check your database tables:</strong></em> Stop mysqld and run a check on your Moodle tables.  See if some of the tables are corrupted, if they are fix them.</p>
<p>So if you&#8217;re wondering what I&#8217;m doing at 4am tomorrow, there&#8217;s the list.  Wish me luck.</p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save">Share/Save</a> </p>]]></content:encoded>
			<wfw:commentRss>http://rosalynmetz.com/ideas/2009/08/31/moodles-mysql-keeps-going-down/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Moodle Enrollment: Flat Files</title>
		<link>http://rosalynmetz.com/ideas/2009/06/17/moodle-enrollment-flat-files/</link>
		<comments>http://rosalynmetz.com/ideas/2009/06/17/moodle-enrollment-flat-files/#comments</comments>
		<pubDate>Wed, 17 Jun 2009 20:57:20 +0000</pubDate>
		<dc:creator>Rosalyn Metz</dc:creator>
				<category><![CDATA[Work]]></category>
		<category><![CDATA[Moodle]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://rosalynmetz.com/ideas/?p=622</guid>
		<description><![CDATA[Currently we are using the LMB Plugin for Moodle to enroll students into our courses.  This works swimmingly, until you have to enroll a large group into a class that really isn&#8217;t a class.  Let me explain&#8230;no let me sum up. We have a bunch of placement tests and advising courses and that sort of [...]]]></description>
			<content:encoded><![CDATA[<p>Currently we are using the LMB Plugin for Moodle to enroll students into our courses.  This works swimmingly, until you have to enroll a large group into a class that really isn&#8217;t a class.  Let me explain&#8230;no let me sum up.</p>
<p>We have a bunch of placement tests and advising courses and that sort of thing we want our first year students to be enrolled in.  Moodle happens to have a flat file enrollment feature.  Below are the instructions from that enrollment feature:</p>
<blockquote><p>This method will repeatedly check for and process a specially-formatted text file in the location that you specify. The file is a comma separated file assumed to have four or six fields per line:</p>
<pre>*  operation, role, idnumber(user), idnumber(course) [, starttime, endtime]
where:
*  operation        = add | del
*  role             = student | teacher | teacheredit
*  idnumber(user)   = idnumber in the user table NB not id
*  idnumber(course) = idnumber in the course table NB not id
*  starttime        = start time (in seconds since epoch) - optional
*  endtime          = end time (in seconds since epoch) - optional</pre>
<p>It could look something like this:</p>
<pre>   add, student, 5, CF101
   add, teacher, 6, CF101
   add, teacheredit, 7, CF101
   del, student, 8, CF101
   del, student, 17, CF101
   add, student, 21, CF101, 1091115000, 1091215000</pre>
</blockquote>
<p>So great, I need to pull a randomly generated number rather than a username in order to enroll students.  So now I need to figure out a way to take a list of usernames in banner and get their corresponding idnumbers in Moodle.</p>
<p>Now if this were a one time thing I would take the lazy man&#8217;s way out and I would create a table in the database and do a simple</p>
<pre>select table.username, user.idnumber
from table, user
where table.username = user.username;</pre>
<p>But I&#8217;m going to have to do this every year until we either get rid of Moodle or I leave Wheaton.  Since plans are not in the work for either, I&#8217;ll actually do something more substantive.</p>
<p>First I made the decision to use the MySQL select in clause.  For those of you who don&#8217;t know, you can do:</p>
<pre>select username, idnumber
from user
where username in ('value1', 'value2', 'valueN');</pre>
<p>Its pretty useful really.  I can&#8217;t really find a MySQL page that talks about the in() clause but I did find a <a href="http://lists.mysql.com/internals/2077">good post in the MySQL lists</a>.  The next thing I had to figure out was how to push a file into a php array.  Again I found a <a href="http://www.phpbuilder.com/board/showthread.php?t=10365807">great post on using the file() </a>command to do this.  The only drawback is that when i go to print it&#8217;ll just show:</p>
<pre>value1 value2 valueN</pre>
<p>When that&#8217;s not what I want.  I need quotes and commas and crap around it.  So I found another great post that talks about <a href="http://bytes.com/topic/mysql/answers/854031-pass-php-array-into-mysql-clause">using the implode function to put a php array into an in() clause</a>.  The implode function will allow me to put quotes and what not around each one of the values in the array so it will look like this:</p>
<pre>'value1', 'value2', 'valueN'</pre>
<p>So now that I have the component parts, all I need to do is create a php page that will let me upload a file, run the query, and retrieve the outfile.  Of course the idea of writing this code makes me tired and since its 5pm I shall just publish this post and write the code tomorrow (hopefully).</p>
<p><em><strong>UPDATE</strong></em></p>
<p>I was wrong.  The value is not a randomly generated number, well it is, but its randomly generated by Banner.  In the Banner XML the value is the &lt;sourcedid&gt; for a &lt;person&gt;.</p>
<p>Luckily this randomly generated value is something that we can pull out of Banner using our reporting system.  The value (in our Banner) is <em>gobsrid_sourced_id</em>.  Not sure if it will be the same in your Banner, but hopefully this will put someone on the right track.</p>
<p>My next step is to document how to do all of this in our Moodle Documentation Wiki.  I might do a Jing Video.</p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save">Share/Save</a> </p>]]></content:encoded>
			<wfw:commentRss>http://rosalynmetz.com/ideas/2009/06/17/moodle-enrollment-flat-files/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Resetting a MediaWiki Password</title>
		<link>http://rosalynmetz.com/ideas/2009/02/17/resetting-a-mediawiki-password/</link>
		<comments>http://rosalynmetz.com/ideas/2009/02/17/resetting-a-mediawiki-password/#comments</comments>
		<pubDate>Tue, 17 Feb 2009 19:49:29 +0000</pubDate>
		<dc:creator>Rosalyn Metz</dc:creator>
				<category><![CDATA[Work]]></category>
		<category><![CDATA[MediaWiki]]></category>
		<category><![CDATA[MySQL]]></category>

		<guid isPermaLink="false">http://rosalynmetz.com/ideas/?p=456</guid>
		<description><![CDATA[If you forgot your MediaWiki password, you&#8217;ll want to reset it.  If you can, go to the login page and have the password sent to you, this is of course the easiest thing to do. Sometimes though, you&#8217;re a stupid Sys Admin (read me) and you set up a wiki real quick and think &#8220;I [...]]]></description>
			<content:encoded><![CDATA[<p>If you forgot your MediaWiki password, you&#8217;ll want to reset it.  If you can, go to the login page and have the password sent to you, this is of course the easiest thing to do.</p>
<p>Sometimes though, you&#8217;re a stupid Sys Admin (read me) and you set up a wiki real quick and think &#8220;I won&#8217;t forget the password!&#8221;.  You then decide <strong>not</strong> to include your email address when creating the wiki account profile.  So if you&#8217;re that Sys Admin (read me) here are the instructions for retrieving that password:</p>
<ol>
<li>log on to mysql</li>
<li>type the following query:<br />
<blockquote><p><code>UPDATE user SET user_password = MD5(CONCAT(user_id, ‘-’, MD5(’newpassword‘))) WHERE user_id = uid</code></p></blockquote>
</li>
<li>go back to the MediaWiki page and log in.</li>
</ol>
<p>And next time don&#8217;t think you can remember a password, you can barely remember your name.</p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save">Share/Save</a> </p>]]></content:encoded>
			<wfw:commentRss>http://rosalynmetz.com/ideas/2009/02/17/resetting-a-mediawiki-password/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Random Moodle</title>
		<link>http://rosalynmetz.com/ideas/2009/02/13/random-moodle/</link>
		<comments>http://rosalynmetz.com/ideas/2009/02/13/random-moodle/#comments</comments>
		<pubDate>Fri, 13 Feb 2009 15:24:29 +0000</pubDate>
		<dc:creator>Rosalyn Metz</dc:creator>
				<category><![CDATA[Work]]></category>
		<category><![CDATA[Mac OS X]]></category>
		<category><![CDATA[Moodle]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://rosalynmetz.com/ideas/?p=450</guid>
		<description><![CDATA[It&#8217;s been a while since I wrote, and its not that I forgot about my blog, it&#8217;s just that I&#8217;ve been busy.  Our Moodle installation is growing up and will be getting its own server soon.  I&#8217;m hoping that it&#8217;ll be a OSX 10.5 Server so I&#8217;ve been working out some of the kinks in [...]]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s been a while since I wrote, and its not that I forgot about my blog, it&#8217;s just that I&#8217;ve been busy.  Our Moodle installation is growing up and will be getting its own server soon.  I&#8217;m hoping that it&#8217;ll be a OSX 10.5 Server so I&#8217;ve been working out some of the kinks in my test installation:</p>
<ol>
<li>GD Library &#8212; By default the GD library&#8217;s aren&#8217;t part of the PHP package in Server 10.5.  I was poking around in this <a href="http://docs.moodle.org/en/Step_by_Step_Installation_on_a_Mac_OS_X_10.5_Server">Step by Step Installation guide</a> trying to upgrade my PHP library on my server.  Turns out I didn&#8217;t need to for various reasons (also the package recommended screwed with my Apache).  So instead i went into my php.ini file and uncommented the line:<br />
<blockquote><p>extension=php_gd2.dll</p></blockquote>
<p>This turned on the GD Library and Moodle looks much better now.</li>
<li>MySQL &#8212; I was getting a weird error in Moodle under Admin &gt; Server &gt; Environment.<br />
<blockquote><p>It is required that you store all your data in Unicode format (UTF-8). New installations must be performed into databases that have their default character set as Unicode. If you are upgrading, you should perform the UTF-8 migration process (see the Admin page).</p></blockquote>
<p>I thought that was a bit weird cause I installed the database from scratch. But sometimes you just need to do what it tells you to.  So I ran the following query:</p>
<blockquote><p><code>alter database moodle collate = utf8_unicode_ci;</code></p></blockquote>
<p>And voila the error went away.</li>
</ol>
<p>So now my Moodle is a bit happier.  I am of course (like always) recording this so that when I get my new server and I run into these problems again, I can remember what the heck I did.</p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save">Share/Save</a> </p>]]></content:encoded>
			<wfw:commentRss>http://rosalynmetz.com/ideas/2009/02/13/random-moodle/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Moving WordPress MU to a New Server</title>
		<link>http://rosalynmetz.com/ideas/2009/01/30/moving-wordpress-mu-to-a-new-server/</link>
		<comments>http://rosalynmetz.com/ideas/2009/01/30/moving-wordpress-mu-to-a-new-server/#comments</comments>
		<pubDate>Fri, 30 Jan 2009 22:55:31 +0000</pubDate>
		<dc:creator>Rosalyn Metz</dc:creator>
				<category><![CDATA[Work]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[WordpressMU]]></category>

		<guid isPermaLink="false">http://rosalynmetz.com/ideas/?p=430</guid>
		<description><![CDATA[I have a WordPress MU site that I wanted to move to a new server, and here&#8217;s how I did it.  I&#8217;m writing this because I did it once, and then forgot how to do it again.  I have a mind like a sieve. First I tarred up all the files for the directory: tar [...]]]></description>
			<content:encoded><![CDATA[<p>I have a WordPress MU site that I wanted to move to a new server, and here&#8217;s how I did it.  I&#8217;m writing this because I did it once, and then forgot how to do it again.  I have a mind like a sieve.</p>
<ol>
<li>First I tarred up all the files for the directory:<br />
<blockquote><p><code>tar cvzf wordpress.tgz wordpress/</code></p></blockquote>
<p>&nbsp;
</li>
<li>Then I backed up the mysql database:<br />
<blockquote><p><code>mysqldump -u root -p wordpress &gt; wordpress.sql</code></p></blockquote>
<p>&nbsp;
</li>
<li>When you back up a MySQL database it comes out as a simple text file.  You can open it up with a text editor (I have a mac and use TextWrangler).  I then use a simple find and replace in my text editor to find all the old URLs and replace them.  If you&#8217;re supper fancy you can use vi (which sometimes I do when I&#8217;m really really lazy and don&#8217;t want to go into a gui&#8230;yes I know that makes me a loser):<br />
<blockquote><p><code>:%s/old.url.com/new.url.com/g</code></p></blockquote>
<p>&nbsp;
</li>
<li>The next thing that I did was move the sql file and the tar file over to my new server.  I then created the database in mysql:<br />
<blockquote><p><code>create database wordpress;</code></p></blockquote>
<p>and then imported the mysql export file into the database that I just created:</p>
<blockquote><p><code>mysql -u root -p wordpress &lt; wordpress.sql</code></p></blockquote>
<p>Afterward, I double check that the database really is populated, but that&#8217;s because I&#8217;m a cautious person.  So I do a really quick:</p>
<blockquote><p><code>use wordpress;<br />
show tables;</code></p></blockquote>
<p>Before moving on.<br />
&nbsp;
</li>
<li>I then moved the tar file into the web directory and unzipped it:<br />
<blockquote><p><code>tar xvzf wordpress.tgz</code></p></blockquote>
<p>This will unzip all the files and create the wordpress directory.<br />
&nbsp;
</li>
<li>Finally you&#8217;ll want to go into your wp-config.php file and look at your database settings.  There is a section that reads:<br />
<blockquote><p><code>// ** MySQL settings ** //<br />
define('DB_NAME', 'wordpress');    // The name of the database<br />
define('DB_USER', 'wordpress');     // Your MySQL username<br />
define('DB_PASSWORD', 'wordpress'); // ...and password<br />
define('DB_HOST', 'localhost');    // 99% chance you won't need to change this value<br />
define('DB_CHARSET', 'utf8');<br />
define('DB_COLLATE', '');<br />
define('VHOST', 'no');<br />
$base = '/wordpress/';</code></p></blockquote>
<p>Using this information you&#8217;ll want to create a MySQL user according to this information (or you can create any old user and change these values in the wp-config.php file).  The MySQL query to create the user referenced above is:</p>
<blockquote><p><code>grant all privileges on wordpress.* to 'wordpress'@'localhost' identified by 'wordpress';</code></p></blockquote>
<p>So now you have created the same wordpress user that you had on your other wordpressmu site.<br />
&nbsp;
</li>
<li>At this point I like to double check that everything worked as planned.  You&#8217;ll want to go to your new URL and make sure that everything that was there before is there now.  Also tip:  don&#8217;t delete the old wordpressmu site until you&#8217;re certain the new one is working properly.</li>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save">Share/Save</a> </p>]]></content:encoded>
			<wfw:commentRss>http://rosalynmetz.com/ideas/2009/01/30/moving-wordpress-mu-to-a-new-server/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Making Moodle Courses Not Enrollable</title>
		<link>http://rosalynmetz.com/ideas/2008/12/23/making-moodle-courses-not-enrollable/</link>
		<comments>http://rosalynmetz.com/ideas/2008/12/23/making-moodle-courses-not-enrollable/#comments</comments>
		<pubDate>Tue, 23 Dec 2008 15:52:13 +0000</pubDate>
		<dc:creator>Rosalyn Metz</dc:creator>
				<category><![CDATA[Work]]></category>
		<category><![CDATA[Moodle]]></category>
		<category><![CDATA[MySQL]]></category>

		<guid isPermaLink="false">http://rosalynmetz.com/ideas/?p=285</guid>
		<description><![CDATA[What?!? Rosalyn what the heck are you talking about. I know, I know, my blog&#8217;s tag cloud is becoming Moodle heavy. Its true. But the boss man thinks that students shouldn&#8217;t be able to enroll themselves into any Moodle class at the drop of a hat. Sadly this makes sense (professors can be very protective [...]]]></description>
			<content:encoded><![CDATA[<p><em>What?!? Rosalyn what the heck are you talking about.</em></p>
<p>I know, I know, my blog&#8217;s tag cloud is becoming Moodle heavy.  Its true.  But the boss man thinks that students shouldn&#8217;t be able to enroll themselves into any Moodle class at the drop of a hat.  Sadly this makes sense (professors can be very protective of their class information because often times it informs their research).  Sigh.  So I&#8217;m off to make this happen.</p>
<p>So I&#8217;ve come up with a few ideas:</p>
<ol>
<li>I can just run a MySQL query every month:<br />
<blockquote><p><code>update course set enrollable = 0;</code></p></blockquote>
<p>While yes this will work, how much of a pain will that be.  I guess I could create a little script to do it for me.  But honestly that&#8217;s not a solution that&#8217;s a patch.</li>
<li>I can try going into moodle/course/edit_form.php and find the line:<br />
<blockquote><p><code>$mform-&gt;setDefault('enrollable', 1);</code></p></blockquote>
<p>And change it to:</p>
<blockquote><p><code>$mform-&gt;setDefault('enrollable', 0);</code></p></blockquote>
<p><em>Wow Rosalyn you&#8217;re genius!</em> Yeah, no, I&#8217;m not I just found that in the <a href="http://moodle.org/mod/forum/discuss.php?d=103018">Moodle Enrollment Plugins forum</a>.  A guy named Michael Skwara came up with it.  So I tried it out.  Unfortunately it doesn&#8217;t effect (or is that affect) courses I create using the LMB Enrollment Plugin.  You can still enroll yourself into those.  Darn it!  Foiled again.</li>
<li>Just change the database schema (<em>oh yeah rosalyn&#8230;like that&#8217;s just so easy)</em>.  I took a look in MySQL and the default for that column is set to 1, so if I set it to 0 perhaps that will make all new courses created with LMB default to <em><strong>not</strong></em> enrollable.  Of course I&#8217;m assuming that LMB doesn&#8217;t really update things like the enrollable field in the course table (I mean where would it get that information).  So I set about testing my theory.<br />
First things first, I asked <a href="http://moodle.org/mod/forum/discuss.php?d=103018">in the forum I referenced above</a> if anyone saw a problem with what I was about to do before I did it.  One of the Moodlers, Iñaki Arenaza, said that there shouldn&#8217;t be any problem with this.  Which is what I suspected, unless of course Moodle goes crazy and revamps their DB schema&#8230;which would cause me other headaches.So on to my next portion of the testing, does LMB update the field enrollable or does it just leave it alone.  So I installed a fresh Moodle (including the LMB plugin).  From there I logged into the MySQL and changed the default value for the column enrollable by running the query:</p>
<blockquote><p><code>alter table course alter column enrollable set default 0;</code></p></blockquote>
<p>Your query might be different if you are using a prefix for your Moodle tables. I then ran an import using the LMB plug in.  After that had finished I logged in using LDAP and tried to enroll myself in a course.  And lo and behold I received the message:</p>
<blockquote><p>This course is not enrollable at the moment.</p></blockquote>
<p>SUCCESS!  So students who aren&#8217;t attached to the course in Banner, can&#8217;t attach themselves to the course in Moodle.  Professors however can still go in and add students (or delete students) from a course the way they did before.</li>
</ol>
<p>So that&#8217;s my foyer into the world of altering the Moodle database schema in order to make the boss man happy.  My next step is to upgrade Moodle so I can take advantage of the fun new features.</p>
<h2><em><strong>UPDATE</strong></em></h2>
<p>I noticed a few people have visited this post recently.  While this fixed worked for me I recommend that you <em><strong>TEST IT OUT FIRST</strong></em>.</p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save">Share/Save</a> </p>]]></content:encoded>
			<wfw:commentRss>http://rosalynmetz.com/ideas/2008/12/23/making-moodle-courses-not-enrollable/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Upgrading Moodle</title>
		<link>http://rosalynmetz.com/ideas/2008/12/16/upgrading-moodle/</link>
		<comments>http://rosalynmetz.com/ideas/2008/12/16/upgrading-moodle/#comments</comments>
		<pubDate>Tue, 16 Dec 2008 21:57:55 +0000</pubDate>
		<dc:creator>Rosalyn Metz</dc:creator>
				<category><![CDATA[Work]]></category>
		<category><![CDATA[Moodle]]></category>
		<category><![CDATA[MySQL]]></category>

		<guid isPermaLink="false">http://rosalynmetz.com/ideas/?p=278</guid>
		<description><![CDATA[I just decided to upgrade Moodle since one of my action items was &#8220;Remove the Percentage Column for Outcomes in the gradebook.&#8221;  Luckily I sat on this task long enough and lo and behold, the Moodle community did this for me (note to self, try to be more proactive and put things in Moodle Tracker). [...]]]></description>
			<content:encoded><![CDATA[<p>I just decided to upgrade Moodle since one of my action items was &#8220;Remove the Percentage Column for Outcomes in the gradebook.&#8221;  Luckily I sat on this task long enough and lo and behold, the Moodle community did this for me (note to self, try to be more proactive and put things in Moodle Tracker).</p>
<p>So at any rate, I decided to upgrade Moodle.  Here are the steps I have outlined for doing an upgrade such as this:</p>
<ol>
<li><strong>Read the directions on the Moodle Documentation site.</strong> These are most useful.  <a href="http://docs.moodle.org/en/Upgrading">http://docs.moodle.org/en/Upgrading</a>.  Keep in mind that there may be directions specific for your installation or the version that you&#8217;re upgrading too.  Which brings me to an excellent point, don&#8217;t just follow directions you find on the internet blindly, INVESTIGATE!</li>
<li><strong>Create a back up of the MySQL database.</strong> Also outlined in the upgrading documentation, but putting it in for good measure.  I just ran the following command:<br />
<blockquote><p><code>mysqldump -u username -p -C -Q -e -a moodle &gt; moodle-backup.sql</code></p></blockquote>
<p>Again this command is outlined in the upgrading Moodle documentation, but since these are my notes&#8230;I&#8217;m putting it here</li>
<li><strong>Create a list of the plugins you have installed. </strong>If you&#8217;re a good systems administrator, you should have all of this somewhere or other&#8230;right?  Well some of us don&#8217;t.  But you&#8217;re going to need this list to make sure that everything you&#8217;ve installed gets moved over after you unpacked the new Moodle you&#8217;re about to download and install.  Here at Wheaton, I&#8217;ve put it on an in house wiki.</li>
<li><strong>Move the moodle directory. </strong>The directions recommend moving and zipping up the directory.  I personally just move it and then if anything goes wrong I can move it back.  Once everything is said and done I&#8217;ll zip it up (and include the mysqldump in that zip file) and store it in the event that something goes wrong farther down the line.  To move the moodle directory:<br />
<blockquote><p><code>cd /your/web/directory/<br />
mv moodle moodle-bak</code></p></blockquote>
</li>
<li><strong>Download the Moodle zip file and unpack it in your web directory.</strong> The next thing you&#8217;ll want to do is <a href="http://download.moodle.org/">download the latest version of Moodle</a>.  Once you&#8217;ve done that move it to your web directory and unpack it.  This should create a Moodle directory.</li>
<li><strong>Move your config.php file from the moodle-bak directory into the moodle directory.</strong> This will essentially transfer your database, server, etc. information over to the new Moodle directory.  You&#8217;ll want to go to your Moodle homepage to check out that things went smoothly with this.  You&#8217;ll see a button asking you to update, but don&#8217;t update your Moodle at this point (you&#8217;re still not done).</li>
<li><strong>Copy all of your plugins and themes from the moodle-bak directory to the moodle directory.</strong> Make sure that when you do this that the correct permissions get moved over.  One way to do this is by using the -p flag.  This will ensure that the directory is copied over as well as the permissions:<br />
<blockquote><p><code>cp -pR /path/to/your/plugins /path/to/new/location</code></p></blockquote>
</li>
<li><strong>Visit the admin page for your Moodle and run the update.</strong> Your admin page is located at: http://server/moodle/admin.  When you get there you&#8217;ll click on a button and the script will update the database; it basically runs itself.  If there is any intervention you need to do, Moodle will let you know.</li>
<li><strong>Zip up the old Moodle database and file system.</strong> I like to keep these things lying around just in case.  You never know when you&#8217;ll want an old version of moodle to play with.</li>
</ol>
<p>Now that you&#8217;ve upgraded you should be a happy camper and get all of the cool new fun features that Moodle has to offer.</p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save">Share/Save</a> </p>]]></content:encoded>
			<wfw:commentRss>http://rosalynmetz.com/ideas/2008/12/16/upgrading-moodle/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Moving a MediaWiki</title>
		<link>http://rosalynmetz.com/ideas/2008/11/18/moving-a-mediawiki/</link>
		<comments>http://rosalynmetz.com/ideas/2008/11/18/moving-a-mediawiki/#comments</comments>
		<pubDate>Tue, 18 Nov 2008 16:23:34 +0000</pubDate>
		<dc:creator>Rosalyn Metz</dc:creator>
				<category><![CDATA[Work]]></category>
		<category><![CDATA[MediaWiki]]></category>
		<category><![CDATA[MySQL]]></category>

		<guid isPermaLink="false">http://rosalynmetz.com/ideas/?p=198</guid>
		<description><![CDATA[I&#8217;m currently in the process of setting up a MediaWiki farm.  As I stated in my previous post on creating a MediaWiki farm, I have a number of already existing MediaWikis that I need to move into my MediaWiki farm. This post outlines the steps I followed in order to move those existing MediaWikis, into [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m currently in the process of setting up a MediaWiki farm.  As I stated in <a href="http://rosalynmetz.com/ideas/2008/11/14/making-a-mediawiki-farm/">my previous post on creating a MediaWiki farm</a>, I have a number of already existing MediaWikis that I need to move into my MediaWiki farm. This post outlines the steps I followed in order to move those existing MediaWikis, into my new farm.</p>
<p><strong>First a Bit of Research</strong></p>
<p>A number of people have posted that its just simply moving the LocalSettings.php file and image directory into the new directory, changing some words in the LocalSettings.php file and voila&#8230;it all works.  But this wasn&#8217;t the case for me.  I&#8217;m not sure if its because of the symlinks or what, but I was running into problems when I did this.</p>
<p>So I did a comparison between a moved wiki and a wiki created within the farm.  Interestingly enough the ones created in the farm were indicating that their $wgScriptPath was <code>/wikis/[wiki-name]</code>.  Now when I set up my MediaWiki, I didn&#8217;t put it at the web root, instead I put it in a containing directory called wikis (clever huh).  One reason I did this was because I had other things on the server beside MediaWiki (WordPressMU for one) and I didn&#8217;t want there to be any conflicts.</p>
<p>Another reason I did this was so that I could set up a DNS to point to the wikis directory.  So if you go to http://wikis.wheatoncollege.edu/domingo you&#8217;ll see a wiki that&#8217;s part of the farm but its not sitting at the root of a server called wikis.wheatoncollege.edu, its sitting at fred.wheatoncollege.edu/wikis.  So&#8230;</p>
<ul>
<li>wikis.wheatoncollege.edu = fred.wheatoncollege.edu/wikis</li>
<li>wikis.wheatoncollege.edu/domingo = fred.wheatoncollege.edu/wikis/domingo</li>
</ul>
<p>I digress&#8230;</p>
<p>So I couldn&#8217;t figure out why this change was happening (I&#8217;m sure it has something to do with symbolic links) and I honestly didn&#8217;t have time to try to figure it out, and besides the web interface install script nicely creates a LocalSettings.php file for you anyway, and no one did a lot (if any) customization for the wikis at my institution.  So why not just use the web based script?</p>
<p><strong>Backing Up a MediaWiki Database</strong></p>
<p>So at this point all I&#8217;m doing is really moving over the database.  I could (if I wanted to) not even move the database, I could just connect the current MediaWikis&#8217; databases to the new interface.  You can do this by entering in all the information that you used before into the web based install script.  But I don&#8217;t like the names my databases were given :) (ok that&#8217;s not the real reason&#8230;the real reason is so that i can keep the old ones running for a day without it affecting the new one)</p>
<p>So I did a MySQL backup:</p>
<blockquote><p><code>mysqldump -u [mysqlrootuser] -p[mysqlrootpassword] --add-drop-table -B &gt; [mysqldumpfile].sql</code></p></blockquote>
<p>Note that I&#8217;m using the <code>--add-drop-table</code> mysql option.  What does this do?  Well when I restore the database, it will look in the existing database and see if the tables already exist.  If they do, it&#8217;ll drop them and then re-add them.  If they don&#8217;t, it&#8217;ll just add them.  This means that essentially its wiping EVERYTHING in your database and replacing it with everything in your backup.  So if there is a table not in your backup that you want to keep&#8230;re-run your backup.  Or restore the tables one at a time (this is an option with MySQL).</p>
<p>Now I stated that I wanted to change my database&#8217;s names.  If I simply restored the database using:</p>
<blockquote><p><code>mysql -u [mysqlrootuser] -p[mysqlrootpassword] &lt; [mysqldumpfile].sql</code></p></blockquote>
<p>It would restore with the same name as before.  Now I thought if I ran this command:</p>
<blockquote><p><code>mysql -u [mysqlrootuser] -p[mysqlrootpassword] [newdbname] &lt; [mysqldumpfile].sql</code></p></blockquote>
<p>It would restore with a different database name, I was wrong.  I&#8217;m sure there is a way to do it from the commandline, but I&#8217;m in a hurry.  So I opened up the .sql file with TextWrangler (a Mac text editor) and found the database name (it occurs four times in the top part of the file) and changed it (much thanks to <a href="http://www.coloradocollege.edu/library/index.php/about/carol-ou">Carol Ou</a> for confirming I could do this).  If you do choose to go this route, make sure you have a backup of the .sql file before you edit it.</p>
<p>A couple of quick notes about doing a backup this way:</p>
<ol>
<li>before you restore the database, you&#8217;ll need to create the new database (with your new database name).  you can do that with a quick <code>create database [newname];</code> query.</li>
<li>once you restore the database, there will be no MySQL users associated with the database, but there will be MediaWiki users associated with the database.  A MediaWiki user <em><strong>does not</strong></em> equal a MySQL user.  One is so that you can go into the GUI and edit the wiki and the other is so that MediaWiki can write information to the database.  When you run the MediaWiki web install script, it will allow you to create MySQL users for the database.</li>
<li>after you restore the database do a quick <code>show tables;</code> query in MySQL to make sure the data was really restored.  doublechecking is always important.</li>
</ol>
<p><strong>Backing up the Images</strong></p>
<p>The last piece that you&#8217;ll want to remember to do is create a backup of the images.  This is simple enough to do, just tar and zip it all up:</p>
<blockquote><p><code>tar -cvzpf [backupname].tgz [wikidirectory]/images</code></p></blockquote>
<p>At this point you&#8217;ll have all of the images in a tarball ready to move into your new wiki&#8217;s image directory.</p>
<p><strong>Now On To Moving a MediaWiki into Your Farm<br />
</strong></p>
<p>Now that I have a backup of the database and a tarball of the images, I&#8217;m ready to move the MediaWiki over.  One thing to note, all my MediaWikis are the same version (yay).  If you have different MediaWiki versions, you&#8217;ll probably want to update them before doing the following steps.</p>
<ol>
<li>Create the directory the MediaWiki will live in under that wikis directory you set up (see above).</li>
<li>Restore the MySQL database as its new name.  You can do this by:<br />
<blockquote><p><code>mysql -u [mysqlrootuser] -p[mysqlrootpassword] [newdbname] &lt; [mysqldumpfile].sql</code></p></blockquote>
<p>Another thing to check is whether or not table prefixes were used when the MediaWiki was originally installed.  In my case, one of the MediaWikis did have prefixes; I checked this by running a simple <code>show tables;</code> query in MySQL.</li>
<li>Create the symbolic links for the MediaWiki.  You can use <a href="http://rosalynmetz.com/ideas/2008/11/14/making-a-mediawiki-farm/">my other post on creating a MediaWiki farm</a> if you&#8217;re not sure how to do this.  I&#8217;ve also created <a href="http://rosalynmetz.com/ideas/wp-content/linkedfiles/createwiki.txt">a script</a> that walks the liaisons here at Wheaton through creating the wiki.  Its works&#8230;but I could improve it and hopefully I&#8217;ll update the file when I do.</li>
<li>Move the untar the images directory that you tarred up before.  You&#8217;ll want to untar it in the MediaWiki&#8217;s directory.  Doing this will move all the images over to the new wiki.</li>
<li>Once you create the symbolic links, you&#8217;ll want to go to the web install script and run it.  This includes:
<ul>
<li>database name [the new one]</li>
<li>database username [you can create a new database user]</li>
<li>database password [again you can create a new one]</li>
<li>database prefix [only if you entered one for the previous incarnation of the wiki]</li>
<li>wiki admin and password [best to use the previous one...if you have it]</li>
</ul>
</li>
<li>Finish up the install by moving the LocalSettings.php file into the MediaWiki&#8217;s main directory, changing permission on the file, and deleting the config directory.</li>
<li>If the LocalSettings.php file was altered for any of the MediaWikis (in my case one was).  Go in and remake those changes.</li>
</ol>
<p>And voila! MediaWiki moved.</p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save">Share/Save</a> </p>]]></content:encoded>
			<wfw:commentRss>http://rosalynmetz.com/ideas/2008/11/18/moving-a-mediawiki/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
