{"id":7217,"date":"2014-05-16T05:03:59","date_gmt":"2014-05-15T19:03:59","guid":{"rendered":"http:\/\/www.rjmprogramming.com.au\/wordpress\/?p=7217"},"modified":"2014-05-16T05:03:59","modified_gmt":"2014-05-15T19:03:59","slug":"mysql-repair-table-primer-tutorial","status":"publish","type":"post","link":"https:\/\/www.rjmprogramming.com.au\/ITblog\/mysql-repair-table-primer-tutorial\/","title":{"rendered":"MySql Repair Table Primer Tutorial"},"content":{"rendered":"<div style=\"width: 230px\" class=\"wp-caption alignnone\"><a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/MySql\/RepairTable\/\"><img decoding=\"async\" style=\"float:left; border: 15px solid pink;\" alt=\"MySql Repair Table Primer Tutorial\" src=\"http:\/\/www.rjmprogramming.com.au\/MySql\/RepairTable\/MySql_Recover-99of.jpg\" title=\"MySql Repair Table Primer Tutorial\"   \/><\/a><p class=\"wp-caption-text\">MySql Repair Table Primer Tutorial<\/p><\/div>\n<p>Today&#8217;s tutorial continues the MySql (command line) discussion last heard about with <a href='#moclpt' title='MySql Stored Procedures Primer Tutorial'>MySql Stored Procedures Primer Tutorial<\/a> as shown below, to illustrate that MySql has functionality to repair database tables, if they run into trouble.<\/p>\n<p>When you troubleshoot a problem regarding an Apache\/PHP\/MySql website you can tend to think, firstly, when a bit of functionality is not working (when it has been working fine for a while now) that the problem is with the software code being unable to cater with some unusual situation.<\/p>\n<p>The Apache log may get you closer to discovering the problem, but you may get to know some troubleshooting shortcuts, to rule out the database, or not, by checking the relevant database table using MySql from the command line, or the brilliant phpMyAdmin, as a GUI interface to the database.<\/p>\n<p>Not always, but sometimes, you can be surprised to find that MySql database tables do have problems from time to time, and that MySql marks these tables as <i>&#8220;crashed&#8221;<\/i>, as you can see in today&#8217;s <a target=_blank title='Click picture' href='http:\/\/www.rjmprogramming.com.au\/MySql\/RepairTable\/'>MySql Repair Table Primer Tutorial<\/a>.<\/p>\n<p>The functionality shown in the tutorial regarding phpMyAdmin MySql statement <i>REPAIR TABLE [tableName]<\/i> and the two MySql command line <i><a target=_blank title='mysqlcheck' href='http:\/\/dev.mysql.com\/doc\/refman\/5.0\/en\/mysqlcheck.html'>mysqlcheck<\/a><\/i> or, if MyISAM format, <i><a target=_blank title='myisamchk' href='https:\/\/dev.mysql.com\/doc\/refman\/5.0\/en\/myisamchk-repair-options.html'>myisamchk<\/a><\/i> choices are not guaranteed to fix the problem all the time, and sometimes it can be to do with the size of the table involved, or with the size of the temp area set aside on your server.  When a <i>REPAIR TABLE<\/i> operation runs too long, in phpMyAdmin the table will be still marked as crashed and you may see the string &#8220;(in use)&#8221; shown in the Collation column of the table screen.   In such cases you can:<\/p>\n<ul>\n<li>continue waiting for repair process to finish &#8230; or &#8230;<\/li>\n<li>use a restore operation to restore the table (that you have backed up recently) &#8230; or &#8230; (the next two options lose data, and so should only be done when you know the table is independent of others) &#8230;<\/li>\n<li>truncate the table with the phpMyAdmin &#8220;empty&#8221; icon (this may not work for a while, but becomes an option as time goes on) &#8230; or &#8230;<\/li>\n<li>drop the table (then recreate it) with the phpMyAdmin &#8220;drop&#8221; icon (this may not work for a while, but becomes an option as time goes on)<\/li>\n<\/ul>\n<hr \/>\n<p id=\"moclpt\">Previous relevant <a target=_blank title='MySql on Command Line Primer Tutorial' href='http:\/\/www.rjmprogramming.com.au\/wordpress\/?p=7031'>MySql on Command Line Primer Tutorial<\/a> is shown below.<\/p>\n<div style=\"width: 230px\" class=\"wp-caption alignnone\"><a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/MySql\/CommandLine\/\"><img decoding=\"async\" style=\"float:left; border: 15px solid pink;\" alt=\"MySql on Command Line Primer Tutorial\" src=\"http:\/\/www.rjmprogramming.com.au\/MySql\/CommandLine\/MySql_CommandLine_Primer-9of.jpg\" title=\"MySql on Command Line Primer Tutorial\"   \/><\/a><p class=\"wp-caption-text\">MySql on Command Line Primer Tutorial<\/p><\/div>\n<p>Today&#8217;s tutorial follows up on <a href='#msppt' title='MySql Stored Procedures Primer Tutorial'>MySql Stored Procedures Primer Tutorial<\/a> as shown below, to illustrate that MySql database (and PHP server-side language) are friends of the command line, and you can use all these tools in <a target=_blank title='Batch processing information from Wikipedia' href='http:\/\/en.wikipedia.org\/wiki\/Batch_program'>batch processing<\/a>, even though you most often associate PHP and MySql with interactive web use (or maybe you don&#8217;t?!).<\/p>\n<p>This blog talks a fair bit about batch processing and command line work, not so much from the point of view of nostalgia, but more from the point of view that lots of computer software functionality can still be modelled on a procedural set of tasks which can be planned so that interactivity stops at a certain point, and then you should let loose the power of the computer to actually do things (the joy of batch processing).   Do enough batch processing, and you feel what you feel like when you have trodden softly on this earth.<\/p>\n<p>Anyway, enough of the rave, but with the <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/MySql\/CommandLine\/\" title=\"Click picture\">tutorial<\/a> we interactively, on our local webserver&#8217;s <a target=_blank title='MAMP tutorials at this blog' href='http:\/\/www.rjmprogramming.com.au\/wordpress\/?tag=MAMP'>MAMP<\/a> environment, create a new database called testdb, use the previous tutorial&#8217;s code to create some MySql tables and stored procedures in that database, so that we have one record in each of our two tables that we show you via phpMyAdmin (in an interactive way) and via a Mac OS X laptop&#8217;s Terminal application&#8217;s Linux bash environment command line (via the mysql program in a Linux command line environment).<\/p>\n<p>This example is simple, but you build off the simple, and imagine the big, and imagine the procedural, and imagine the compartmentalization of tasks &#8230; if you want to have fun that is &#8230; the bungee jumpers are all just faking it!<\/p>\n<p>So today, as well as with the previously relevant tutorial we used (MySql) stored procedures, and we&#8217;ll let Wikipedia explain this important database tool below.<\/p>\n<blockquote><p>A stored procedure is a subroutine available to applications that access a relational database system. A stored procedure (sometimes called a proc, sproc, StoPro, StoredProc, sp or SP) is actually stored in the database data dictionary.<\/p>\n<p>Typical use for stored procedures include data validation (integrated into the database) or access control mechanisms. Furthermore, stored procedures can consolidate and centralize logic that was originally implemented in applications. Extensive or complex processing that requires execution of several SQL statements is moved into stored procedures, and all applications call the procedures. One can use nested stored procedures by executing one stored procedure from within another.<\/p>\n<p>Stored procedures are similar to user-defined functions (UDFs). The major difference is that UDFs can be used like any other expression within SQL statements, whereas stored procedures must be invoked using the CALL statement.[1]<\/p><\/blockquote>\n<p>Thanks to <a target=_blank title='Database stored procedure information from Wikipedia' href='http:\/\/en.wikipedia.org\/wiki\/Stored_procedure'>Wikipedia<\/a> for the quote above, and would recommend that if you want to get the most out of what is possible with databases, like MySql you also study triggers, and for that will leave you with a Wikipedia entry about this <a target=_blank title='Database trigger information from Wikipedia' href='http:\/\/en.wikipedia.org\/wiki\/Database_trigger'>topic<\/a>.   Happy databasing!<\/p>\n<hr \/>\n<p id='msppt'>Previous relevant <a target=_blank title='MySql Stored Procedures Primer Tutorial' href='http:\/\/www.rjmprogramming.com.au\/wordpress\/?p=3849'>MySql Stored Procedures Primer Tutorial<\/a> is shown below.<\/p>\n<div style=\"width: 230px\" class=\"wp-caption alignnone\"><a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/MySql\/StoredProcedure\/MySql_StoredProcedure_Primer.jpg\"><img decoding=\"async\" style=\"float:left; border: 15px solid pink;\" alt=\"MySql Stored Procedures Primer Tutorial\" src=\"http:\/\/www.rjmprogramming.com.au\/MySql\/StoredProcedure\/MySql_StoredProcedure_Primer.jpg\" title=\"MySql Stored Procedures Primer Tutorial\"   \/><\/a><p class=\"wp-caption-text\">MySql Stored Procedures Primer Tutorial<\/p><\/div>\n<p>Today&#8217;s tutorial follows up on <a href='#pitmappt' title='phpMyAdmin interface to MySql and PHP Primer Tutorial'>phpMyAdmin interface to MySql and PHP Primer Tutorial<\/a> in that we again use the brilliant phpMyAdmin to oversee the results of some PHP code which uses MySql calls to create tables called POINT and CIRCLE used to store information defining a circle, and then it creates three MySql stored procedures in the database to help add circle data with the single MySql statement that goes <em>CALL AddCircle(x, y, radius);<\/em> via the use of those stored procedures.   Let&#8217;s see below what <a target=_blank title='Stored Procedures information from Wikipedia' href='http:\/\/en.wikipedia.org\/wiki\/Stored_procedure'>Wikipedia<\/a> says about Stored Procedures generally.<\/p>\n<blockquote><p>A stored procedure is a subroutine available to applications that access a relational database system. A stored procedure (sometimes called a proc, sproc, StoPro, StoredProc, sp or SP) is actually stored in the database data dictionary.<\/p>\n<p>Typical use for stored procedures include data validation (integrated into the database) or access control mechanisms. Furthermore, stored procedures can consolidate and centralize logic that was originally implemented in applications. Extensive or complex processing that requires execution of several SQL statements is moved into stored procedures, and all applications call the procedures. One can use nested stored procedures by executing one stored procedure from within another.<\/p>\n<p>Stored procedures are similar to user-defined functions (UDFs). The major difference is that UDFs can be used like any other expression within SQL statements, whereas stored procedures must be invoked using the CALL statement.[1]<\/p><\/blockquote>\n<p>Here is some downloadable PHP programming source code which shows the results of the MySql SQL requests made and can be renamed to <a target=_blank title='ourmysqlstoreprocedure.php' href='http:\/\/www.rjmprogramming.com.au\/MySql\/StoredProcedure\/ourmysqlstoredprocedure.php_GETME'>ourmysqlstoredprocedure.php<\/a> as required.<\/p>\n<p>Here is some downloadable supervisory PHP programming source code which gathers the MySql SQL requests made and can be renamed to <a target=_blank title='ourmysql_storeprocedure.php' href='http:\/\/www.rjmprogramming.com.au\/MySql\/StoredProcedure\/ourmysql_storedprocedure.php_GETME'>ourmysql_storedprocedure.php<\/a> as required.<\/p>\n<p>If you want to develop your own live usage (have provided a live usage link <a target=_blank title='live usage or to see the raw MySql SQL involved in this tutorail' href='http:\/\/www.rjmprogramming.com.au\/MySql\/StoredProcedure\/'>here<\/a> which will not work but you can use if you are a beginner, to get used to mysql errors, which will occur after you hit either button of the link (these errors indicate bad MySql connection details which are the same reason the database dropdown is not full of options), or you can use this link to see the raw MySql SQL involved in piecing this tutorial together) of these two PHP source codes then you could fix up the hard codings for MySql host\/username\/password up the top of ourmysql_storeprocedure.php (where you may notice that the default host in the code is localhost:8889 which is the default host string for MySql (ie. <a target=_blank title='port explained by Wikipedia' href='http:\/\/en.wikipedia.org\/wiki\/Port_%28computer_networking%29'>port<\/a> 8889 is used) when using a <a target=_blank title='PHP and MySql via MAMP Primer Tutorial' href='http:\/\/www.rjmprogramming.com.au\/wordpress\/?p=933'>MAMP<\/a> (Mac laptop) local web server (which uses localhost:8888 as its local &#8220;domain name&#8221; for http usage)) or you can keep the same code and use a URL like:<\/p>\n<p>[your-domain-name-plus-a-bit-maybe]\/ourmysql_storeprocedure.php?host=[your MySql host address]&#038;username=[your MySql username]&#038;password=[your MySql password]&#038;database=[your optional MySql default database name within the looked up list presented]<\/p>\n<hr \/>\n<p id='pitmappt'>Previous <a href='http:\/\/www.rjmprogramming.com.au\/wordpress\/?p=492' title='phpMyAdmin interface to MySql and PHP Primer Tutorial'>phpMyAdmin interface to MySql and PHP Primer Tutorial<\/a> is relevant and shown below.<\/p>\n<div style=\"width: 230px\" class=\"wp-caption alignnone\"><a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/phpMyAdmin\/iFrame.html\"><img decoding=\"async\" style=\"float:left; border: 15px solid pink;\" alt=\"phpMyAdmin interface to MySql and PHP Primer Tutorial\" src=\"http:\/\/www.rjmprogramming.com.au\/phpMyAdmin\/phpMyAdmin.jpg\" title=\"phpMyAdmin interface to MySql and PHP Primer Tutorial\"   \/><\/a><p class=\"wp-caption-text\">phpMyAdmin interface to MySql and PHP Primer Tutorial<\/p><\/div>\n<p><strong><\/p>\n<p>Transcript:<\/p>\n<p><\/strong><\/p>\n<p>You never hear much about the data when you hear about great PHP products, but we<br \/>\n   all know it is the data that differentiates the quality of the end result.<\/p>\n<p>That is probably because database products like MySql, SqlServer, Oracle SQL, Advantage and Access<br \/>\n   are pretty good at what they do, and emphasise reliability rather than flashiness.<\/p>\n<p>MySql and PHP have a great open source interface with phpMyAdmin, which is so good,<br \/>\n  you forget that it is not the default MySql administrator&#8217;s interface product.<\/p>\n<p>Let&#8217;s have a look at this WordPress database and a bit of how it looks, looking<br \/>\n  through the prism of  <a target=_blank title='click picture' href='http:\/\/www.rjmprogramming.com.au\/phpMyAdmin\/iFrame.html'>phpMyAdmin<\/a> &#8230;\n<\/p>\n<p>If this was interesting you may be interested in <a title='Click here to see topics in which you might be interested' href='#d492' onclick='var dv=document.getElementById(\"d492\"); dv.innerHTML = \"&lt;iframe width=670 height=600 src=\" + \"http:\/\/www.rjmprogramming.com.au\/wordpress\/?cat=47\" + \"&gt;&lt;\/iframe&gt;\"; dv.style.display = \"block\";'>this<\/a> too.<\/p>\n<div id='d492' style='display: none; border-left: 2px solid green; border-top: 2px solid green;'><\/div>\n<hr \/>\n<p>If this was interesting you may be interested in <a title='Click here to see topics in which you might be interested' href='#d3849' onclick='var dv=document.getElementById(\"d3849\"); dv.innerHTML = \"&lt;iframe width=670 height=600 src=\" + \"http:\/\/www.rjmprogramming.com.au\/wordpress\/?cat=47\" + \"&gt;&lt;\/iframe&gt;\"; dv.style.display = \"block\";'>this<\/a> too.<\/p>\n<div id='d3849' style='display: none; border-left: 2px solid green; border-top: 2px solid green;'><\/div>\n<hr \/>\n<p>If this was interesting you may be interested in <a title='Click here to see topics in which you might be interested' href='#d7031' onclick='var dv=document.getElementById(\"d7031\"); dv.innerHTML = \"&lt;iframe width=670 height=600 src=\" + \"http:\/\/www.rjmprogramming.com.au\/wordpress\/?cat=47\" + \"&gt;&lt;\/iframe&gt;\"; dv.style.display = \"block\";'>this<\/a> too.<\/p>\n<div id='d7031' style='display: none; border-left: 2px solid green; border-top: 2px solid green;'><\/div>\n<hr \/>\n<p>If this was interesting you may be interested in <a title='Click here to see topics in which you might be interested' href='#d7217' onclick='var dv=document.getElementById(\"d7217\"); dv.innerHTML = \"&lt;iframe width=670 height=600 src=\" + \"http:\/\/www.rjmprogramming.com.au\/wordpress\/?cat=47\" + \"&gt;&lt;\/iframe&gt;\"; dv.style.display = \"block\";'>this<\/a> too.<\/p>\n<div id='d7217' style='display: none; border-left: 2px solid green; border-top: 2px solid green;'><\/div>\n","protected":false},"excerpt":{"rendered":"<p>Today&#8217;s tutorial continues the MySql (command line) discussion last heard about with MySql Stored Procedures Primer Tutorial as shown below, to illustrate that MySql has functionality to repair database tables, if they run into trouble. When you troubleshoot a problem &hellip; <a href=\"https:\/\/www.rjmprogramming.com.au\/ITblog\/mysql-repair-table-primer-tutorial\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9,12,37],"tags":[85,234,299,826,827,828,938,1052,1186,1319],"class_list":["post-7217","post","type-post","status-publish","format-standard","hentry","category-database","category-elearning","category-tutorials","tag-apache","tag-command-line","tag-database-2","tag-myisamchk","tag-mysql","tag-mysqlcheck","tag-phpmyadmin","tag-repair-table","tag-sql","tag-tutorial"],"_links":{"self":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/7217"}],"collection":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/comments?post=7217"}],"version-history":[{"count":0,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/7217\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/media?parent=7217"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/categories?post=7217"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/tags?post=7217"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}