<?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>PHP Log &#187; MySQL</title>
	<atom:link href="http://www.php-log.de/programmierer/mysql/feed" rel="self" type="application/rss+xml" />
	<link>http://www.php-log.de</link>
	<description>Eine feine Sammlung nützlicher PHP Notizen</description>
	<lastBuildDate>Thu, 27 May 2010 04:43:12 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>CakePHP &#8211; Arbeiten mit zwei Datenbanken</title>
		<link>http://www.php-log.de/505/php/cakephp-arbeiten-mit-zwei-datenbanken</link>
		<comments>http://www.php-log.de/505/php/cakephp-arbeiten-mit-zwei-datenbanken#comments</comments>
		<pubDate>Thu, 18 Mar 2010 14:00:21 +0000</pubDate>
		<dc:creator>ralle</dc:creator>
				<category><![CDATA[CakePHP]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://www.php-log.de/?p=505</guid>
		<description><![CDATA[Im Prinzip ist es sehr einfach mit zwei Datenbanken zu arbeiten. CakePHP erlaubt ja über die Member Variable $useDbConfig die Konfiguration zu ändern. Dieses Verfahren wird hier ganz schön beschrieben: http://blog.4webby.com/posts/view/6/cakephp_models_using_multiple_db_connections Aaaahber, was ist wenn es keine weitere Konfiguration gibt, weil mit einer flammneuen Datenbank gearbeitet werden soll, die man gerade eben erst selbst erzeugt [...]]]></description>
			<content:encoded><![CDATA[<p>Im Prinzip ist es sehr einfach mit zwei Datenbanken zu arbeiten. CakePHP erlaubt ja über die Member Variable $useDbConfig die Konfiguration zu ändern.</p>
<p><span id="more-505"></span></p>
<p>Dieses Verfahren wird hier ganz schön beschrieben: <a href="http://blog.4webby.com/posts/view/6/cakephp_models_using_multiple_db_connections">http://blog.4webby.com/posts/view/6/cakephp_models_using_multiple_db_connections</a></p>
<p>Aaaahber, was ist wenn es keine weitere Konfiguration gibt, weil mit einer flammneuen Datenbank gearbeitet werden soll, die man gerade eben erst selbst erzeugt hat? In diesem Fall hilft das &#8220;USE&#8221; Statement. Hier ein Bespiel:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// DB Wechseln</span>
<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Model</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">query</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;USE `other_db` ;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Query auf der neuen DB absetzen</span>
<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Model</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">query</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;UPDATE configuration SET configuration_value = 'foo' WHERE configuration_key =  'bar' ;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Und wieder zurück zur alten DB</span>
<span style="color: #000088;">$current_config</span>    <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Model</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getDataSource</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$original_db</span> 	    <span style="color: #339933;">=</span> <span style="color: #000088;">$current_config</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">config</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'database'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Model</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">query</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;USE `<span style="color: #006699; font-weight: bold;">$original_db</span>` ;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.php-log.de/505/php/cakephp-arbeiten-mit-zwei-datenbanken/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Ein MySQL Datum in ein Javascript Datum konvertieren</title>
		<link>http://www.php-log.de/500/mysql/ein-mysql-datum-in-ein-javascript-datum-konvertieren</link>
		<comments>http://www.php-log.de/500/mysql/ein-mysql-datum-in-ein-javascript-datum-konvertieren#comments</comments>
		<pubDate>Mon, 15 Mar 2010 03:33:17 +0000</pubDate>
		<dc:creator>ralle</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[MySQL]]></category>

		<guid isPermaLink="false">http://www.php-log.de/?p=500</guid>
		<description><![CDATA[Eine Aufgabe die nicht allzu häufig ansteht. Zumindest ich brauche so eine Funktion selten. Deswegen schreibe ich das mal hier nieder. Meine Lösung erweitert die String Funktionen von Javascript, so dass ein im MySQL Format 2010-12-24 vorliegendes Datum direkt umgewandelt werden kann. String.prototype.MySQLDateToJavascriptDate = function&#40;&#41;&#123; var res = this.split&#40;'-'&#41;; return new Date &#40; parseInt&#40;res&#91;0&#93;, 10&#41;, [...]]]></description>
			<content:encoded><![CDATA[<p>Eine Aufgabe die nicht allzu häufig ansteht. Zumindest ich brauche so eine Funktion selten. Deswegen schreibe ich das mal hier nieder.</p>
<p><span id="more-500"></span>Meine Lösung erweitert die String Funktionen von Javascript, so dass ein im MySQL Format 2010-12-24 vorliegendes Datum direkt umgewandelt werden kann.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">String.<span style="color: #660066;">prototype</span>.<span style="color: #660066;">MySQLDateToJavascriptDate</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	<span style="color: #003366; font-weight: bold;">var</span> res <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">split</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'-'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">new</span> Date <span style="color: #009900;">&#40;</span> parseInt<span style="color: #009900;">&#40;</span>res<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">10</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> parseInt<span style="color: #009900;">&#40;</span>res<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">-</span><span style="color: #CC0000;">1</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">10</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> parseInt<span style="color: #009900;">&#40;</span>res<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">2</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">10</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>	
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #006600; font-style: italic;">// Usage</span>
<span style="color: #003366; font-weight: bold;">var</span> my_date <span style="color: #339933;">=</span> <span style="color: #3366CC;">'2010-12-24'</span><span style="color: #339933;">;</span>
<span style="color: #003366; font-weight: bold;">var</span> js_date <span style="color: #339933;">=</span> my_date.<span style="color: #660066;">MySQLDateToJavascriptDate</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span>js_date.<span style="color: #660066;">toString</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #006600; font-style: italic;">// Fri Dec 24 2010 00:00:00 GMT+0100 (CET)</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.php-log.de/500/mysql/ein-mysql-datum-in-ein-javascript-datum-konvertieren/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Zend_Date in ein MySQL kompatibles Datum konvertieren</title>
		<link>http://www.php-log.de/378/php/zend_date-in-ein-mysql-kompatibles-datum-konvertieren</link>
		<comments>http://www.php-log.de/378/php/zend_date-in-ein-mysql-kompatibles-datum-konvertieren#comments</comments>
		<pubDate>Tue, 14 Jul 2009 15:58:47 +0000</pubDate>
		<dc:creator>ralle</dc:creator>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[Zend Framework]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://www.php-log.de/?p=378</guid>
		<description><![CDATA[Zend_Date hat für alle erdenklichen Ausgabeformate eine Lösung. Nur für den Einsatz als MySQL Datum nicht. das muss man noch &#8216;händisch&#8217; einrichten. Die Lösung ist natürlich sehr einfach, aber da ich das Zend Framework nur gelegentlich benutze musste ich trotzdem danach googlen. Fündig wurde ich hier: http://www.eatmybusiness.com/food/2009/01/31/how-to-get-zend-date-in-sql-timestamp-format-eg-mysql-yyyy-mm-dd-hhmmss/90/ Hier die vereinfachte Zusammenfassung: $date = new Zend_Date&#40;&#41;; [...]]]></description>
			<content:encoded><![CDATA[<p>Zend_Date hat für alle erdenklichen Ausgabeformate eine Lösung. Nur für den Einsatz als MySQL Datum nicht. das muss man noch &#8216;händisch&#8217; einrichten.<span id="more-378"></span></p>
<p>Die Lösung ist natürlich sehr einfach, aber da ich das Zend Framework nur gelegentlich benutze musste ich trotzdem danach googlen. Fündig wurde ich hier: <a href="http://www.eatmybusiness.com/food/2009/01/31/how-to-get-zend-date-in-sql-timestamp-format-eg-mysql-yyyy-mm-dd-hhmmss/90/" target="_blank">http://www.eatmybusiness.com/food/2009/01/31/how-to-get-zend-date-in-sql-timestamp-format-eg-mysql-yyyy-mm-dd-hhmmss/90/</a> </p>
<p>Hier die vereinfachte Zusammenfassung:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$date</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Zend_Date<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$sql_date_pattern</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'yyyy-MM-dd HH:mm:ss'</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$date</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">get</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$sql_date_pattern</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Achja, dann gibt es auch noch eine kleine Falle wenn man mit ein Zend_Date Object, mit einem Datum aus einer MySQL DB initialisieren will. Wer das Datum nicht vorher mit <code>strtotime()</code> behandelt kann sich einen gut versteckten Fehler einfangen.:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$day</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;2009-10-11&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Falsch</span>
<span style="color: #000088;">$date</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Zend_Date<span style="color: #009900;">&#40;</span><span style="color: #000088;">$day</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$week</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$date</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">get</span><span style="color: #009900;">&#40;</span>Zend_Date<span style="color: #339933;">::</span><span style="color: #004000;">WEEK</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">#-&gt; Nov 10, 2009 12:00:00 AM
</span>
<span style="color: #666666; font-style: italic;">// Richtig</span>
<span style="color: #000088;">$date</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Zend_Date<span style="color: #009900;">&#40;</span><span style="color: #990000;">strtotime</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$day</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$week</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$date</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">get</span><span style="color: #009900;">&#40;</span>Zend_Date<span style="color: #339933;">::</span><span style="color: #004000;">WEEK</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">#-&gt; Oct 11, 2009 12:00:00 AM</span></pre></div></div>

<p>Kurioserweise tritt dieses Phänomen bei mir nur dann auf, wenn ich das Script via CLI auf der Shell aufrufe.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.php-log.de/378/php/zend_date-in-ein-mysql-kompatibles-datum-konvertieren/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>CakePHP &#8211; SaveField mit MySQL Funktionen wie z.B. Now()</title>
		<link>http://www.php-log.de/328/mysql/cakephp-savefield-mit-mysql-funktionen-wie-zb-now</link>
		<comments>http://www.php-log.de/328/mysql/cakephp-savefield-mit-mysql-funktionen-wie-zb-now#comments</comments>
		<pubDate>Fri, 15 May 2009 10:09:44 +0000</pubDate>
		<dc:creator>ralle</dc:creator>
				<category><![CDATA[CakePHP]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[Controller]]></category>

		<guid isPermaLink="false">http://www.php-log.de/?p=328</guid>
		<description><![CDATA[Dummerweise erlaubt es CakePHP nicht beim aktualisieren eines einzelnen Datenbankfeldes auf MySQL aufzurufen. Eine kurze Rechereche braucht auch keine wirkliche Abhilfe. Das einzige was ich gefunden habe ist ein Hinweis darauf dass schon mal jemand diese Funktion vermisst hat, auch eine Patch möglich ist, dieser aber nicht in die das offizielle Release aufgenommen wird.Einzelheiten dazu [...]]]></description>
			<content:encoded><![CDATA[<p>Dummerweise erlaubt es CakePHP nicht beim aktualisieren eines einzelnen Datenbankfeldes auf MySQL aufzurufen. Eine kurze Rechereche braucht auch keine wirkliche Abhilfe. Das einzige was ich gefunden habe ist ein Hinweis darauf dass schon mal jemand diese Funktion vermisst hat, auch eine Patch möglich ist, dieser aber nicht in die das offizielle Release aufgenommen wird.<span id="more-328"></span>Einzelheiten dazu findet man im Cake <a href="https://trac.cakephp.org/ticket/3341" target="_blank">Ticketsystem</a></p>
<p>Ich mich dazu entschieden meine Datenbank Klasse nicht zu patchen, es reicht ja schon dass ich für eine saubere Ausgabe von Monatsnamen im Core rumstochern muss. Auf eine weitere Ausnahme und Fehlerquelle habe ich keine Lust mehr. Statdessen habe ich mir lieber eine simple Funktion in den Application Controller gelegt.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// Im Application Controller</span>
<span style="color: #009933; font-style: italic;">/**
 * creates a date value, suitable for mysql datetime fields
 *
 * @return string
 * @author Ralf Kramer
 */</span>
<span style="color: #000000; font-weight: bold;">function</span> now<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	<span style="color: #b1b100;">return</span> <span style="color: #990000;">strftime</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'%Y-%m-%d %H:%M:%S'</span><span style="color: #339933;">,</span> <span style="color: #990000;">time</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Im Controller dann:</span>
<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Model</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">saveField</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'a_datetime_field'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">now</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.php-log.de/328/mysql/cakephp-savefield-mit-mysql-funktionen-wie-zb-now/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>PureFTPD</title>
		<link>http://www.php-log.de/75/php/pureftpd</link>
		<comments>http://www.php-log.de/75/php/pureftpd#comments</comments>
		<pubDate>Sat, 31 Jan 2009 17:40:08 +0000</pubDate>
		<dc:creator>ralle</dc:creator>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[Administration]]></category>

		<guid isPermaLink="false">http://www.php-log.de/?p=75</guid>
		<description><![CDATA[PureFTPD ist ein FTP Server der mächtig und vor allem flexibel ist. Er ermöglicht unter anderem die Authentifikation über eine MySQL Tabelle. Dass macht ihn besonders attraktiv, insbesondere für Portale wie Video-Communities, wo große Datenmengen durch die Drähte geschickt werden müssen. Auf einem Ubuntu Rechner ist auch die Installation relativ Schmerzfrei. Eine gute Anleitung gibt [...]]]></description>
			<content:encoded><![CDATA[<p>PureFTPD ist ein FTP Server der mächtig und vor allem flexibel ist. Er ermöglicht unter anderem die Authentifikation über eine MySQL Tabelle. Dass macht ihn besonders attraktiv, insbesondere für Portale wie Video-Communities, wo große Datenmengen durch die Drähte geschickt werden müssen.</p>
<p><span id="more-75"></span>Auf einem Ubuntu Rechner ist auch die Installation relativ Schmerzfrei. Eine gute Anleitung gibt es hier:</p>
<p><a href="http://www.howtoforge.com/virtual-hosting-with-pureftpd-and-mysql-ubuntu-7.10" target="_blank">http://www.howtoforge.com/virtual-hosting-with-pureftpd-and-mysql-ubuntu-7.10</a></p>
<p>Eine Fehlerquelle kann sein dass die Queries ein Escapen erforden und das kann bei Copy &amp; Paste schon mal verloren gehen:</p>
<p>Richtig:</p>

<div class="wp_syntax"><div class="code"><pre class="sh" style="font-family:monospace;">MYSQLGetPW      SELECT Password FROM ftpd WHERE User=&quot;\L&quot; AND status=&quot;1&quot; AND (ipaccess = &quot;*&quot; OR ipaccess LIKE &quot;\R&quot;)</pre></div></div>

<p>Bunter Nachmittag wegen fehlendem Backslash:</p>

<div class="wp_syntax"><div class="code"><pre class="sh" style="font-family:monospace;">MYSQLGetPW      SELECT Password FROM ftpd WHERE User=&quot;L&quot; AND status=&quot;1&quot; AND (ipaccess = &quot;*&quot; OR ipaccess LIKE &quot;R&quot;)</pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.php-log.de/75/php/pureftpd/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MySQL User und Datenbank in einem Rutsch über die Kommandozeile</title>
		<link>http://www.php-log.de/61/mysql/mysql-user-und-datenbank-in-einem-rutsch-uber-die-kommandozeile</link>
		<comments>http://www.php-log.de/61/mysql/mysql-user-und-datenbank-in-einem-rutsch-uber-die-kommandozeile#comments</comments>
		<pubDate>Fri, 30 Jan 2009 15:11:27 +0000</pubDate>
		<dc:creator>ralle</dc:creator>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[Administration]]></category>

		<guid isPermaLink="false">http://www.php-log.de/?p=61</guid>
		<description><![CDATA[Gerade wenn man neu auf einem Server ist, kann es passieren das man mal eben schnell eine Datenbank und einen dazu gehörenden User braucht. Dieses kurze SQL File legt einen neuen User und eine neue Datenbank an und weist dem User alle Rechte an besagter neuen Datenbank zu. # file: install.sql FLUSH PRIVILEGES ; CREATE [...]]]></description>
			<content:encoded><![CDATA[<p>Gerade wenn man neu auf einem Server ist, kann es passieren das man mal eben schnell eine Datenbank und einen dazu gehörenden User braucht. Dieses kurze SQL File legt einen neuen User und eine neue Datenbank an und weist dem User alle Rechte an besagter neuen Datenbank zu.</p>
<p><span id="more-61"></span></p>

<div class="wp_syntax"><div class="code"><pre class="mysql" style="font-family:monospace;"><span style="color: #808080; font-style: italic;"># file: install.sql</span>
FLUSH <span style="color: #990099; font-weight: bold;">PRIVILEGES</span> <span style="color: #000033;">;</span>
<span style="color: #990099; font-weight: bold;">CREATE</span> <span style="color: #000099;">USER</span> <span style="color: #008000;">'userxy'</span>@<span style="color: #008000;">'localhost'</span> IDENTIFIED BY <span style="color: #008000;">'passwordxy'</span><span style="color: #000033;">;</span>
<span style="color: #990099; font-weight: bold;">GRANT</span> <span style="color: #990099; font-weight: bold;">USAGE</span> <span style="color: #990099; font-weight: bold;">ON</span> <span style="color: #CC0099;">*</span> . <span style="color: #CC0099;">*</span> <span style="color: #990099; font-weight: bold;">TO</span> <span style="color: #008000;">'userxy'</span>@<span style="color: #008000;">'localhost'</span> IDENTIFIED BY <span style="color: #008000;">'passwordxy'</span> <span style="color: #990099; font-weight: bold;">WITH</span> MAX_QUERIES_PER_HOUR <span style="color: #008080;">0</span> MAX_CONNECTIONS_PER_HOUR <span style="color: #008080;">0</span> MAX_UPDATES_PER_HOUR <span style="color: #008080;">0</span> MAX_USER_CONNECTIONS <span style="color: #008080;">0</span> <span style="color: #000033;">;</span>
<span style="color: #990099; font-weight: bold;">CREATE</span> <span style="color: #990099; font-weight: bold;">DATABASE</span> <span style="color: #990099; font-weight: bold;">IF <span style="color: #CC0099; font-weight: bold;">NOT</span> EXISTS</span> <span style="color: #008000;">`datenbankxy`</span> <span style="color: #000033;">;</span>
<span style="color: #990099; font-weight: bold;">GRANT</span> <span style="color: #990099; font-weight: bold;">ALL</span> <span style="color: #990099; font-weight: bold;">PRIVILEGES</span> <span style="color: #990099; font-weight: bold;">ON</span> <span style="color: #008000;">`datenbankxy`</span> . <span style="color: #CC0099;">*</span> <span style="color: #990099; font-weight: bold;">TO</span> <span style="color: #008000;">'userxy'</span>@<span style="color: #008000;">'localhost'</span><span style="color: #000033;">;</span>
FLUSH <span style="color: #990099; font-weight: bold;">PRIVILEGES</span> <span style="color: #000033;">;</span></pre></div></div>

<p>Auf der Shell kann dann mit</p>

<div class="wp_syntax"><div class="code"><pre class="sh" style="font-family:monospace;">mysql &lt; install.sql</pre></div></div>

<p>die Datenbank inkl. User installiert werden.</p>
<p>Achso&#8230;damit der Aufruf von mysql ohne Verbindungsparameter klappt, hinterlegt man einfach eine .my.cnf Datei im Home Folder des SSH Users. Diese Datei hat einfach folgenden Inhalt:</p>

<div class="wp_syntax"><div class="code"><pre class="sh" style="font-family:monospace;">[client]
user=ssh-username
password=strengestensgeheimundanonymisiert
&nbsp;
[mysqld]
default-character-set=utf8
default-collation=latin1_german1_ci</pre></div></div>

<p># file: install.sql</p>
]]></content:encoded>
			<wfw:commentRss>http://www.php-log.de/61/mysql/mysql-user-und-datenbank-in-einem-rutsch-uber-die-kommandozeile/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
