<?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>Armand Brahaj - Blog Personal &#187; MySQL</title>
	<atom:link href="http://armandbrahaj.blog.al/category/information-technology/mysql/feed/" rel="self" type="application/rss+xml" />
	<link>http://armandbrahaj.blog.al</link>
	<description>Mendime te ndryshme, probleme teknike e te ngjashme</description>
	<lastBuildDate>Wed, 21 Jul 2010 13:22:24 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=abc</generator>
<image>
  <link>http://armandbrahaj.blog.al</link>
  <url>http://armandbrahaj.blog.al//wp-content/uploads/2009/04/shqiperiacom-logo.png</url>
  <title>Armand Brahaj - Blog Personal</title>
</image>
	<atom:link rel='hub' href='http://armandbrahaj.blog.al/?pushpress=hub'/>
<cloud domain='armandbrahaj.blog.al' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
		<item>
		<title>MySQL Remove Duplicates</title>
		<link>http://armandbrahaj.blog.al/2009/12/17/mysql-remove-dublicates/</link>
		<comments>http://armandbrahaj.blog.al/2009/12/17/mysql-remove-dublicates/#comments</comments>
		<pubDate>Thu, 17 Dec 2009 10:58:54 +0000</pubDate>
		<dc:creator>Mandi</dc:creator>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[columns]]></category>
		<category><![CDATA[duplicate]]></category>
		<category><![CDATA[remove duplicates]]></category>

		<guid isPermaLink="false">http://armandbrahaj.blog.al/?p=1209</guid>
		<description><![CDATA[A quick method to remove duplicate records from your database: ALTER IGNORE TABLE tablename ADD UNIQUE INDEX dublicatedindex (fieldthatcontaindoubles); ALTER TABLE tablename DROP INDEX dublicatedindex The method above will remove dublicates and will add a Unique key to the field of interest. Another non-recommended option is: CREATE TABLE tablenamenew as SELECT * FROM acttable WHERE [...]]]></description>
			<content:encoded><![CDATA[<p>A quick method to remove duplicate records from your database:</p>
<blockquote><p>ALTER IGNORE TABLE tablename ADD UNIQUE INDEX dublicatedindex (fieldthatcontaindoubles);<br />
ALTER TABLE tablename DROP INDEX dublicatedindex</p></blockquote>
<p>The method above will remove dublicates and will add a Unique key to the field of interest.</p>
<p>Another non-recommended option is:</p>
<blockquote><p>CREATE TABLE tablenamenew as SELECT * FROM acttable WHERE 1 GROUP BY fieldthatcontaindoubles;</p></blockquote>
<p>The syntax will create a new table that has unique records on <em>fieldthatcontaindoubles</em><br />
<h3>Artikuj të ngjashëm</h3>
<ul class="related_post">
<li>09/21/2009 &#8212; <a href="http://armandbrahaj.blog.al/2009/09/21/mysql-database-replication/" title="MySQL Database Replication">MySQL Database Replication (6)</a></li>
<li>06/07/2009 &#8212; <a href="http://armandbrahaj.blog.al/2009/06/07/how-to-install-mysql-monitoring-tools-mtop-for-centos-debian/" title="How to install MySQL Monitoring Tools mtop for CentOS Debian ">How to install MySQL Monitoring Tools mtop for CentOS Debian  (1)</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://armandbrahaj.blog.al/2009/12/17/mysql-remove-dublicates/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MySQL Database Replication</title>
		<link>http://armandbrahaj.blog.al/2009/09/21/mysql-database-replication/</link>
		<comments>http://armandbrahaj.blog.al/2009/09/21/mysql-database-replication/#comments</comments>
		<pubDate>Mon, 21 Sep 2009 21:49:42 +0000</pubDate>
		<dc:creator>Mandi</dc:creator>
				<category><![CDATA[Infoarkiva]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[Webi Shqip]]></category>
		<category><![CDATA[databaze e madhe]]></category>
		<category><![CDATA[search]]></category>

		<guid isPermaLink="false">http://armandbrahaj.blog.al/?p=951</guid>
		<description><![CDATA[<div class="wp-caption alignleft" style="width: 160px;"><img class="size-full wp-image-957" title="replication" src="http://armandbrahaj.blog.al/wp-content/uploads/2009/09/replication1.jpg" alt="Replication" width="150" height="150"><p class="wp-caption-text">Replication</p></div>
<p>Kur nje projekt arrin nje fare volumi informacioni, vihet re qe nuk eshte me e lehte te administrohet databaza e tij. Ne rastin tone, Projekti i Infoarkives, (http://lajme.shqiperia.com), kaloi mbi 2.1 Giga informacion. Per kete projekt ne kishim vendosur nje server te dedikuar ne dispozicion. Megjithe sistemin e cache per te rritur performancen apo procesorin e mire, duke qene se disa here brenda dites serveri terhiqte lajme dhe i shkruante ne DB, sherbimi web u be teper i ngadalte dhe po krijonte problem.</p>]]></description>
			<content:encoded><![CDATA[<div id="attachment_957" class="wp-caption alignleft" style="width: 160px"><a href="http://armandbrahaj.blog.al/wp-content/uploads/2009/09/replication1.jpg"><img class="size-full wp-image-957" title="replication" src="http://armandbrahaj.blog.al/wp-content/uploads/2009/09/replication1.jpg" alt="Replication" width="150" height="150" /></a><p class="wp-caption-text">Replication</p></div>
<p>Kur nje projekt arrin nje fare volumi informacioni, vihet re qe nuk eshte me e lehte te administrohet databaza e tij. Ne rastin tone, Projekti i Infoarkives, (<a title="Lajmet e dites" href="http://lajme.shqiperia.com/media/artikull/iden/225028/titulli/" target="_blank">http://lajme.shqiperia.com</a>), kaloi mbi 2.1 Giga informacion. Per kete projekt ne kishim vendosur nje server te dedikuar ne dispozicion. Megjithe sistemin e cache per te rritur performancen apo procesorin e mire, duke qene se disa here brenda dites serveri terhiqte lajme dhe i shkruante ne DB, sherbimi web u be teper i ngadalte dhe po krijonte problem.</p>
<p>Nga natyra, tabelat myisam jane teper te shpejta ne lexim dhe nxjerrje te informacionit, por problemi kryesor shkrimi ne databaze. Rrobotet e kerkimit terhiqnin informacion i cili shkruhet ne disa tabela dhe nje prej tyre me madhesi prej afro 2Giga. Procesi i shkrimit ne nje tabele te madhe MySQL rrezultoi teper i shtrenjte. Ne nje situate kur shkrimi zgjat disa seconda dhe vendos nje &#8220;kycje&#8221; per leximin apo indeksimin e leximeve ne DB, nga mysql krijohej nje bottleneck dhe webserveri nuk pergjigjej me shpejtesine e duhur.</p>
<p>Per te zgjidhur probleme te tilla ka disa skenare.</p>
<ul>
<li>Shtimi i RAM ne server per te lejuar cache me te mire per mysql</li>
<li>Ndarja e tabelave te informacionit ne tabela me te vogla. Per kete do duhej kalimi ne InnoDB ku perseri kerkesat per RAM do ishin me te larta</li>
<li>Kalimi ne nje strukture no-sql, pra ruajtje statike e informacionit</li>
<li>Ndarja e sherbimit te mysql ne nje server te ndryshem nga webserveri</li>
</ul>
<p>Megjithese kishim bere disa optimizime ne MySQL dhe ne Apache per te lehtesuar proceset e secilit, ekzekutimi i te dy ketyre sherbimeve krijonte probleme. Ne nje situate te tille, shtimi i RAM ne server (qe eshte i kushtueshem) nuk ishte nje zgjidhje afatgjate.</p>
<p>Fatmiresisht, MySQL lejon Replikimin e databazes. Praktikisht nje server i cilesuar si kryesori (MASTER) mund te replikohet (kopjohet) nga motorri i MySQl ne disa servera te tjere qe quhen Skllever (Slaves). Ne nje situate te tille, eshte e mundur qe serveri kryesor (master) te perdoret per shkrimin e te dhenave nga rrobotet, dhe serveri skllav mund te perdoret per leximin e te dhenave nga webserveri. Ishte kjo zgjidhja qe zgjodhem per rastin e Infoarkives, praktikisht hapat e implementimit jane me poshte.</p>
<p>Krijimi i Log File te MySQL</p>
<p>Replikimi ne MySQL funksionon mbi loget e serverit.  Ketu nuk flitet per loget normal qe tregojne logimin e userave, por logu binar i MySQL.</p>
<p>Logu Binar permban te gjithe komandat qe ndryshojne te dhenat ose qe mund te ndryshojne te dhenat (psh INSERT). Keto komanda (statements) ruhen ne menyre kronologjike qe pershkruajne modifikimet. Nje nga qellimet e ketij logu binar eshte pikerisht replikimi.<br />
Per replikimet, logu binar perdoret tek serveri kryesor (master) si nje rekord i komandave qe duhet ti dergohen sklleverve. Servero kryesor i dergon ngjarjet qe ndodhen ne logun binar tek serveri skllav i cili i ekzekuton ato ne menyren kronologjike (Shih me shume: <a title="Mysql Replication" title='Original Link: http://dev.mysql.com/doc/refman/5.0/en/binary-log.html'  href="http://armandbrahaj.blog.al/?WXwD5NnX" target="_blank">Manualin e References se MySQL</a>).</p>
<p>Per te krijuar logun binar, modifikohet skedari: my.cnf (zakonisht gjendet nen /etc/my.cnf) qe te permbaje komandat me poshte:</p>
<div class="syhi_block"><code>log-bin = /var/lib/mysqllog/mysql-bin.log<br />
binlog-do-db=db_arkivaime<br />
server-id=1</code></div>
<p>Rrjeshti i pare komandon mySQL qe te shkruaje nje Log dhe ta shkruaje ate pikerisht ne direktorine mesiper. (Kjo direktori duhet te jete me te drejta shkrimi nga perdoruesi mysql).  Rrjeshti i dyte eshte nje reference per databazen qe do te replikohet (kujdes, replikohet nje DB dhe jo te gjitha DBte e serverit.) Ne rastin me siper po replikoj db_arkivaime. Ndersa rrjeshti i trete percakton nga nje Identifikim (unik sigurisht) te ketij serveri.  Nje identifikim unik do percaktohet pak me pas dhe tek serveri skllav.</p>
<p>Ne menyre qe databaza qe do replikohet te lexohet nga serveri skllav, duhet qe ne mysql te krijohet nje user i cili ka te drejta replikimi.</p>
<p>Ne phpmyadmin apo ne mysql console (mysql -u root -p) duhet te krijohet nje perdoures me sintaksen si me poshte:</p>
<div class="syhi_block"><code>GRANT REPLICATION SLAVE ON *.* TO 'perdoruesiSkllav'@'IPjaeserveritSkllav' IDENTIFIED BY 'fjalekalimi';<br />
FLUSH PRIVILEGES;</code></div>
<p>Me tej, ne serverin skllav duhet te modifikohet my.cnf duke shtuar informacionin si me poshte:</p>
<div class="syhi_block"><code>server-id=2<br />
master-host=IPeMasterServer<br />
master-connect-retry=60<br />
master-user=perdoruesiSkllav<br />
master-password=fjalekalimi<br />
replicate-do-db=db_arkivaime</code></div>
<p>relay-log = /var/lib/mysql/skllav-relay.log<br />
relay-log-index = /var/lib/mysql/skllav-relay-log.index</p>
<p>Sintaksa pak a shume eshte e qarte, rrjeshti i pare percakton nje identifikim per kete server dhe i percakton atij nr 2 si emertim. Rrjeshtat me poshte tregojne perdoruesin me te cilin mund te lidhet serveri skllav me serverin kryesor dhe ne fund ka disa loge qe i duhen motorrit te MySQL per te mbajtur shenim positionin ne te cilin serveri kryesor eshte tek logs.</p>
<p>Ne kete cast eshte e nevojshme te ndalohet serveri kryesor dhe te kopjohet databaza aktuale ne serverin skllav (ne kete menyre te dy serverat do te nisin replikimin duke pasur te njejtin informacion). Metoda ime e preferuar eshte me rsync dhe pasi te jete krijuar dhe databaza &#8220;db_arkivaime&#8221; dhe tek serveri skllav, mund te kopjohen te gjitha te dhenat nga serveri kryesor tek serveri skllav me sintaksen me poshte:</p>
<div class="syhi_block"><code>rsync -avz -e ssh root@IPserveriKryesor:/var/lib/mysql/db_arkivaime/ /var/lib/mysql/db_arkivaime/</code></div>
<p>Sintaksa me siper, ekzekutohet ne serverin skllav dhe kopjon ne menyre binare gjithcka qe ndodhet nen /var/lib/mysql/db_arkivaime/ tek e njejta direktori ne serverin tjeter. Normalisht ky eshte path-i ku ruhen te dhenat e DBve (nje bashkesi skedaresh, .MYI, frm, MYD).</p>
<p>Pervec rsync (per databaza te medha), mysqldump (apo phpmyadmin dump) mund te perdoren per te kopjuar databazen nga masteri tek serveri.</p>
<p>Per te gjetur pozicionin e serverit kryesor ne Logs duhet te ekzekutohet (serveri duhet startuar me pare):</p>
<div class="syhi_block"><code>SHOW MASTER STATUS;</code></div>
<p>ne mysql console apo phpmyadmin te serverit Master. Pergjigja do jete dicka e tipit:</p>
<div class="syhi_block"><code>+------------------+----------+----------------+------------------+<br />
| File             &nbsp; &nbsp; &nbsp; &nbsp;| &nbsp; Position | Binlog_Do_DB   | Binlog_Ignore_DB |<br />
+------------------+----------+----------------+------------------+<br />
| mysql-bin.000003 |   199749 &nbsp; | db_arkivaime |                  |<br />
+------------------+----------+----------------+------------------+<br />
1 row in set (0.00 sec)</code></div>
<p>Ne kete cast tek Serveri Skllav duhet te ekzekutohet:</p>
<div class="syhi_block"><code>slave stop;<br />
CHANGE MASTER TO MASTER_HOST='IPKryesor', MASTER_USER='perdoruesiSkllav', MASTER_PASSWORD='fjalekalimi', MASTER_LOG_FILE='mysql-bin.000003', MASTER_LOG_POS=199749;<br />
slave start;</code></div>
<p>Pas nje restarti te serveri te slave mund te shikohet qe cdo veprim Update, Insert apo Delete ne serverin master reflektohet real time tek serveri skllav.<br />
<h3>Artikuj të ngjashëm</h3>
<ul class="related_post">
<li>12/17/2009 &#8212; <a href="http://armandbrahaj.blog.al/2009/12/17/mysql-remove-dublicates/" title="MySQL Remove Duplicates">MySQL Remove Duplicates (0)</a></li>
<li>06/07/2009 &#8212; <a href="http://armandbrahaj.blog.al/2009/06/07/how-to-install-mysql-monitoring-tools-mtop-for-centos-debian/" title="How to install MySQL Monitoring Tools mtop for CentOS Debian ">How to install MySQL Monitoring Tools mtop for CentOS Debian  (1)</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://armandbrahaj.blog.al/2009/09/21/mysql-database-replication/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>How to install MySQL Monitoring Tools mtop for CentOS Debian</title>
		<link>http://armandbrahaj.blog.al/2009/06/07/how-to-install-mysql-monitoring-tools-mtop-for-centos-debian/</link>
		<comments>http://armandbrahaj.blog.al/2009/06/07/how-to-install-mysql-monitoring-tools-mtop-for-centos-debian/#comments</comments>
		<pubDate>Sun, 07 Jun 2009 00:15:09 +0000</pubDate>
		<dc:creator>Mandi</dc:creator>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[Webi Shqip]]></category>
		<category><![CDATA[centos]]></category>
		<category><![CDATA[high load]]></category>
		<category><![CDATA[monitoring]]></category>
		<category><![CDATA[mtop]]></category>
		<category><![CDATA[mtop tool]]></category>
		<category><![CDATA[optimize mysql]]></category>

		<guid isPermaLink="false">http://armandbrahaj.blog.al/?p=607</guid>
		<description><![CDATA[<div class="wp-caption alignleft" style="width: 250px;"><a title="· ·T· ·eam·  Keule &#38; Kalle" href="http://flickr.com/photos/65336381@N00/2541600095"><img title="Monitore your MySQL Server" src="http://farm3.static.flickr.com/2278/2541600095_9d77df4fb9_m.jpg" alt="" width="240" height="135"></a><p class="wp-caption-text">Monitor' your MySQL Server</p></div>
<p>If a webserver with Apache and MySQL is having a high load or apache takes too long to respond, most of the times it is a problem with the MySQL Server. In order to find out what is causing the Load and which mysql database is taking too much time to respond, mtop (MySQL Monitoring Tools) is the perfect tool for monitoring.</p>]]></description>
			<content:encoded><![CDATA[<div class="wp-caption alignleft" style="width: 250px"><a title="· ·T· ·eam·  Keule &amp; Kalle" title='Original Link: http://flickr.com/photos/65336381@N00/2541600095'  href="http://armandbrahaj.blog.al/?DQWJGVjn"><img title="Monitore your MySQL Server" src="http://farm3.static.flickr.com/2278/2541600095_9d77df4fb9_m.jpg" alt="" width="240" height="135" /></a><p class="wp-caption-text">Monitor&#39; your MySQL Server</p></div>
<p>If a webserver with Apache and MySQL is having a high load or apache takes too long to respond, in the most of the cases it is a the MySQL that is causing the high load. In order to find out what is causing the Load and which of the Mysql database is taking too much time to respond, mtop (MySQL Monitoring Tools) is the perfect tool for monitoring.</p>
<p>As described from the <a title="Mtop Mysql Monitoring Tool" rel="nofollow" title='Original Link: http://mtop.sourceforge.net/'  href="http://armandbrahaj.blog.al/?ZOrag8TL" target="_blank">Official Home page</a>, <em>&#8220;mtop (MySQL top) monitors a MySQL server showing the queries which are taking the most amount of time to complete. Features include &#8216;zooming&#8217; in on a process to show the complete query, &#8216;explaining&#8217; the query optimizer information for a query and &#8216;killing&#8217; queries. In addition, server performance statistics, configuration information, and tuning tips are provided. &#8220;</em></p>
<h4>Debian Installation</h4>
<p>If you are using a Debain Server, installing mtop is easy through apt-get</p>
<blockquote><p>apt-get install mtop</p></blockquote>
<p>If the Debian installation complains because of the new root password! Change back to empty the root password, and reset it as below.</p>
<blockquote><p>$ mysql -u root -p</p>
<p>* Enter the following MySQL command:<br />
<span class="foldable-quoted"> &gt;SET PASSWORD FOR root@localhost=PASSWORD(&#8221;);QUIT; </span></p>
<p>* install mtop<br />
apt-get install mtop</p>
<p>* Set MySQL root password to irs previous value:</p>
<p>$      mysql -u root -p<br />
<span class="foldable-quoted"> &gt;SET PASSWORD FOR root@localhost=PASSWORD(&#8216;YOURROOTPASSWORD&#8217;);QUIT; </span></p></blockquote>
<p><span class="foldable-quoted" style="font-size:90%">(Credits for the solution above: https://bugs.launchpad.net/debian/+source/mtop/+bug/77980)<br />
</span></p>
<h4>CentOS Installation</h4>
<p>Installing the mtop tool on a CentOS system is a little bit more tricky as there is no official support in the main yum channels. Even though, there exists some packages from the website: <a title="Dag Wieers" rel="nofollow" title='Original Link: http://dag.wieers.com/'  href="http://armandbrahaj.blog.al/?QSGin6hc" target="_blank">http://dag.wieers.com/</a></p>
<p>Based on the architecture you are using, navigate to the <a title="Mtop RPM Package" rel="nofollow" title='Original Link: http://dag.wieers.com/rpm/packages/mtop/'  href="http://armandbrahaj.blog.al/?1P88nzYQ" target="_blank">http://dag.wieers.com/rpm/packages/mtop/</a> website and retrieve and install the mtop rpm package.</p>
<blockquote><p>cd ~</p>
<p>wget http://dag.wieers.com/rpm/packages/mtop/mtop-0.6.6-1.2.el5.rf.noarch.rpm</p>
<p>rpm -ivh wget http://dag.wieers.com/rpm/packages/mtop/mtop-0.6.6-1.2.el5.rf.noarch.rpm</p></blockquote>
<p>If the installation failes with the message:</p>
<blockquote><p>warning: mtop-0.6.6-1.2.el5.rf.noarch.rpm: Header V3 DSA signature: NOKEY, key ID 6b8d79e6<br />
error: Failed dependencies:<br />
perl(Curses) is needed by mtop-0.6.6-1.2.el5.rf.noarch</p></blockquote>
<p>then you need to install Curses. The good news is that http://dag.wieers.com has support also for this library. By navigating to the: <a title="Perl Curses RPM" rel="nofollow" title='Original Link: http://dag.wieers.com/rpm/packages/perl-Curses/'  href="http://armandbrahaj.blog.al/?eJoLuxZi" target="_blank">http://dag.wieers.com/rpm/packages/perl-Curses/</a> you will be able to find the Perl Curses library that corresponds to the architecture of your system.<br />
The installation is the same as above, <em>wget </em>and <em>rpm -ivh</em> Curses and agatin <em>mtop</em>.<br />
<h3>Artikuj të ngjashëm</h3>
<ul class="related_post">
<li>01/25/2010 &#8212; <a href="http://armandbrahaj.blog.al/2010/01/25/restarto-apache-nese-serveri-arrin-nje-limit-te-caktuar-ngarkese/" title="Restarto Apache nese serveri arrin nje limit te caktuar ngarkese">Restarto Apache nese serveri arrin nje limit te caktuar ngarkese (3)</a></li>
<li>12/17/2009 &#8212; <a href="http://armandbrahaj.blog.al/2009/12/17/mysql-remove-dublicates/" title="MySQL Remove Duplicates">MySQL Remove Duplicates (0)</a></li>
<li>09/21/2009 &#8212; <a href="http://armandbrahaj.blog.al/2009/09/21/mysql-database-replication/" title="MySQL Database Replication">MySQL Database Replication (6)</a></li>
<li>05/02/2009 &#8212; <a href="http://armandbrahaj.blog.al/2009/05/02/debian-and-i-am-loving-it/" title="Debian and I am loving it">Debian and I am loving it (2)</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://armandbrahaj.blog.al/2009/06/07/how-to-install-mysql-monitoring-tools-mtop-for-centos-debian/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Backup database pa pasur nevoje per phpMyAdmin apo Shell</title>
		<link>http://armandbrahaj.blog.al/2009/04/13/backup-database-pa-pasur-nevoje-per-phpmyadmin-apo-shell/</link>
		<comments>http://armandbrahaj.blog.al/2009/04/13/backup-database-pa-pasur-nevoje-per-phpmyadmin-apo-shell/#comments</comments>
		<pubDate>Mon, 13 Apr 2009 19:57:02 +0000</pubDate>
		<dc:creator>Mandi</dc:creator>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[Servers]]></category>
		<category><![CDATA[Webi Shqip]]></category>
		<category><![CDATA[backup]]></category>
		<category><![CDATA[databaze]]></category>
		<category><![CDATA[db]]></category>
		<category><![CDATA[mysqldump]]></category>
		<category><![CDATA[php script]]></category>
		<category><![CDATA[ruaj]]></category>
		<category><![CDATA[shell]]></category>

		<guid isPermaLink="false">http://armandbrahaj.blog.al/?p=172</guid>
		<description><![CDATA[PhpMyAdmin është një web-program fantastik për administrimin e një databaze në MySQL. Këtë program e instalojmë gjithmonë në serverat e administruar nga Host.al dhe ua rekomandojmë të gjithë klientëve tanë. Megjithatë ndodh që ka raste që në seksionin e programimit kemi nevojë të punojmë me databaza në servera jo vetëm të kompanisë sonë, por dhe [...]]]></description>
			<content:encoded><![CDATA[<div id="attachment_173" class="wp-caption alignleft" style="width: 138px"><a href="http://armandbrahaj.blog.al/wp-content/uploads/2009/04/database.png"><img class="size-full wp-image-173" title="Database" src="http://armandbrahaj.blog.al/wp-content/uploads/2009/04/database.png" alt="Backup" width="128" height="128" /></a><p class="wp-caption-text">Backup</p></div>
<p><a title='Original Link: http://www.phpmyadmin.net'  href="http://armandbrahaj.blog.al/?uHZsKM0D" target="_blank">PhpMyAdmin </a>është një web-program fantastik për administrimin e një databaze në <a title="MySQL" title='Original Link: http://www.mysql.com'  href="http://armandbrahaj.blog.al/?zPwxbQb2" target="_blank">MySQL</a>. Këtë program e instalojmë gjithmonë në serverat e administruar nga <a title="Host.al Servera te dedikuar" title='Original Link: http://www.host.al'  href="http://armandbrahaj.blog.al/?bdu6xmND" target="_blank">Host.al</a> dhe ua rekomandojmë të gjithë klientëve tanë.</p>
<p>Megjithatë ndodh që ka raste që në seksionin e programimit kemi nevojë të punojmë me databaza në servera jo vetëm të kompanisë sonë, por dhe të hostuesve të tjerë. Para 2 ditësh mora një email nga një koleg i punës për backup të një DB MySQL në një server të tillë për të cilin nuk kishim as të dhëna shelli e as të dhëna për ndonjë phpMyAdmin. Në këtë rast nuk mund as të instalohej phpMyAdmin kështuqë databaza duhej bërë backup në një mënyrë tjetër.</p>
<p>Normalisht për të bërë backup një Databazë me anë të phpmydmin shkohet tek menuja Export (ose sipas gjuhës) dhe procedohet më tej.</p>
<div id="attachment_174" class="wp-caption alignnone" style="width: 310px"><a href="http://armandbrahaj.blog.al/wp-content/uploads/2009/04/phpmyadmin_export.jpg"><img class="size-medium wp-image-174" title="phpmyadmin_export" src="http://armandbrahaj.blog.al/wp-content/uploads/2009/04/phpmyadmin_export-300x230.jpg" alt="Export table in PhpMyAdmin" width="300" height="230" /></a><p class="wp-caption-text">Export table in PhpMyAdmin</p></div>
<p>Mënyra më e thjeshtë dhe praktike për mendimin tim është përdorimi i shell. Nëpërmjet shell me komandën mysqldump mund të transferohet lehtësisht e gjithë databaza në një file .sql. Shembull:</p>
<blockquote><p>mysqldump -u <em>emerperdoruesi </em>-p<em>fjalekalimi emerDB</em> &gt; db.sql</p></blockquote>
<p>Në rastin kur nuk ka shell, por funksioni exec i PHP është aktiv mund të krijohet një script i thjeshtë php që të thërrasë këtë komandë dhe ta shkruaj në një skedar. Duhet që më parë skedari (psh db.sql) të jetë krijuar dhe të jetë bërë i shkruajtshëm si 666 (rw-rw-rw-).</p>
<p>Në këtë rast përmbajtja e skedarit (psh: <em>mysqldump.php</em>) mund të jetë:</p>
<blockquote><p>&lt;?php<br />
exec(&#8216;mysqldump -u <em>emerperdoruesi </em>-p<em>fjalekalimi emerDB</em> &gt; db.sql&#8217;);</p></blockquote>
<p>Pas thërritjes nga browseri, në të njëjtën direktori, skedari db.sql do të përmbajë të gjithë përmbajtjen e DB në sintaksë SQL Ansi.</p>
<p>Shpeshherë funksionet e ngjashme me exec (system, shell e të ngjashëm) ndalohen për ekzekutim nga PHP (Psh ne i bllokojmë këto funksione për efekt siguria tek <a title="Host" title='Original Link: http://www.host.al'  href="http://armandbrahaj.blog.al/?bdu6xmND" target="_self">Host.al</a>). Në këtë rast duhet të shkruhet një funksion që të gjenerojë një tekst të gjatë me komandat ANSI SQL që përdoren per DB Dump.</p>
<p>Një shembull për një file të tillë jepet më poshtë:</p>
<blockquote><p>&lt;?php</p>
<p>//Lidhja me DB</p>
<p>$db=&#8217;DBNAME&#8217;;<br />
$link = mysql_connect(&#8216;localhost&#8217;, &#8216;EMERPERDORUESI&#8217;, &#8216;FJALEKALIM&#8217;);<br />
if (!$link) {<br />
die(&#8216;Could not connect: &#8216; . mysql_error());<br />
}<br />
$db_selected = mysql_select_db($db, $link);<br />
if (!$db_selected) {<br />
die (&#8216;Can\&#8217;t use dbname : &#8216; . mysql_error());<br />
}</p>
<p>//Thërritja e funksionit që shfaq kodin,<br />
//Deklarimi i funksionit është më poshtë</p>
<p>echo &#8216;&lt;pre&gt;&#8217;.mysql_dump($db).&#8217;&lt;/pre&gt;&#8217;;</p>
<p>//Funksioni: Credits: http://snipplr.com/view/173/mysql-dump/<br />
function mysql_dump($database) {<br />
$query = &#8221;;<br />
$tables = @mysql_list_tables($database);<br />
while ($row = @mysql_fetch_row($tables)) { $table_list[] = $row[0]; }</p>
<p>for ($i = 0; $i &lt; @count($table_list); $i++) {</p>
<p>$results = mysql_query(&#8216;DESCRIBE &#8216; . $database . &#8216;.&#8217; . $table_list[$i]);<br />
$query .= &#8216;DROP TABLE IF EXISTS `&#8217; . $database . &#8216;.&#8217; . $table_list[$i] . &#8216;`;&#8217; .&#8221;\n\r&#8221;;<br />
$query .= &#8220;\n\r&#8221; . &#8216;CREATE TABLE `&#8217; . $database . &#8216;.&#8217; . $table_list[$i] . &#8216;` (&#8216; .&#8221;\n\r&#8221;;<br />
$tmp = &#8221;;<br />
while ($row = @mysql_fetch_assoc($results)) {<br />
$query .= &#8216;`&#8217; . $row['Field'] . &#8216;` &#8216; . $row['Type'];<br />
if ($row['Null'] != &#8216;YES&#8217;) { $query .= &#8216; NOT NULL&#8217;; }<br />
if ($row['Default'] != &#8221;) { $query .= &#8216; DEFAULT \&#8221; . $row['Default'] . &#8216;\&#8221;; }<br />
if ($row['Extra']) { $query .= &#8216; &#8216; . strtoupper($row['Extra']); }<br />
if ($row['Key'] == &#8216;PRI&#8217;) { $tmp = &#8216;primary key(&#8216; . $row['Field'] . &#8216;)&#8217;; }<br />
$query .= &#8216;,&#8217;. &#8220;\n\r&#8221;;<br />
}<br />
$query .= $tmp . &#8220;\n\r&#8221; . &#8216;);&#8217; . str_repeat(&#8220;\n\r&#8221;, 2);<br />
$results = mysql_query(&#8216;SELECT * FROM &#8216; . $database . &#8216;.&#8217; . $table_list[$i]);<br />
while ($row = @mysql_fetch_assoc($results)) {<br />
$query .= &#8216;INSERT INTO `&#8217; . $database . &#8216;.&#8217; . $table_list[$i] .&#8217;` (&#8216;;<br />
$data = Array();<br />
while (list($key, $value) = @each($row)) { $data['keys'][] = $key; $data['values'][] = addslashes($value); }<br />
$query .= join($data['keys'], &#8216;, &#8216;) . &#8216;)&#8217; . &#8220;\n\r&#8221; . &#8216;VALUES (\&#8221; . join($data['values'], &#8216;\&#8217;, \&#8221;) . &#8216;\&#8217;);&#8217; . &#8220;\n\r&#8221;;<br />
}<br />
$query .= str_repeat(&#8220;\n\r&#8221;, 2);<br />
}<br />
return $query;<br />
}</p></blockquote>
<blockquote><p>mysql_close($link);<br />
?&gt;</p></blockquote>
<h3>Artikuj të tjerë</h3>
<ul class="related_post"></ul>
]]></content:encoded>
			<wfw:commentRss>http://armandbrahaj.blog.al/2009/04/13/backup-database-pa-pasur-nevoje-per-phpmyadmin-apo-shell/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>
