tag:blogger.com,1999:blog-135173342024-02-16T02:06:28.492+00:00gilfsterAndrew Gilfrinhttp://www.blogger.com/profile/09929358844206555905noreply@blogger.comBlogger95125tag:blogger.com,1999:blog-13517334.post-23772039616733720172016-02-16T08:44:00.001+00:002016-02-16T08:44:12.870+00:00SQL Database Performance TuningIt's not often I get asked to share stuff and even less that I feel compelled to, but this is well worth reading.
<a href="http://www.toptal.com/sql/sql-database-tuning-for-developers">http://www.toptal.com/sql/sql-database-tuning-for-developers</a>Andrew Gilfrinhttp://www.blogger.com/profile/09929358844206555905noreply@blogger.com0tag:blogger.com,1999:blog-13517334.post-46214232620442973562012-07-05T09:37:00.002+00:002012-07-05T09:38:13.148+00:00Comments GoneWell seeing as I'm going to open this blog up again I figured I better come in and have a little clean up. Checking the comments it was obvious that most of the 1000+ comments were some form of spam so I decided that I'd clear then all out, including the good ones, sorry about that but I didn't have the time to read each one and decide what was worth keeping.
<br /><br />
It seems that the blog still gets a number of visitors even though it's not been updated in some considerable time. It's linked from a number of significant places and still rates reasonably well in Google.
<br /><br />
In the next few days I'll be writing something about my new Raspberry Pi computer, including setting up MySQL.Andrew Gilfrinhttp://www.blogger.com/profile/09929358844206555905noreply@blogger.com2tag:blogger.com,1999:blog-13517334.post-83681818260961850022012-07-03T17:17:00.001+00:002012-07-03T17:17:24.616+00:00It's as if I never went awayIt's been getting on for 3 years since I updated this blog and more like 6 since I regularly added to it. It's actually pretty amazing that in that time it's still prettying relevant and useful, that's not something you could have said in my first 6 years in the IT industry back in the late 90's.<br /><br />I'm writing this sitting on a train, it will take me a couple of minutes to update and post, something even back then that would have seemed pretty out there. But the last six years hasn't seen those same radical shifts in programming, what I wrote back at the start is still relevant today, let's hope that what I write in the following months stays around for as long. Andrew Gilfrinhttp://www.blogger.com/profile/09929358844206555905noreply@blogger.com0tag:blogger.com,1999:blog-13517334.post-81074667346162148932009-04-14T14:45:00.004+00:002009-04-15T09:24:53.286+00:00Generating "Random" Data using rand() and sub selectsI'm developing a demonstration site for new system we are about to unleash on the world, so far it's going great but one of the worst things about demo sites is the lack of real world data at hand. I don't want to give too much away but the site is vehicle sales based and I need to generate a bunch of data. The problem I needed to solve was that the table with the cars in didn't have associated dealer data and the pages looked very bare when there wasn't any as much of the data comes from the dealers table. <br /><br />I didn't fancy going in to the table and amending 165 cars by hand, but I also didn't want to run the update in blocks as I wanted an a pretty even spread of the different cars between the 12 dealers. Take for example this data set... <br /><br /><pre style="color:orange;"><br />mysql> select id, Make, dealer from cars_cars limit 5;<br /><br />+----+------------+-----------+<br />| id | Make | dealer |<br />+----+------------+-----------+<br />| 1 | Land Rover | Aldershot |<br />| 2 | Land Rover | |<br />| 3 | Land Rover | |<br />| 4 | Land Rover | |<br />| 5 | Land Rover | |<br />+----+------------+-----------+<br />5 rows in set (0.00 sec)<br /></pre> <br /><br />Only one of the vehicles has a dealer attached. What I want is to populate that dealer column with a real dealer. <br /><br />I always run updates in select mode first, to see what the final out put is like. First I want a way to get a random dealer, we can use rand() in the order by to generate a random number which MySQL will sort on. <br /><br /><pre style="color:orange;"><br />mysql> select name from cars_dealers <br /> order by rand() limit 1;<br />+------------+<br />| name |<br />+------------+<br />| Birmingham |<br />+------------+<br />1 row in set (0.00 sec)<br /><br />mysql> select name from cars_dealers <br /> order by rand() limit 1;<br />+--------+<br />| name |<br />+--------+<br />| Oldham |<br />+--------+<br />1 row in set (0.00 sec)<br /></pre><br /><br />Now I can include that in my original select like so...<br /><br /><pre style="color:orange;"><br />mysql> select id, Make, <br /> (select name from cars_dealers <br /> order by rand() limit 1) as dealer <br /> from cars_cars limit 5;<br />+----+------------+-------------+<br />| id | Make | dealer |<br />+----+------------+-------------+<br />| 1 | Land Rover | Oxford |<br />| 2 | Land Rover | Aldershot |<br />| 3 | Land Rover | Coventry |<br />| 4 | Land Rover | Southampton |<br />| 5 | Land Rover | Birmingham |<br />+----+------------+-------------+<br />5 rows in set (0.00 sec)<br /></pre><br /><br />Great, so I now have a random dealer against each vehicle, all I need now is to turn that into an update and we are good to go.<br /><br /><pre style="color:orange;"><br />mysql> update cars_cars <br /> set dealer = <br /> (select name from cars_dealers <br /> order by rand() limit 1)<br /> where id > 0;<br /><br />Query OK, 163 rows affected (0.01 sec)<br />Rows matched: 163 Changed: 163 Warnings: 0<br /></pre><br /><br />I now have "random" data in my table. I put random in quotes because it is random within a set range of values not totally random as in totally unpredictable. Just to prove it really did work.<br /><br /><pre style="color:orange;"><br />mysql> select id, Make, dealer from cars_cars limit 5;<br />+----+------------+---------------+<br />| id | Make | dealer |<br />+----+------------+---------------+<br />| 1 | Land Rover | Aldershot |<br />| 2 | Land Rover | Basingstoke |<br />| 3 | Land Rover | Wolverhampton |<br />| 4 | Land Rover | Aldershot |<br />| 5 | Land Rover | Wolverhampton |<br />+----+------------+---------------+<br />5 rows in set (0.00 sec)<br /></pre><br /><br />* I used where id > 0 because as mentioned in my previous post I have safe update mode turned on.Andrew Gilfrinhttp://www.blogger.com/profile/09929358844206555905noreply@blogger.com0tag:blogger.com,1999:blog-13517334.post-28344055019691155772009-04-09T14:29:00.003+00:002009-04-09T14:44:00.037+00:00I am a DummyWay back when I started this blog just under 4 years ago I wrote a post called 'An Oracle Developers Journey', in the early days the blog focused on the transition from Oracle to MySQL. The irony was that after a year or so professionally I move back the other way and for the last 3 years or so it's been all Oracle for me. <br /><br />We all make mistakes, I know I have made some massive ones in the past, some were saved by a decent back up others were not so easy to recover from. It's been a while since I made anything like a big mistake (certainly not one that was noticed ;), once bitten twice shy tends to make you think about the consequences a little more. <br /><br />But having now switched back to MySQL again I find myself really worried I'm going to make a mistake, in Oracle it's UPDATE/INSERT or more worryingly DELETE and then a COMMIT, but in MySQL (at least the way we are running it) there is no commit stage. I'm currently working on development systems but I just know that one day I'm going to delete or update something I really don't want to. <br /><br />Thankfully MySQL is clever enough to make up for my itchy delete finger and includes the --safe-updates startup option. But I love the alias which is --i-am-a-dummy. I'm man enough to admit to being a dummy, well at least prone to doing something dum from time to time and that's why the first thing I did when I switched back to MySQL was to include --i-am-a-dummy in my startup alias. <br /><br />So hands up who else is a dummy?<br /><br />p.s. if you don't know --safe-updates sets the following session system variables.<br /><br />SET sql_safe_updates=1, <br />sql_select_limit=1000, <br />sql_max_join_size=1000000;<br /><br />sql_safe_updates is the key as it stops you running an update or delete without some sort of where clause.Andrew Gilfrinhttp://www.blogger.com/profile/09929358844206555905noreply@blogger.com0tag:blogger.com,1999:blog-13517334.post-28933137904033232712009-03-26T10:17:00.003+00:002009-03-26T10:31:14.998+00:00Adventures in Web PerformanceI mentioned in my previous post that recently I have been working with web performance. Often when working with clients they want fast performing web sites but then proceed to give you all manner of other requirements which slow the site down to a crawl. Convincing a client to give you the time to look at performance isn't easy, while the gains in speed are there for all to see attributing some monetary value to that is close to impossible. In the longer term you might see an up turn in the traffic levels or a higher percentage of people taking a longer user journey on your site but whether that was a result of higher performance is very difficult to prove. <br /><br />Thankfully one of our larger clients could see the benefit of having a dedicated resource looking at performance issues, all be it as a result of such poor performance that the sites became difficult to use during peek times. When a client keeps throwing stuff at you it's easy to take your eye off the performance issue and one thing that became clear was that while the tendency was to blame the database many of the things we looked at were nothing to do with that area. <br /><br />Over the next few posts I'll discuss some of the things we looked at, how we did that and how we radically improved performance on some of our sites with some minimal changes.Andrew Gilfrinhttp://www.blogger.com/profile/09929358844206555905noreply@blogger.com0tag:blogger.com,1999:blog-13517334.post-17945213046484489722009-03-26T10:10:00.003+00:002009-03-26T10:16:50.486+00:00Such a long time....Wow, is it really that long since I updated this thing. I can't believe that it's been close to 3 years since I updated it regularly, but I suppose it is as I have been in my current job for that long and it was a transition from MySQL back to Oracle (and a lot more work) that meant I stopped posting in the first place. <br /><br />The good news is I'm moving back to working with MySQL after 3 years away and that should give me some more opportunities to update the blog. While there have been some highlights over the 3 years much of the work I have been doing has been maintenance and the normal daily grind of work so it didn't offer that much that was interesting. Of late I have been doing some really cool stuff with web performance but I've been out of the blogging for so long I never really thought about sharing it. <br /><br />Of course any regular readers will be long gone but the blog still ranks pretty high in Google so maybe some folks will stop by.Andrew Gilfrinhttp://www.blogger.com/profile/09929358844206555905noreply@blogger.com0tag:blogger.com,1999:blog-13517334.post-92156220618727310742007-06-22T09:30:00.000+00:002007-06-22T09:55:06.104+00:00MySQL on a PS3I work in IT for 2 reasons, firstly it pays well but secondly and most importantly it's fun. When I look back on jobs I had before I started working in IT, while it was never a problem getting up in the morning and the social aspects were great I would never have said that the job it self was fun.<br /><br />It's been sometime since I last updated the blog, 6 moths or so and almost a year since I did on anything like a regular basis, the main reason as I have mentioned in the past is that if you have nothing to say then why bother saying it. Therefore I doubt anybody is listening any longer, but I suppose that's not really an issue.<br /><br />I have been prompted to write because I have been doing some work on a site in MySQL, in the day job I use Oracle (but do some admin on MySQL sites from time to time) so I no longer have the experiences to blog about. But I recently needed to upgrade a family members web site which required some MySQL work. As it happens this coincided with a recent hardware upgrade, I used to have an X-Box 360 but it recently decided to die on me so I took the plunge to get a <span class="blsp-spelling-error" id="SPELLING_ERROR_0">Playstation</span> 3. As games consoles go it's pretty decent and with the addition of a Blue-Ray drive it means I can take full advantage of my new <span class="blsp-spelling-error" id="SPELLING_ERROR_1">HD</span> TV.<br /><br />Getting back to the point, Sony allow you to format the PS3 hard drive in such a way that it can have two operating systems, the standard console one and also Linux. The install process looked easy and given that Sony fully supports this I thought I would give it a go. The PS3 allows the connection of a <span class="blsp-spelling-error" id="SPELLING_ERROR_2">USB</span> Keyboard and mouse so it's easy enough to get going. The install was painless enough (if a little long winded) but once it was done I now had a PS3 running Linux, of course one of the first things I did was have a go at running MySQL which of course runs like a dream.<br /><br />So now my development machine is a Sony PS3 :)Andrew Gilfrinhttp://www.blogger.com/profile/09929358844206555905noreply@blogger.com0tag:blogger.com,1999:blog-13517334.post-1166617699914627282006-12-20T12:17:00.000+00:002006-12-20T12:28:20.003+00:00Mysqldevelopment.com emails are no more.When I transferred the content of mysqldevelopment.com over to the MySQL Forge site I always intended to continue updating this blog. Unfortunately due to work commitments I simply haven't had the time and because I haven't been working with MySQL so much I also haven't had the quality of content I once had. <br /><br />Rather unsurprisingly then I haven't been receiving much in the way of email to my email address andrew_gilfrin@mysqldevelopment.com. I have however been getting plenty of spam so I have decided to drop that email address, therefore if you wish to contact me you can do so at my hotmail address (andrew_gilfrin at homtail.com).Andrew Gilfrinhttp://www.blogger.com/profile/09929358844206555905noreply@blogger.com0tag:blogger.com,1999:blog-13517334.post-1153234531611361092006-07-18T14:45:00.000+00:002006-07-18T14:56:59.673+00:00Spotlight on MySQLOne of my "part time" roles is a sysop on the Quest MySQL Pipelines, as I have mentioned on here before we don't get many posts unfortunately and I can only assume that's because MySQL have such great forums of their own. <br /><br />Anyway, Quest produce a product called Spotlight on MySQL which is a <a href="http://www.quest.com/spotlight_on_mysql/visual_overview.html">rather cool looking</a> monitoring tool for MySQL. Personally I haven't had the chance to use it but the development team are currently looking for feedback on Spotlight on MySQL, with particular interest in if there is need for replication support.<br /><br />So if you have anything to add pop over to the forum and let the guys know in the Spotlight on MySQL section. <br /><br />http://pipetalk.quest-pipelines.com/default.asp?boardid=mysql<br /><br /><br />Andrew Gilfrinhttp://www.blogger.com/profile/09929358844206555905noreply@blogger.com0tag:blogger.com,1999:blog-13517334.post-1152723087879955022006-07-12T16:11:00.000+00:002006-07-12T16:52:18.436+00:00Regular Expressions in Oracle 10g - Part 1Before my current role I generally worked in a windows environment, I would occasionally copy a file or log on to a Unix box to does something only when absolutely necessary. But at my last job and this current one I have had to spend most of my time connected to a Unix server, for as long as I could I'd edit in Windows and copy across to do what I needed but it soon became apparent that I'd need to get with the times ;) and take the plunge into Unix. <br /><br />I have found Unix to be really powerful and it didn't take anywhere near as long to get used to vi as I feared. One of the things I have most useful is regular expression, now I know that they are available in Windows in various places but in all my time with computers I had only a minimal amount of exposure to them. <br /><br />This then leads on to today's blog, In Oracle 10g a number of new functions were introduced that allow you to search and update using regular expressions. Over the next few days I'll be looking at what can be done but lets start with some simple examples. Let's take the following data set.<br /><pre><br />SQL> select * from reg_test;<br /><br />VAL_1<br />------------------------------<br />My name is Andrew<br />My name is Dave<br />My name is dave<br />His name is dave<br />His name is dave.<br />He dave me andrew<br /></pre><br />Before 10g we had to use like to search on sections of a column, this wasn't necessarily a problem but often involved using other functions to format the data in a way that we could search on. For example lets say we wanted to get a count of all of the records with Dave at the end, including those which were upper or lower case. Using like we would do something like this.<br /><pre><br />SQL> select count(*) from reg_test <br /> where upper(val_1) like ('%DAVE');<br /><br /> COUNT(*)<br />----------<br /> 3<br /></pre><br />That's fine but it requires us to covert the whole of the val_1 to upper case so we can pick out the required fields. Also we have a count of 3 when realistically speaking we have 4, one of the rows has a full stop. We could to this..<br /><pre><br />SQL> select count(*) from reg_test <br /> where upper(val_1) like ('%DAVE%');<br /><br /> COUNT(*)<br />----------<br /> 5<br /></pre><br />Now we are getting 5, because we have added the second %. To get round this in 10g we can now use REGEXP_LIKE, this allows us to use regular expressions as the comparison. <br /><br />I'll assume some knowledge of regular expressions (given you possibly know more about them than I do). <br /><pre><br />SQL> select count(*) from reg_test <br /> where regexp_like(val_1,'[Dd]ave\.*$');<br /><br /> COUNT(*)<br />----------<br /> 4<br /></pre><br />This time we get the right result.Andrew Gilfrinhttp://www.blogger.com/profile/09929358844206555905noreply@blogger.com0tag:blogger.com,1999:blog-13517334.post-1152547660829013432006-07-10T15:56:00.000+00:002006-07-10T16:08:10.393+00:00Adventures in PHP and OracleRecently we have been asked to develop some of our future sites in PHP. Traditionally we have worked in an in house language which fits in nicely with HTML but there is pressure from our clients to use something a little more "available" so that they can customise their sites themselves. <br /><br />The in house language connects to Oracle and we have a large library of Oracle Packages designed to get our information from the database in a structured way. One thing we do a lot is return data in collections rather than via ref cursors. The problem is that the current version of the Oracle Call Interface doesn't support returning arrays (collections) which have been defined within the header of a package. <br /><br />This means either rewriting some 500 packages/procedures or adding another layer of complexity to convert the returns into a data type PHP can handle.Andrew Gilfrinhttp://www.blogger.com/profile/09929358844206555905noreply@blogger.com1tag:blogger.com,1999:blog-13517334.post-1148762058846832132006-05-27T20:32:00.000+00:002006-05-27T20:34:18.873+00:00MySQLDevelopment.comMySQLDevelopment.com is no more, All requests to the site will now be served from http://forge.mysql.com/wiki/Category:MySQLDevelopment.<br /><br />Thanks for all those who visited the site over the last year.Andrew Gilfrinhttp://www.blogger.com/profile/09929358844206555905noreply@blogger.com0tag:blogger.com,1999:blog-13517334.post-1147439572502956852006-05-12T11:23:00.000+00:002006-05-12T13:13:22.976+00:00MySQLDevelopment.com UpdateI recently I announced that MySQLDevelopment was going to close, at the time I wasn't sure what would be happening to the content but I hoped that it would be able to live on in some form. <br /><br />I had a number of requests and suggestions with regard to the site and I felt the best option was to hand it over to MySQL for inclusion in the new MySQL Forge Wiki. My timing was a little off as the site was due to close during the MySQL conference but with that now out of the way the content of the site has been transfered and is available now at..<br /><br /><a href="http://forge.mysql.com/wiki/Category:MySQLDevelopment">http://forge.mysql.com/wiki/Category:MySQLDevelopment<br /></a><br />I will be passing over the domain name to MySQL also but that may take some time to be up and running so MySQLDevelopment.com will still be available in the mean time.<br /><br />Now it's finally happening it's a little sad for me but this way I know the content can continue to grow and members of the community can contribute in real time.Andrew Gilfrinhttp://www.blogger.com/profile/09929358844206555905noreply@blogger.com0tag:blogger.com,1999:blog-13517334.post-1146232850262861692006-04-28T13:49:00.000+00:002006-04-28T14:00:50.643+00:00MySQL Stored Procedure Programming (The Book) - 3I have mentioned a couple of times about the upcoming release of MySQL Stored Procedure Programming by Guy Harrison and Steven Feuerstein. It was scheduled for release in March but the release date slipped a couple of times, I pre-ordered and the good news is that the book arrived this morning, so it's out now (in the UK at least). <br /><br />It weighs in at 636 pages so while it's not the door stopper that's often related to computer books there is a lot of information in there especially given the relatively recent addition of stored procedures to MySQL. Jay Pipes and Michael Kruckenberg did a great job with their stored procedure chapters in Pro MySQL but given that it wasn't an exclusive development book it didn't go into detail about using stored procedures from other languages, this new book goes into great detail on the subject with dedicated chapters on using stored procedures with PHP, Perl, Python, Java and .Net.<br /><br />Having only received the book today I haven't had much of a chance to read it but first impressions look good and as I said previously if it's half as good as Steven Feuerstein's Oracle related books it will be well worth the money.Andrew Gilfrinhttp://www.blogger.com/profile/09929358844206555905noreply@blogger.com0tag:blogger.com,1999:blog-13517334.post-1146138611458838932006-04-27T11:12:00.000+00:002006-04-28T13:43:21.443+00:00OpportunitiesIt's been well mentioned by myself that of late the time I have been able to devote to MySQL has become restricted. Part of this was due to me taking an exciting new job just before Christmas. When I took the decision to close MySQLDevelopment.com down this was in part due to the fact I was using Oracle rather than MySQL and my exposure to real world situations was limited. <br /><br />However the day after I made the decision and announced it here my boss asked me to take over the running of a MySQL/PHP based website. The good news at least is that it means it might give me something to actually comment on with regard to the blog, even if it doesn't afford me the time to continue with the site.<br /><br />But it's not just good news for me it's also good news for you out there too, the company I work for are looking to take on some new developers. We are looking ideally for people with PHP and Oracle experience but are willing to train good PHP people with limited or no Oracle experience, if you have MySQL skills that would also be a great bonus. The company is based in SW London (England) very close to both over ground rail and tube stations, the atmosphere is relaxed, friendly and informal. <br /><br />I personally can't recommend it enough as a place to work and it would be great to hear from you if you are currently looking for a role in the London area and have the skills we are looking for. <br /><br />You can use the following link to get some more formal details or you can contact me directly for a more informal chat about the role. <br /><br /><a href="http://www.cwjobs.co.uk/JobSearch/JobDetails.aspx?JobId=21270097&Keywords=&CompanyId=138050&Directory=6">Click here to see more details of the role...</a><br /><br />Andrew Gilfrinhttp://www.blogger.com/profile/09929358844206555905noreply@blogger.com0tag:blogger.com,1999:blog-13517334.post-1146044526485343272006-04-26T09:30:00.000+00:002006-04-26T09:44:13.463+00:00Fun with datesIn response to Kai Voigt's post about unxepected results from dates here is what is going wrong. <br /><br />To add and subtract time using + and - you need to use the INTERVAL keyword either before or after the + or - like so..<br /><pre><br />mysql> select now() - interval 2 day;<br />+------------------------+<br />| now() - interval 2 day |<br />+------------------------+<br />| 2006-04-24 07:31:02 |<br />+------------------------+<br />1 row in set (0.00 sec)<br /></pre><br />In Kai's example it's valid to use - on it's own but that handles the date simply as an integer and subtracts the number specified. In small cases as in the example this can seem as if it's the seconds being subtracted but if for example you subtract 100 it simply reduces the number by that amount and not by 1 minute 40 seconds as it sould for a date type. <br /><pre><br />mysql> select now() - 100 day, now();<br />+----------------+---------------------+<br />| day | now() |<br />+----------------+---------------------+<br />| 20060426073122 | 2006-04-26 07:32:22 |<br />+----------------+---------------------+<br />1 row in set (0.00 sec)<br /></pre><br />You can see above the seconds portion of the first "date" is the same where it should be different if it were dealing with it as a time. You can also see that any date formating has been removed (suggesting something odd is going on).<br /><br />The second problem is that while you might think that not including the interval would case a problem it becomes a valid SQL statement because it treats the DAY simply as a heading in the output. To change the heading of a column we can either use AS <i>column_name</i> or simply <i>column_name</i> after our column definiton, this can be seen like so..<br /><pre>mysql> select now() - 100 day, now();<br />+----------------+---------------------+<br />| day | now() |<br />+----------------+---------------------+<br />| 20060426073122 | 2006-04-26 07:32:22 |<br />+----------------+---------------------+<br />1 row in set (0.00 sec)<br /><br />mysql> select now() - 100 as "anything you fancy", now();<br />+--------------------+---------------------+<br />| anything you fancy | now() |<br />+--------------------+---------------------+<br />| 20060426073738 | 2006-04-26 07:38:38 |<br />+--------------------+---------------------+<br />1 row in set (0.00 sec)<br /></pre><br />So to add and remove time from dates you need to make sure you use the interval. Something to watch out for when you get unexpected results is the column heading, that might give a clue that all is not right with your SQL.Andrew Gilfrinhttp://www.blogger.com/profile/09929358844206555905noreply@blogger.com0tag:blogger.com,1999:blog-13517334.post-1145962276462183072006-04-25T10:35:00.000+00:002006-04-25T10:51:16.793+00:00MySQLDevelopment.com gets a stay of executionWhen I posted a few weeks ago about the end of MySQLDevelopment.com it seems the timing was a little off. I was planning to close things down on 30th April simply as it was the end of a month, what I hadn't taken into account was that this would coincide with the MySQL user conference. I won't say too much at the moment but there are plans to use the content on another site which will have some involvment with MySQL themselves, however because of the user conference the people involved won't be able to transfer the content until after the 30th. <br /><br />Our visitor numbers are still growing the figures for March were twice those of January so to avoid any distruption of service I won't be pulling the plug until I can make a seemless switch.Andrew Gilfrinhttp://www.blogger.com/profile/09929358844206555905noreply@blogger.com0tag:blogger.com,1999:blog-13517334.post-1144402034981519232006-04-07T09:15:00.000+00:002006-04-07T09:27:15.003+00:00MySQLDevelopment Update.I have had a great response from people with regards to the (possible) closure of MySQLDevelopment. It seems people want to keep the site alive in one format or another and I have had a lot of communication from MySQL themselves with regard to keeping the content alive. <br /><br />First let me say sorry to all the people who did respond, as suggested in my last post I am really busy at the moment and it's difficult to find the time to reply in a timely fashion. I will be contacting you all individually this weekend. <br /><br />Whatever happens it seems that while the site may change a little as from the 1st May MySQLDevelopment will still be available in some form. I'll keep you posted.Andrew Gilfrinhttp://www.blogger.com/profile/09929358844206555905noreply@blogger.com0tag:blogger.com,1999:blog-13517334.post-1143804567669106402006-03-31T11:15:00.000+00:002006-03-31T11:29:27.690+00:00Calling it a day.I have been blogging since last June (is it really that long) and www.mysqldevelopment.com has been going for over a year now. But as the frequency of posts on this blog and updates on the site will testify recently I just haven't had the time I used to have with regards to MySQL. One of the good and bad things with the web is that it's relatively cheap to just leave stuff hanging around where in traditional media, books for example, the costs of continual production mean things go out of print never to be seen again. This means that the web is full of sites and pages which are left untouched for months or years. Most of the time that isn't a problem but often, especially with IT related sites the information can be way off the mark. <br /><br />It's with that in mind that as from 1st May 2006 www.mysqldevelopment will no longer exist and this will be my last MySQL related blog entry. I no longer have the time or energy to commit to it and with out that the site won't move forward. Of course if somebody wanted to take it on that would be great but privately I have been looking at ways to move the site forward without success. <br /><br />I want to say thanks to all the people who took the time to read my blog and to visit MySQLDevelopment.com and definately a huge thank you to those who contributed to the site over the last year.<br /><br />So long and thanks for all the fish.Andrew Gilfrinhttp://www.blogger.com/profile/09929358844206555905noreply@blogger.com0tag:blogger.com,1999:blog-13517334.post-1143217018832343512006-03-24T15:46:00.000+00:002006-03-24T16:16:58.906+00:00Debugging Stored Procedures in MySQLI have recently seen a couple of posts on the MySQL forums with regard to debugging stored procedures in MySQL. The people asking have been Oracle developers who like most people developing stored procedures in Oracle have been using an Oracle built in package called DBMS_OUTPUT. The package essentially accepts text which is then inserted into a buffer which can be viewed after a procedure has been executed (or even during using the correct tools). It got me thinking how easy it would be to add a similar debug method to MySQL so I came up with the following.<br /><br />I created a new database called debug, this isn't strictly necessary but I like the idea of having a set area for the debug constructs to reside. I then created a table to hold the output, to keep it simple I simply gave it an id column so we could use the debug across a number of procedures at once, a text column to hold out debug statements and an auto increment column so I could order the results with some certainty. <br /><pre><br />DROP TABLE IF EXISTS debug.debug;<br />CREATE TABLE debug.debug (<br /> id varchar(100) default NULL,<br /> debug_output text,<br /> line_id int(11) NOT NULL auto_increment,<br /> PRIMARY KEY (line_id)<br />)<br /></pre><br />I then created three procedures, debug_on to turn logging on, debug_insert to insert debugging messages and then finally debug_off to stop debugging, display the results and then clear the debug table of records for that id. <br /><pre><br />DROP PROCEDURE IF EXISTS `debug`.`debug_on` $$<br />CREATE PROCEDURE `debug_on`(in p_proc_id varchar(100))<br />begin<br /> call debug.debug_insert(p_proc_id,concat('Debug Started :',now()));<br />end $$<br /><br />CREATE PROCEDURE `debug_insert`(in p_proc_id varchar(100),in p_debug_info text)<br />begin<br /> insert into debug (proc_id,debug_output)<br /> values (p_proc_id,p_debug_info);<br />end $$<br /><br />CREATE PROCEDURE `debug_off`(in p_proc_id varchar(100))<br />begin<br /> call debug.debug_insert(p_proc_id,concat('Debug Ended :',now()));<br /> select debug_output from debug where proc_id = p_proc_id order by line_id;<br /> delete from debug where proc_id = p_proc_id;<br />end $$<br /></pre><br />I can now call these from my stored procedures to get debug information like so.<br /><pre><br />CREATE PROCEDURE test.test_debug()<br />begin<br />declare l_proc_id varchar(100) default 'test_debug';<br /> call debug.debug_on(l_proc_id);<br /> call debug.debug_insert(l_proc_id,'Testing Debug');<br /> call debug.debug_off(l_proc_id);<br />end $$<br /><br />mysql> call test.test_debug();<br />+------------------------------------+<br />| debug_output |<br />+------------------------------------+<br />| Debug Started :2006-03-24 16:10:33 |<br />| Testing Debug |<br />| Debug Ended :2006-03-24 16:10:33 |<br />+------------------------------------+<br />3 rows in set (0.20 sec)<br /><br />Query OK, 3 rows affected (0.23 sec)<br /></pre><br />Not rocket science but I'm sure all you Oracle users will be happy, you could of course call the DB DBMS_OUTPUT to make you feel really at home :).Andrew Gilfrinhttp://www.blogger.com/profile/09929358844206555905noreply@blogger.com4tag:blogger.com,1999:blog-13517334.post-1142525204334969942006-03-16T15:51:00.000+00:002006-03-16T17:14:06.056+00:00Do you really want to comment out that code?Yet again I have been on the MySQL forums and yet again it's given me something to write about. The question was pretty standard simply asking how you comment out code or add comments to MySQL stored routines. However the wording of the question got me thinking. In the past when I have been writing complex stored procedures in Oracle it can be difficult to see where an error is coming from, not necessarily which line is raising the error but which section of code cause the problem. One of the methods I have used in the past is to use the /* */ multi line comment syntax to exclude blocks of code on mass to rule them out quickly, this has proved a good way to narrow down where the root of an error comes from. <br /><br />But as you may know MySQL simply removes any comments from the code if it's entered via the command line, it makes no distinction between comments you are adding and code which has been commented out. This isn't a problem when you write procedures in script files and upload them but if you use the command line directly (either typing them in or copy and paste) it means the commented code will be lost forever. <br /><br />Yet another example of why you don't want to write stored procedures directly into the command line.Andrew Gilfrinhttp://www.blogger.com/profile/09929358844206555905noreply@blogger.com0tag:blogger.com,1999:blog-13517334.post-1142423107168668412006-03-15T11:14:00.000+00:002006-03-15T11:45:07.186+00:00Event Scheduler on Mac OS XOne of the things I learnt a year ago when I first started working with MySQL stored procedures was that you really need to have the latest version of MySQL running. By the time you have identified a possible bug and noted down the specifics a new version was available which invariably fixed the problem. <br /><br />This is also true with release 5.1, I have recently started writing content on the event scheduler over at <a href="http://www.mysqldevelopment.com">www.mysqldevelopment.com</a> and found a few bugs early on. Given that 5.1 is still very much in development I tend not to raise bugs these days without first checking on the forums and then making sure I have the very latest release to test against. <br /><br />One of the biggest issues I had was that one off events worked fine, but events that fired at intervals didn't. I say they didn't but one of the big problem with testing events is that you have to wait a long time to prove something. I was using 1 minute intervals which didn't work, I also tried 5 and 10 minute intervals also. Testing hour intervals was just about practical but any more than that was just too time consuming. I checked on the forum but there doesn't seem to be a great deal of activity in the event scheduler section at present, so I downloaded a newer version of 5.1 (in this case going from 5.1.6 to 5.1.7), testing again proved positive and it seems whatever the problem had been was now fixed.<br /><br />I think the event scheduler is a great new feature and I can't wait to get the content finished, unfortunately it's taking a bit longer than I hoped due to other commitments and also the fact it takes a fair amount of time to testing things.Andrew Gilfrinhttp://www.blogger.com/profile/09929358844206555905noreply@blogger.com0tag:blogger.com,1999:blog-13517334.post-1141832639139685632006-03-08T15:34:00.000+00:002006-03-08T15:43:59.160+00:00Spread the wordAs you may or may not know I'm a sysop over at the Quest Pipelines MySQL forum. We don't get a great deal of visitors in the MySQL forums there, due in part I guess to the fact the forums on the MySQL website are so good. <br /><br />However in addition to running the forums Quest produce a monthly database newsletter which is sent to over 28,000 database professionals. Subjects vary but the general format is an article on Oracle, SQL Server, DB2 and for the last year or so MySQL. For me this is a great way to spread the MySQL word to other database users but unfortunately I'm insanely busy with the day job so I can't submit anything this month. <br /><br />So if you have something written or would like to contribute then let the newsletter team know at <br /><br />newsletter@quest-pipelines.com<br /><br />Or have a look at the latest addition over at the MySQL area of the pipelines site.<br /><br /><a href="http://www.quest-pipelines.com/pipelines/mysql/index.asp">http://www.quest-pipelines.com/pipelines/mysql/index.asp</a>Andrew Gilfrinhttp://www.blogger.com/profile/09929358844206555905noreply@blogger.com0tag:blogger.com,1999:blog-13517334.post-1141129514517542492006-02-28T12:07:00.000+00:002006-02-28T12:25:14.553+00:00The MySQL PromptFollowing on from my previous post about tips I have been picking up from the MySQL certification study guide I have another which I think is worth mentioning. <br /><br />Personally I had never noticed that the MySQL prompt changes in relation to what went before it. How often have you done something similar to the following.<br /><pre><br />mysql> select * from emps where emp_name = 'john ;<br /> '> ;<br /> '> ';<br />Empty set (0.01 sec)<br /></pre><br />You type in a select statement only to open a quote but never close it, personally I always stick in another ; before I realise the mistake and terminate the quote and end the statement correctly. But what I didn't realise before reading the study guide (and making me very unobservant) was that the mysql> prompt changes in response to the currently open quote. In the above example this isn't obvious because it just looks like a continuation but in fact the prompt has been changed to show us that it is expecting a closing single quote. Take for example the following.<br /><pre><br />mysql> select * from emps<br /> -> where emp_name = 'john';<br /></pre><br />In this case it gives us the standard -> continuation prompt. Firstly I never even noticed this and secondly even if I did I doubt I would have seen the significance, generally I'm more focused on why the five semi-colons I entered have failed to be recognised. The certification study guide points out that there are in fact 5 prompts. <br /><pre><br />mysql> <br /> -><br /> '><br /> "><br /> `><br /></pre> <br />This becomes much more relevant when we are entering large complex SQL statements where it might not be obvious where the mistake has occurred. Take this SQL for example.<br /><pre><br />mysql> select e.emp_id, e.emp_name, d.dept_name<br /> -> from emps e, dept d<br /> -> where e.dept_id = d.dept_id<br /> -> and e.emp_name = 'john<br /> '> and e.dept_id = 1;<br /> '><br /></pre><br />While this isn't as complex as it could be it’s easy to see in this instance where the problem occurred because our prompt changes from -> to '> on line 5.<br /><br />We can use this in combination with the \c tip I mentioned earlier.<br /><pre><br />mysql> select e.emp_id, e.emp_name, d.dept_name<br /> -> from emps e, dept d<br /> -> where e.dept_id = d.dept_id<br /> -> and e.emp_name = 'john<br /> '> '\c<br /></pre>Andrew Gilfrinhttp://www.blogger.com/profile/09929358844206555905noreply@blogger.com0