<?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>OpenKB::Server Technical Papers &#187; MySQL</title>
	<atom:link href="http://www.openkb.org/category/mysql/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.openkb.org</link>
	<description>Computer , server issues and solutions</description>
	<lastBuildDate>Thu, 02 Feb 2012 16:50:15 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Mysql: Warning: #1264 Out of range value adjusted</title>
		<link>http://www.openkb.org/mysql-warning-1264-out-of-range-value-adjusted/</link>
		<comments>http://www.openkb.org/mysql-warning-1264-out-of-range-value-adjusted/#comments</comments>
		<pubDate>Thu, 17 Nov 2011 15:01:44 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[MySQL]]></category>

		<guid isPermaLink="false">http://www.openkb.org/?p=1069</guid>
		<description><![CDATA[Full Error: Warning: #1264 Out of range value adjusted for column &#8216;id&#8217; at row 1 We have a database that was used to store some valuable data. The Id column was set to auto increment when a new record was inserted. After about 127 records we started to get the above error message. come to [...]]]></description>
			<content:encoded><![CDATA[<p>Full Error: Warning: #1264 Out of range value adjusted for column &#8216;id&#8217; at row 1</p>
<p>We have a database that was used to store some valuable data. The Id column was set to auto increment when a new record was inserted. After about 127 records we started to get the above error message. come to find out we designed the column to use tinyint instead of INT. TinyINT has a max value of 127 , while the record will insert into the table. The id value remained at 127 for all records after. This could have been a huge problem with a larger and high volume application. We ignored the error for about 30 days as it was a warning and not a true error. </p>
<p>Despite what <a href="http://webomania.wordpress.com/2006/10/01/out-of-range-value-adjusted-for-column-error/">This blog</a> says to issue the following SET GLOBAL SQL_MODE=”; . I would recommend exploring all options before changing the value of the sql mode. </p>
<p>Please check the following resource links to help you make a decision<br />
<a href="http://dev.mysql.com/doc/refman/5.0/en/numeric-types.html">Numeric Types</a><br />
<a href="http://dev.mysql.com/doc/refman/5.0/en/server-sql-mode.html">MySQL Modes</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.openkb.org/mysql-warning-1264-out-of-range-value-adjusted/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>mysql: MySQL_Server_Time_Zone_Support</title>
		<link>http://www.openkb.org/mysql-mysql_server_time_zone_support/</link>
		<comments>http://www.openkb.org/mysql-mysql_server_time_zone_support/#comments</comments>
		<pubDate>Wed, 31 Aug 2011 09:21:03 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[MySQL]]></category>

		<guid isPermaLink="false">http://www.openkb.org/?p=1029</guid>
		<description><![CDATA[[[Category:MySQL]] Reference: http://dev.mysql.com/doc/refman/5.1/en/time-zone-support.html Some customer will attempt to use the SET SESSION time_zone query to set the time zone for their database. This will only work if we have loaded the zone data into the mysql.time_zone_name Table. One of the error will be mysql> SET SESSION time_zone = &#8216;US/Central&#8217;; ERROR 1298 (HY000): Unknown or incorrect [...]]]></description>
			<content:encoded><![CDATA[<p>[[Category:MySQL]]</p>
<p>Reference: http://dev.mysql.com/doc/refman/5.1/en/time-zone-support.html</p>
<p>Some customer will attempt to use the  SET SESSION time_zone query to set the time zone for their database. This will only work if we have loaded the zone data into the mysql.time_zone_name Table.</p>
<p>One of the error will be<br />
mysql> SET SESSION time_zone = &#8216;US/Central&#8217;;<br />
ERROR 1298 (HY000): Unknown or incorrect time zone: &#8216;US/Central&#8217; <*missing zone data*></p>
<p>Log into the server as root</p>
<p>Type Command : mysql<br />
Run this query to check if the zone data already exist<br />
mysql> SELECT COUNT(*) FROM mysql.time_zone_name; *if the count returns 0 , then the zone data will need to be loaded*</p>
<p>Type exist to leave mysql<br />
at the prompt run<br />
 mysql_tzinfo_to_sql /usr/share/zoneinfo | mysql  **you may see some errors unable to load** these can be ignored</p>
<p>This will import the zone data from the system into mysql<br />
Additional details: The mysql_tzinfo_to_sql utility reads your system&#8217;s time zone files and generates SQL statements from them. Using the pipe to send those SQL statements to the mysql client, it then processes those statements to load the data into the time zone tables.</p>
<p>now run </p>
<p>mysql> SELECT COUNT(*) FROM mysql.time_zone_name;  * you should see a higher number indicating how zone records were imported into mysql *</p>
<p>log into mysql as the user<br />
mysql  -u username -p</p>
<p>run the set command to verify setting the time zone works as the user<br />
mysql> SET SESSION time_zone = &#8216;US/Central&#8217;;<br />
Query OK, 0 rows affected (0.20 sec)</p>
<p>The user does not need admin rights to the server to perform the  SESSION time_zone option. They just need grant rights to their db. </p>
<p><a href="http://dev.mysql.com/doc/refman/5.1/en/time-zone-support.html">reference</a><br />
also <a href="http://helpdesk.bkpm.go.id/index.php?_m=knowledgebase&#038;_a=viewarticle&#038;kbarticleid=41">Reference</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.openkb.org/mysql-mysql_server_time_zone_support/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Mysql: import from Excel</title>
		<link>http://www.openkb.org/mysql-import-from-excel/</link>
		<comments>http://www.openkb.org/mysql-import-from-excel/#comments</comments>
		<pubDate>Sat, 30 Apr 2011 22:04:01 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[MySQL]]></category>

		<guid isPermaLink="false">http://www.openkb.org/?p=960</guid>
		<description><![CDATA[You will need to convert you Excel worksheet to a csv file by saving it as .csv If you have mysql installed locally on your pc , you can run the following query to import your data . *please note you should remove the first column which includes the columns titles. * LOAD DATA local [...]]]></description>
			<content:encoded><![CDATA[<p>You will need to convert you Excel worksheet to a csv file by saving it as .csv</p>
<p>If you have mysql installed locally on your pc , you can run the following query to import your data . *please note you should remove the first column which includes the columns titles. *</p>
<p>LOAD DATA local INFILE &#8216;C:\\wamp\\file.csv&#8217; INTO TABLE bizdir.directoryFIELDS TERMINATED BY &#8216;,&#8217; LINES TERMINATED BY &#8216;\r\n&#8217; (col1,col2);</p>
<p>You will need to make some minor adjustments to the query above including the file name and location. Also the columns name to match the columns in the table you are importing into.  You can then export the data from your local mysql instance to a remote server.</p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.openkb.org/mysql-import-from-excel/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>IIS7 /PHP5.3.1/mysql 500 error</title>
		<link>http://www.openkb.org/iis7-php5-3-1mysql-500-error/</link>
		<comments>http://www.openkb.org/iis7-php5-3-1mysql-500-error/#comments</comments>
		<pubDate>Mon, 09 Aug 2010 09:24:59 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[MySQL]]></category>

		<guid isPermaLink="false">http://www.openkb.org/?p=823</guid>
		<description><![CDATA[Seems it is no longer enough to have localhost in the servers local hosts file (C:\Windows\System32\drivers\etc\hosts) you also have to comment out or remove the IPv6 equivalent. 127.0.0.1 localhost #::1 localhost **this seem to work only when connecting locally ** Thanks Bruce]]></description>
			<content:encoded><![CDATA[<p>Seems it is no longer enough to have localhost in the servers local hosts file (C:\Windows\System32\drivers\etc\hosts) you also have to comment out or remove the IPv6 equivalent.</p>
<p>127.0.0.1 localhost<br />
#::1 localhost</p>
<p>**this seem to work only when connecting locally **</p>
<p><a href="http://www.php.net/manual/en/install.windows.iis7.php#94317">Thanks Bruce</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.openkb.org/iis7-php5-3-1mysql-500-error/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Mysql &#8211; mysqlnd cannot connect to MySQL 4.1+ using old authentication</title>
		<link>http://www.openkb.org/mysql-mysqlnd-cannot-connect-to-mysql-4-1-using-old-authentication/</link>
		<comments>http://www.openkb.org/mysql-mysqlnd-cannot-connect-to-mysql-4-1-using-old-authentication/#comments</comments>
		<pubDate>Mon, 09 Aug 2010 09:22:07 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[MySQL]]></category>

		<guid isPermaLink="false">http://www.openkb.org/?p=821</guid>
		<description><![CDATA[&#8211; packet 6 bytes shorter than expected in &#8211; Client does not support authentication protocol requested by server; consider upgrading MySQL client Error: This means you are connecting to a mysql server using the new hash client while the server is setup to receive the old. You will first need to make sure old-password is [...]]]></description>
			<content:encoded><![CDATA[<p> &#8211; packet 6 bytes shorter than expected in<br />
 &#8211;  Client does not support authentication protocol requested<br />
by server; consider upgrading MySQL client</p>
<p>Error: This means you are connecting to a mysql server using the new hash client while the server is setup to receive the old. </p>
<p>You will first need to make sure old-password is not enabled in my.cnf<br />
old-password </p>
<p>You can just had a # in front of it to comment the settings. Restart the service and do<br />
SET PASSWORD FOR &#8216;some_user&#8217;@'some_host&#8217; = PASSWORD(&#8216;newpwd&#8217;);</p>
<p>This will give you a 41 byte hash , you may want to re-enable the old-password option for legacy apps. </p>
<p><a href="http://dev.mysql.com/doc/refman/5.1/en/old-client.html">support authentication</a> </p>
<p><a href="http://dev.mysql.com/doc/refman/5.1/en/password-hashing.htmlhttp://dev.mysql.com/doc/refman/5.1/en/password-hashing.html">Password Hashing in MySQL</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.openkb.org/mysql-mysqlnd-cannot-connect-to-mysql-4-1-using-old-authentication/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>mysql:  Incorrect information in file:</title>
		<link>http://www.openkb.org/mysql-incorrect-information-in-file/</link>
		<comments>http://www.openkb.org/mysql-incorrect-information-in-file/#comments</comments>
		<pubDate>Sat, 30 Jan 2010 18:23:50 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[MySQL]]></category>

		<guid isPermaLink="false">http://www.openkb.org/?p=726</guid>
		<description><![CDATA[Incorrect information in file /path/test.frm This indicates that skip-innodb is enabled in the my.cnf file ..]]></description>
			<content:encoded><![CDATA[<p> Incorrect information in file /path/test.frm</p>
<p>This indicates that skip-innodb is enabled in the my.cnf file .. </p>
]]></content:encoded>
			<wfw:commentRss>http://www.openkb.org/mysql-incorrect-information-in-file/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Mysql ERROR 3 (HY000): Error writing file</title>
		<link>http://www.openkb.org/mysql-error-3-hy000-error-writing-file/</link>
		<comments>http://www.openkb.org/mysql-error-3-hy000-error-writing-file/#comments</comments>
		<pubDate>Sat, 31 Oct 2009 17:35:51 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[MySQL]]></category>

		<guid isPermaLink="false">http://www.openkb.org/?p=638</guid>
		<description><![CDATA[Error : ERROR 3 (HY000): Error writing file &#8216;/tmp/MY68ie0h&#8217; (Errcode: 28)   this is due to a storage issue with the partition that is holding /tmp]]></description>
			<content:encoded><![CDATA[<p>Error :</p>
<p>ERROR 3 (HY000): Error writing file &#8216;/tmp/MY68ie0h&#8217; (Errcode: 28)</p>
<p> </p>
<p>this is due to a storage issue with the partition that is holding /tmp</p>
]]></content:encoded>
			<wfw:commentRss>http://www.openkb.org/mysql-error-3-hy000-error-writing-file/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MySQL: Persistent connections</title>
		<link>http://www.openkb.org/mysql-persistent-connections/</link>
		<comments>http://www.openkb.org/mysql-persistent-connections/#comments</comments>
		<pubDate>Sun, 10 May 2009 18:45:39 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[MySQL]]></category>

		<guid isPermaLink="false">http://www.openkb.org/?p=476</guid>
		<description><![CDATA[You may encounter a max user connection error if your my.cnf file is set to a low number and you have mysql.allow_persistent = on within your php.ini file. You have two ways to fix this . 1) use a mysql_close() statement within your code. this is not needed for non-persistent connection per the PHP manual [...]]]></description>
			<content:encoded><![CDATA[<p>You may encounter a max user connection error if your my.cnf file is set to a low number and you have mysql.allow_persistent = on within your php.ini file. </p>
<p>You have two ways to fix this . </p>
<p>1) use a mysql_close() statement within your code. this is not needed for non-persistent connection per the PHP manual<br />
<a href="http://us2.php.net/mysql_close"> PHP Manual </a></p>
<p>2) disallow persistent connection by turning it off within the php.ini file. </p>
<p>Persistent connection keeps the last connection active with mysql which goes into sleep mode. </p>
<p>Other errors you may see<br />
<a href="http://dev.mysql.com/doc/refman/5.1/en/too-many-connections.html"> Too many connections </a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.openkb.org/mysql-persistent-connections/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MysQL: Show grants for users</title>
		<link>http://www.openkb.org/mysql-show-grants-for-users/</link>
		<comments>http://www.openkb.org/mysql-show-grants-for-users/#comments</comments>
		<pubDate>Sat, 09 May 2009 22:59:16 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[MySQL]]></category>

		<guid isPermaLink="false">http://www.openkb.org/?p=470</guid>
		<description><![CDATA[mysql> show grants for &#8216;user&#8217;@'host&#8217; or select * from information_schema.user_privileges where grantee like &#8220;&#8216;user&#8217;%&#8221;; Tools Maakit]]></description>
			<content:encoded><![CDATA[<p>mysql> show grants for &#8216;user&#8217;@'host&#8217;<br />
or<br />
select * from information_schema.user_privileges where grantee like &#8220;&#8216;user&#8217;%&#8221;;</p>
<p>Tools<br />
<a href="http://www.maatkit.org/tools.html"> Maakit </a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.openkb.org/mysql-show-grants-for-users/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Mysql: drop all tables via the command line</title>
		<link>http://www.openkb.org/mysql-drop-all-tables-via-the-command-line/</link>
		<comments>http://www.openkb.org/mysql-drop-all-tables-via-the-command-line/#comments</comments>
		<pubDate>Mon, 02 Feb 2009 00:22:54 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[MySQL]]></category>

		<guid isPermaLink="false">http://www.openkb.org/?p=348</guid>
		<description><![CDATA[Thanks to VIVEK GITE for this &#8212;&#8212; Drop all tables using shell script w/o root access Nice script to run via shell I&#8217;ve small handy shell script that removes all tables without dropping and creating MySQL database again. #!/bin/bash MUSER="$1" MPASS="$2" MDB="$3" # Detect paths MYSQL=$(which mysql) AWK=$(which awk) GREP=$(which grep) if [ $# -ne [...]]]></description>
			<content:encoded><![CDATA[<p>Thanks to VIVEK  GITE  for this &#8212;&#8212;<br />
<a href="http://www.cyberciti.biz/faq/how-do-i-empty-mysql-database/comment-page-1/#comment-40082">Drop all tables using shell script w/o root access</a></p>
<p>Nice script to run via shell</p>
<p>I&#8217;ve small handy shell script that removes all tables without dropping and creating MySQL database again.</p>
<pre class="bash"><span style="color: #808080; font-style: italic;">#!/bin/bash</span>
<span style="color: #007800;">MUSER=</span><span style="color: #ff0000;">"$1"</span>
<span style="color: #007800;">MPASS=</span><span style="color: #ff0000;">"$2"</span>
<span style="color: #007800;">MDB=</span><span style="color: #ff0000;">"$3"</span>

<span style="color: #808080; font-style: italic;"># Detect paths</span>

<span style="color: #007800;">MYSQL=</span>$<span style="color: #7a0874; font-weight: bold;">(</span><span style="color: #c20cb9; font-weight: bold;">which</span> mysql<span style="color: #7a0874; font-weight: bold;">)</span>
<span style="color: #007800;">AWK=</span>$<span style="color: #7a0874; font-weight: bold;">(</span><span style="color: #c20cb9; font-weight: bold;">which</span> <span style="color: #c20cb9; font-weight: bold;">awk</span><span style="color: #7a0874; font-weight: bold;">)</span>
<span style="color: #007800;">GREP=</span>$<span style="color: #7a0874; font-weight: bold;">(</span><span style="color: #c20cb9; font-weight: bold;">which</span> <span style="color: #c20cb9; font-weight: bold;">grep</span><span style="color: #7a0874; font-weight: bold;">)</span>

<span style="color: #ffffff; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">[</span> <span style="color: #007800;">$#</span> -ne <span style="color: #ffffff;">3</span> <span style="color: #7a0874; font-weight: bold;">]</span>
<span style="color: #ffffff; font-weight: bold;">then</span>
	<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">"Usage: $0 {MySQL-User-Name} {MySQL-User-Password} {MySQL-Database-Name}"</span>

	<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">"Drops all tables from a MySQL"</span>
	<span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #ffffff;">1</span>
<span style="color: #ffffff; font-weight: bold;">fi</span>

<span style="color: #007800;">TABLES=</span>$<span style="color: #7a0874; font-weight: bold;">(</span><span style="color: #007800;">$MYSQL</span> -u <span style="color: #007800;">$MUSER</span> -p<span style="color: #007800;">$MPASS</span> <span style="color: #007800;">$MDB</span> -e <span style="color: #ff0000;">'show tables'</span> | <span style="color: #007800;">$AWK</span> <span style="color: #ff0000;">'{ print $1}'</span> | <span style="color: #007800;">$GREP</span> -v <span style="color: #ff0000;">'^Tables'</span> <span style="color: #7a0874; font-weight: bold;">)</span>

<span style="color: #ffffff; font-weight: bold;">for</span> t <span style="color: #ffffff; font-weight: bold;">in</span> <span style="color: #007800;">$TABLES</span>
<span style="color: #ffffff; font-weight: bold;">do</span>
	<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">"Deleting $t table from $MDB database..."</span>
	<span style="color: #007800;">$MYSQL</span> -u <span style="color: #007800;">$MUSER</span> -p<span style="color: #007800;">$MPASS</span> <span style="color: #007800;">$MDB</span> -e <span style="color: #ff0000;">"drop table $t"</span>

<span style="color: #ffffff; font-weight: bold;">done</span></pre>
<p>Simply use above script as follows to empty a database called quiz with username tom and password jerry:</p>
<p><code>$ ./drop.table.sh tom jerry quiz</code></p>
<p>View the full script below</p>
<p>==============</p>
<div class="format_text entry-content">
<pre class="bash"><span style="color: #808080; font-style: italic;">#!/bin/bash</span>
<span style="color: #808080; font-style: italic;"># A shell script to delete / drop all tables from MySQL database.</span>
<span style="color: #808080; font-style: italic;"># Usage: ./script user password dbnane</span>
<span style="color: #808080; font-style: italic;"># Usage: ./script user password dbnane server-ip</span>
<span style="color: #808080; font-style: italic;"># Usage: ./script user password dbnane mysql.nixcraft.in</span>
<span style="color: #808080; font-style: italic;"># -------------------------------------------------------------------------</span>
<span style="color: #808080; font-style: italic;"># Copyright <span style="color: #7a0874; font-weight: bold;">(</span>c<span style="color: #7a0874; font-weight: bold;">)</span> <span style="color: #ffffff;">2008</span> nixCraft project &lt;http://www.cyberciti.biz/fb/&gt;</span>

<span style="color: #808080; font-style: italic;"># This script is licensed under GNU GPL version <span style="color: #ffffff;">2.0</span> or above</span>
<span style="color: #808080; font-style: italic;"># -------------------------------------------------------------------------</span>
<span style="color: #808080; font-style: italic;"># This script is part of nixCraft shell script collection <span style="color: #7a0874; font-weight: bold;">(</span>NSSC<span style="color: #7a0874; font-weight: bold;">)</span></span>
<span style="color: #808080; font-style: italic;"># Visit http://bash.cyberciti.biz/ <span style="color: #ffffff; font-weight: bold;">for</span> <span style="color: #c20cb9; font-weight: bold;">more</span> information.</span>

<span style="color: #808080; font-style: italic;"># ----------------------------------------------------------------------</span>
<span style="color: #808080; font-style: italic;"># See URL <span style="color: #ffffff; font-weight: bold;">for</span> <span style="color: #c20cb9; font-weight: bold;">more</span> info:</span>
<span style="color: #808080; font-style: italic;"># http://www.cyberciti.biz/faq/how-do-i-empty-mysql-database/</span>
<span style="color: #808080; font-style: italic;"># ---------------------------------------------------</span>

<span style="color: #007800;">MUSER=</span><span style="color: #ff0000;">"$1"</span>

<span style="color: #007800;">MPASS=</span><span style="color: #ff0000;">"$2"</span>
<span style="color: #007800;">MDB=</span><span style="color: #ff0000;">"$3"</span>

<span style="color: #007800;">MHOST=</span><span style="color: #ff0000;">"localhost"</span>

<span style="color: #7a0874; font-weight: bold;">[</span> <span style="color: #ff0000;">"$4"</span> != <span style="color: #ff0000;">""</span> <span style="color: #7a0874; font-weight: bold;">]</span> &amp;&amp; <span style="color: #007800;">MHOST=</span><span style="color: #ff0000;">"$4"</span>

<span style="color: #808080; font-style: italic;"># Detect paths</span>
<span style="color: #007800;">MYSQL=</span>$<span style="color: #7a0874; font-weight: bold;">(</span><span style="color: #c20cb9; font-weight: bold;">which</span> mysql<span style="color: #7a0874; font-weight: bold;">)</span>
<span style="color: #007800;">AWK=</span>$<span style="color: #7a0874; font-weight: bold;">(</span><span style="color: #c20cb9; font-weight: bold;">which</span> <span style="color: #c20cb9; font-weight: bold;">awk</span><span style="color: #7a0874; font-weight: bold;">)</span>
<span style="color: #007800;">GREP=</span>$<span style="color: #7a0874; font-weight: bold;">(</span><span style="color: #c20cb9; font-weight: bold;">which</span> <span style="color: #c20cb9; font-weight: bold;">grep</span><span style="color: #7a0874; font-weight: bold;">)</span>

<span style="color: #808080; font-style: italic;"># help</span>
<span style="color: #ffffff; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">[</span> ! <span style="color: #007800;">$#</span> -ge <span style="color: #ffffff;">3</span> <span style="color: #7a0874; font-weight: bold;">]</span>
<span style="color: #ffffff; font-weight: bold;">then</span>
	<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">"Usage: $0 {MySQL-User-Name} {MySQL-User-Password} {MySQL-Database-Name} [host-name]"</span>

	<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">"Drops all tables from a MySQL"</span>
	<span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #ffffff;">1</span>
<span style="color: #ffffff; font-weight: bold;">fi</span>

<span style="color: #808080; font-style: italic;"># <span style="color: #c20cb9; font-weight: bold;">make</span> sure we can connect to server</span>

<span style="color: #007800;">$MYSQL</span> -u <span style="color: #007800;">$MUSER</span> -p<span style="color: #007800;">$MPASS</span> -h <span style="color: #007800;">$MHOST</span> -e <span style="color: #ff0000;">"use $MDB"</span>  &amp;&gt;/dev/null
<span style="color: #ffffff; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">[</span> $? -ne <span style="color: #ffffff;">0</span> <span style="color: #7a0874; font-weight: bold;">]</span>

<span style="color: #ffffff; font-weight: bold;">then</span>
	<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">"Error - Cannot connect to mysql server using given username, password or database does not exits!"</span>
	<span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #ffffff;">2</span>
<span style="color: #ffffff; font-weight: bold;">fi</span>

<span style="color: #007800;">TABLES=</span>$<span style="color: #7a0874; font-weight: bold;">(</span><span style="color: #007800;">$MYSQL</span> -u <span style="color: #007800;">$MUSER</span> -p<span style="color: #007800;">$MPASS</span> -h <span style="color: #007800;">$MHOST</span> <span style="color: #007800;">$MDB</span> -e <span style="color: #ff0000;">'show tables'</span> | <span style="color: #007800;">$AWK</span> <span style="color: #ff0000;">'{ print $1}'</span> | <span style="color: #007800;">$GREP</span> -v <span style="color: #ff0000;">'^Tables'</span> <span style="color: #7a0874; font-weight: bold;">)</span>

<span style="color: #808080; font-style: italic;"># <span style="color: #c20cb9; font-weight: bold;">make</span> sure tables exits</span>
<span style="color: #ffffff; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">[</span> <span style="color: #ff0000;">"$TABLES"</span> == <span style="color: #ff0000;">""</span> <span style="color: #7a0874; font-weight: bold;">]</span>
<span style="color: #ffffff; font-weight: bold;">then</span>
	<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">"Error - No table found in $MDB database!"</span>

	<span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #ffffff;">3</span>
<span style="color: #ffffff; font-weight: bold;">fi</span>

<span style="color: #808080; font-style: italic;"># <span style="color: #7a0874; font-weight: bold;">let</span> us <span style="color: #ffffff; font-weight: bold;">do</span> it</span>
<span style="color: #ffffff; font-weight: bold;">for</span> t <span style="color: #ffffff; font-weight: bold;">in</span> <span style="color: #007800;">$TABLES</span>

<span style="color: #ffffff; font-weight: bold;">do</span>
	<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">"Deleting $t table from $MDB database..."</span>
	<span style="color: #007800;">$MYSQL</span> -u <span style="color: #007800;">$MUSER</span> -p<span style="color: #007800;">$MPASS</span> -h <span style="color: #007800;">$MHOST</span> <span style="color: #007800;">$MDB</span> -e <span style="color: #ff0000;">"drop table $t"</span>

<span style="color: #ffffff; font-weight: bold;">done</span></pre>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.openkb.org/mysql-drop-all-tables-via-the-command-line/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

