<?xml version="1.0" encoding="UTF-8"?>
<codes type="array">
  <code>
    <code>mysqldump -u username -ppassword &#8211;all-databases &gt; dump.sql</code>
    <created-at type="datetime">2009-08-22T15:26:33Z</created-at>
    <description></description>
    <id type="integer">193</id>
    <language-id type="integer">42</language-id>
    <privated type="boolean">false</privated>
    <title>backup all mysql database</title>
    <updated-at type="datetime">2009-08-22T15:26:33Z</updated-at>
    <user-id type="integer">7</user-id>
  </code>
  <code>
    <code>SELECT COUNT(*) AS Total, SUBSTRING_INDEX(email, '@', -1) AS Domain FROM users 
GROUP BY SUBSTRING_INDEX(email, '@', -1) ORDER BY COUNT(*) DESC LIMIT 10;</code>
    <created-at type="datetime">2009-07-12T17:47:15Z</created-at>
    <description>from: http://www.mendable.com/sql-trick-where-are-your-users-from/</description>
    <id type="integer">186</id>
    <language-id type="integer">40</language-id>
    <privated type="boolean">false</privated>
    <title>count domain users using sql</title>
    <updated-at type="datetime">2009-07-12T17:50:03Z</updated-at>
    <user-id type="integer">7</user-id>
  </code>
  <code>
    <code>-- mostra o n&#250;mero de usu&#225;rios novos criados dia a dia
select date_format(created_at,'%d/%m/%y') as data, count(id) as total from leonardo_supertestes.users group by date_format(created_at,'%m-%d') order by date_format(created_at,'%m-%d');

-- mostra o n&#250;mero de testes feitos dia a dia
select date_format(created_at,'%d/%m/%y') as data, count(rate) as total from leonardo_supertestes.results group by date_format(created_at,'%m-%d') order by date_format(created_at,'%m-%d');

-- conta o n&#250;mero total de usu&#225;rios
select count(id) from leonardo_supertestes.users;

-- conta o n&#250;mero total de testes feitos
select sum(hits) from leonardo_supertestes.exams;</code>
    <created-at type="datetime">2009-05-24T16:45:07Z</created-at>
    <description></description>
    <id type="integer">177</id>
    <language-id type="integer">40</language-id>
    <privated type="boolean">true</privated>
    <title>autosimulado queries</title>
    <updated-at type="datetime">2009-05-24T16:45:07Z</updated-at>
    <user-id type="integer">7</user-id>
  </code>
  <code>
    <code>Export
mysqldump -u username -p -h mysqlhostname databasename &gt; databasedump.sql

Import
mysql -u username -p -h mysqlhostname databasename &lt; databasedump.sql</code>
    <created-at type="datetime">2008-10-17T02:55:50Z</created-at>
    <description>import/export a database via terminal</description>
    <id type="integer">76</id>
    <language-id type="integer">42</language-id>
    <privated type="boolean">false</privated>
    <title>mysql dump</title>
    <updated-at type="datetime">2008-10-17T02:55:50Z</updated-at>
    <user-id type="integer">7</user-id>
  </code>
  <code>
    <code>sudo launchctl unload -w /Library/LaunchDaemons/com.mysql.mysqld.plist
sudo launchctl load -w /Library/LaunchDaemons/com.mysql.mysqld.plis</code>
    <created-at type="datetime">2008-10-17T02:54:47Z</created-at>
    <description></description>
    <id type="integer">75</id>
    <language-id type="integer">42</language-id>
    <privated type="boolean">false</privated>
    <title>stop/start mysql via terminal </title>
    <updated-at type="datetime">2008-10-17T02:54:47Z</updated-at>
    <user-id type="integer">7</user-id>
  </code>
  <code>
    <code>&lt;?php

function backup_tables($host,$user,$pass,$name,$tables = '*'){
	
	$link = mysql_connect($host,$user,$pass);
	mysql_select_db($name,$link);
	
	//get all of the tables
	if($tables == '*')
	{
		$tables = array();
		$result = mysql_query('SHOW TABLES');
		while($row = mysql_fetch_row($result))
		{
			$tables[] = $row[0];
		}
	}
	else
	{
		$tables = is_array($tables) ? $tables : explode(',',$tables);
	}
	
	//cycle through
	foreach($tables as $table)
	{
		$result = mysql_query('SELECT * FROM '.$table);
		$num_fields = mysql_num_fields($result);
		for ($i = 0; $i &lt; $num_fields; $i++) 
		{
			$return.= 'DROP TABLE '.$table.';';
			
			$row2 = mysql_fetch_row(mysql_query('SHOW CREATE TABLE '.$table));
			$return.= &quot;\n\n&quot;.$row2[1].&quot;;\n\n&quot;;
			
			while($row = mysql_fetch_row($result))
			{
				$return.= 'INSERT INTO '.$table.' VALUES(';
				for($j=0; $j&lt;$num_fields; $j++) 
				{
					$row[$j] = addslashes($row[$j]);
					$row[$j] = ereg_replace(&quot;\n&quot;,&quot;\\n&quot;,$row[$j]);
					if (isset($row[$j])) { $return.= '&quot;'.$row[$j].'&quot;' ; } else { $return.= '&quot;&quot;'; }
					if ($j&lt;($num_fields-1)) { $return.= ','; }
				}
				$return.= &quot;);\n&quot;;
			}
		}
		$return.=&quot;\n\n\n&quot;;
	}
	
	//save file
	$handle = fopen('db-backup-'.time().'-'.(md5(implode(',',$tables))).'.sql','w+');
	fwrite($handle,$return);
	fclose($handle);
}

backup_tables('localhost','username','password','blog');

?&gt;</code>
    <created-at type="datetime">2008-09-01T00:10:48Z</created-at>
    <description></description>
    <id type="integer">55</id>
    <language-id type="integer">35</language-id>
    <privated type="boolean">false</privated>
    <title>php script for mysql backup</title>
    <updated-at type="datetime">2008-09-01T00:10:48Z</updated-at>
    <user-id type="integer">7</user-id>
  </code>
  <code>
    <code>echo DROP TABLE `echo 'SHOW TABLES;' | mysql -u USER -p DATABASE | tail -n +2 | sed -e 's/$/,/'` | sed -e 's/,$/;/'</code>
    <created-at type="datetime">2008-07-31T21:31:30Z</created-at>
    <description>run in shell: </description>
    <id type="integer">44</id>
    <language-id type="integer">42</language-id>
    <privated type="boolean">false</privated>
    <title>Drop all tables in a MySQL Database</title>
    <updated-at type="datetime">2008-07-31T21:31:30Z</updated-at>
    <user-id type="integer">7</user-id>
  </code>
  <code>
    <code>mysqldump --al-databases -u -p &gt; backup.sql</code>
    <created-at type="datetime">2008-07-04T00:43:01Z</created-at>
    <description></description>
    <id type="integer">16</id>
    <language-id type="integer">42</language-id>
    <privated type="boolean">false</privated>
    <title>mysql one line all database backup</title>
    <updated-at type="datetime">2008-07-04T00:43:01Z</updated-at>
    <user-id type="integer">1</user-id>
  </code>
  <code>
    <code>ALTER TABLE tablename AUTO_INCREMENT = 1</code>
    <created-at type="datetime">2008-07-02T00:31:31Z</created-at>
    <description></description>
    <id type="integer">10</id>
    <language-id type="integer">40</language-id>
    <privated type="boolean">false</privated>
    <title>resets autoincrement (mysql)</title>
    <updated-at type="datetime">2008-07-02T00:31:31Z</updated-at>
    <user-id type="integer">7</user-id>
  </code>
</codes>
