<?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>OSTalks &#187; mysql</title>
	<atom:link href="http://www.ostalks.com/tag/mysql/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.ostalks.com</link>
	<description>Open Source, Operating Systems, Offtopic Stuff!</description>
	<lastBuildDate>Fri, 04 Nov 2011 13:16:29 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>How to Debug Sleeping MySQL Processes</title>
		<link>http://www.ostalks.com/2011/05/17/how-to-debug-sleeping-mysql-processes/</link>
		<comments>http://www.ostalks.com/2011/05/17/how-to-debug-sleeping-mysql-processes/#comments</comments>
		<pubDate>Tue, 17 May 2011 03:09:47 +0000</pubDate>
		<dc:creator>clintcan</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[sleeping processes]]></category>

		<guid isPermaLink="false">http://www.ostalks.com/?p=561</guid>
		<description><![CDATA[A server in our environment was not working properly. This was a webserver running apache and a db server. Everything was running well, and then we experienced lots of random slowdowns and seemingly queries that do not seem to run and execute properly. Another problem was that we experienced lots of sleeping processes when we [...]]]></description>
			<content:encoded><![CDATA[<p>A server in our environment was not working properly.  This was a webserver running apache and a db server.</p>
<p>Everything was running well, and then we experienced lots of random slowdowns and seemingly queries that do not seem to run and execute properly.  Another problem was that we experienced lots of sleeping processes when we checked the db server.</p>
<p>Restarting the db server didn&#8217;t work, nor did restarting the webserver.  Checking the disk space on the db server showed that free disk space was more than adequate.  So how do you debug sleeping mysql processes?</p>
<p>In the SHOW PROCESSLIST command, one of the fields returned is the Host field.  For example:</p>
<p>xxx.xxx.xxx.xxx:39769</p>
<p>The most important part here is the port number (39769).  The ip address here in my example showed that the originating ip was one of our webservers.</p>
<p>We now log into our webserver and type in the command:<br />
netstat -ntp | grep 39769</p>
<p>This would now show (this is simulated output below):<br />
tcp        0      0 192.168.1.20:39769          192.168.1.1:3306</p>
<p>We can filter out the pid (process id) using the netstat command and using the pid do a strace command:</p>
<p>strace -p [pid]</p>
<p>In my case here, it was found out that the webserver&#8217;s /var partition was full.</p>
<p>Hope these instructions help you guys when you have some weird stuff going on with mysql and your webserver.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ostalks.com/2011/05/17/how-to-debug-sleeping-mysql-processes/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Import DBF Files To MySQL Using PHP</title>
		<link>http://www.ostalks.com/2009/12/31/import-dbf-files-to-mysql-using-php/</link>
		<comments>http://www.ostalks.com/2009/12/31/import-dbf-files-to-mysql-using-php/#comments</comments>
		<pubDate>Thu, 31 Dec 2009 00:35:35 +0000</pubDate>
		<dc:creator>clintcan</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[open source]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[convert]]></category>
		<category><![CDATA[DBase]]></category>
		<category><![CDATA[dbf]]></category>
		<category><![CDATA[FoxPro]]></category>
		<category><![CDATA[import]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[repository]]></category>
		<category><![CDATA[rpm]]></category>

		<guid isPermaLink="false">http://www.ostalks.com/?p=224</guid>
		<description><![CDATA[I recently had a task to do for a friend of mine to migrate Visual FoxPro data into a mysql database.]]></description>
			<content:encoded><![CDATA[<p>I recently had a task to do for a friend of mine to migrate Visual FoxPro data into a mysql database.</p>
<p>As a programmer that doesn&#8217;t like to re-invent the wheel, I tried searching through google, but was only partially successful in getting code to insert dbf data into mysql (it was public domain code, but only had code to insert data into a table that was created earlier).</p>
<p>This is the code modified to work with any dbf file &#8211; it creates the table, then inserts the dbf data into the created table.  The code was further modified to strip whitespaces from the text values (FoxPro/DBase pads text with spaces up to the length of the field).  You may want to change this further, since this is a quick and dirty code for the sole purpose of importing dbf tables.  This works with my rpms at the repository.</p>
<p><code><br />
<?php<br />
/*<br />
 * Part 2 code modified by Clint Christopher Canada from different public domain sources<br />
 * Part 1 code created by Clint Christopher Canada. BSD licensed.<br />
 */</p>
<p>// This is Part I of the code<br />
$tbl = "table to create";<br />
$db_uname = 'mysql username';<br />
$db_passwd = 'mysql password';<br />
$db = 'database';<br />
$conn = mysql_pconnect('localhost',$db_uname, $db_passwd); </p>
<p>// Path to dbase file<br />
$db_path = ".DBF";</p>
<p>// Open dbase file<br />
$dbh = dbase_open($db_path, 0)<br />
  or die("Error! Could not open dbase database file '$db_path'.");</p>
<p>// Get column information<br />
$column_info = dbase_get_header_info($dbh);</p>
<p>// Display information<br />
//print_r($column_info);</p>
<p>$line = array();</p>
<p>foreach($column_info as $col)<br />
{<br />
	switch($col['type'])<br />
	{<br />
		case 'character':<br />
			$line[]= "`$col[name]` VARCHAR( $col[length] )";<br />
			break;<br />
		case 'number':<br />
			$line[]= "`$col[name]` FLOAT";<br />
			break;<br />
		case 'boolean':<br />
			$line[]= "`$col[name]` BOOL";<br />
			break;<br />
		case 'date':<br />
			$line[]= "`$col[name]` DATE";<br />
			break;<br />
		case 'memo':<br />
			$line[]= "`$col[name]` TEXT";<br />
			break;<br />
	}<br />
}<br />
$str = implode(",",$line);<br />
$sql = "CREATE TABLE `$tbl` ( $str );";</p>
<p>mysql_select_db($db,$conn);</p>
<p>mysql_query($sql,$conn);<br />
set_time_limit(0); // I added unlimited time limit here, because the records I imported were in the hundreds of thousands.</p>
<p>// This is part 2 of the code</p>
<p>import_dbf($db, $tbl, $db_path);</p>
<p>function import_dbf($db, $table, $dbf_file)<br />
{<br />
    global $conn;<br />
    if (!$dbf = dbase_open ($dbf_file, 0)){ die("Could not open $dbf_file for import."); }<br />
    $num_rec = dbase_numrecords($dbf);<br />
    $num_fields = dbase_numfields($dbf);<br />
    $fields = array();</p>
<p>    for ($i=1; $i<=$num_rec; $i++){<br />
        $row = @dbase_get_record_with_names($dbf,$i);<br />
        $q = "insert into $db.$table values (";<br />
        foreach ($row as $key => $val){<br />
            if ($key == 'deleted'){ continue; }<br />
            $q .= "'" . addslashes(trim($val)) . "',"; // Code modified to trim out whitespaces<br />
        }<br />
        if (isset($extra_col_val)){ $q .= "'$extra_col_val',"; }<br />
        $q = substr($q, 0, -1);<br />
        $q .= ')';<br />
        //if the query failed - go ahead and print a bunch of debug info<br />
        if (!$result = mysql_query($q, $conn)){<br />
            print (mysql_error() . " SQL: $q<br />\n");<br />
            print (substr_count($q, ',') + 1) . " Fields total.
<p>";<br />
            $problem_q = explode(',', $q);<br />
            $q1 = "desc $db.$table";<br />
            $result1 = mysql_query($q1, $conn);<br />
            $columns = array();<br />
            $i = 1;<br />
            while ($row1 = mysql_fetch_assoc($result1)){<br />
                $columns[$i] = $row1['Field'];<br />
                $i++;<br />
            }<br />
            $i = 1;<br />
            foreach ($problem_q as $pq){<br />
                print "$i column: {$columns[$i]} data: $pq<br />\n";<br />
                $i++;<br />
            }<br />
            die();<br />
        }<br />
    }<br />
}</p>
<p>?><br />
</code></p>
]]></content:encoded>
			<wfw:commentRss>http://www.ostalks.com/2009/12/31/import-dbf-files-to-mysql-using-php/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>

