<?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>MySQL &#8211; lifeLinux: Linux Tips, Hacks, Tutorials, Ebooks</title>
	<atom:link href="http://lifelinux.com/tag/mysql/feed/" rel="self" type="application/rss+xml" />
	<link>http://lifelinux.com</link>
	<description>All About Linux !</description>
	<lastBuildDate>Thu, 20 Nov 2014 03:45:39 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=5.5.3</generator>
	<item>
		<title>How To Restore Default Permissions Of All Files Under / (ROOT)</title>
		<link>http://lifelinux.com/how-to-restore-default-permissions-of-all-files-under-root/</link>
					<comments>http://lifelinux.com/how-to-restore-default-permissions-of-all-files-under-root/#respond</comments>
		
		<dc:creator><![CDATA[admin]]></dc:creator>
		<pubDate>Thu, 20 Nov 2014 03:45:39 +0000</pubDate>
				<category><![CDATA[NoSQL]]></category>
		<category><![CDATA[Sys Admin]]></category>
		<category><![CDATA[CentOS]]></category>
		<category><![CDATA[chmod]]></category>
		<category><![CDATA[chown]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[single user mode]]></category>
		<guid isPermaLink="false">http://www.lifelinux.com/?p=1951</guid>

					<description><![CDATA[<p>Have you ever made a mistake and changed permissions of the folder and all it’s subfolders? And how to change back permissions of files/folders to default state ? Yesterday , I accidentally changed / (ROOT) permission to 777 with following command # chmod 777 -R / After that, All files and folders on my server [&#8230;]</p>
<p>The post <a rel="nofollow" href="http://lifelinux.com/how-to-restore-default-permissions-of-all-files-under-root/">How To Restore Default Permissions Of All Files Under / (ROOT)</a> appeared first on <a rel="nofollow" href="http://lifelinux.com">lifeLinux: Linux Tips, Hacks, Tutorials, Ebooks</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p></p><p>Have you ever made a mistake and changed permissions of the folder and all it’s subfolders? And how to change back permissions of files/folders to default state ?<br />
<span id="more-1951"></span></p>
<p>Yesterday , I accidentally changed / (ROOT) permission to 777 with following command</p>
<pre>
# chmod 777 -R /
</pre>
<p>After that, All files and folders on my server changed to 777 permissions. And I try to reboot my server, I can&#8217;t login into my server. It&#8217;s shown error: </p>
<pre>
Failed to start SSH server : Starting sshd:WARNING: UNPROTECTED PRIVATE KEY FILE! Permissions 0775 for '/etc/ssh/ssh_host_key' are too open. It is recommended that your private key files are NOT accessible by others. This private key will be ignored. bad permissions: ignore key: /etc/ssh/ssh_host_key Could not load host key: /etc/ssh/ssh_host_key
...
</pre>
<h2>How do I fix it ? </h2>
<p>If you can <a href="http://www.lifelinux.com/how-to-boot-into-single-user-mode-on-centos/">boot your system into Single User Mode</a>, then type 2 commands</p>
<pre>
# for p in $(rpm -qa); do rpm --setperms $p; done
# for p in $(rpm -qa); do rpm --setugids $p; done
</pre>
<p>Above command combination will reset all the permissions to the default permissions under CentOS / RHEL / Fedora Linux.</p>
<p>If you can&#8217;t boot into Single User Mode, Let boot from CentOS installation CD into <a href="https://www.centos.org/docs/5/html/Installation_Guide-en-US/s1-rescuemode-boot.html">Recuse Mode</a>, make sure that your system mounted into /mnt/sysimage, And type the following command</p>
<pre>
# chmod 7777 -R /mnt/sysimage/
</pre>
<p>Note: Permission is 7777 not 777<br />
To change all files and folder to &#8220;7777&#8221; permission. And reboot your system. After that, You can boot into Single User Mode and type above commands.</p>
<h2>Reset default permissions of all files and folders under /home/ </h2>
<p>Type the following commands</p>
<pre>
# cd /home/
# for p in $(ll); do chown $p.$p -R /home/$p; done
# find . -type d -print0 | xargs -0 chmod 755
# find . -type f -print0 | xargs -0 chmod 644
# chmod 700 *
</pre>
<h2>Reset default permissions of all files and folders of MySQL (/var/lib/mysql)</h2>
<p>Type the following commands</p>
<pre>
# chown mysql.mysql -R /var/lib/mysql
# cd /var/lib/mysql
# find . -type d -print0 | xargs -0 chmod 700
# find . -type f -print0 | xargs -0 chmod 660
# chmod 777 *.sock
</pre>
<p>Finally, restart MySQL with following command</p>
<pre>
# /etc/init.d/mysqld restart
</pre>
<g:plusone href="http://lifelinux.com/how-to-restore-default-permissions-of-all-files-under-root/" size="standard"  annotation="none"   ></g:plusone><p>The post <a rel="nofollow" href="http://lifelinux.com/how-to-restore-default-permissions-of-all-files-under-root/">How To Restore Default Permissions Of All Files Under / (ROOT)</a> appeared first on <a rel="nofollow" href="http://lifelinux.com">lifeLinux: Linux Tips, Hacks, Tutorials, Ebooks</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>http://lifelinux.com/how-to-restore-default-permissions-of-all-files-under-root/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>How Do I Fix &#8220;Host is blocked because of many connection error&#8221; In MySQL</title>
		<link>http://lifelinux.com/how-do-i-fix-host-is-blocked-because-of-many-connection-error-in-mysql/</link>
					<comments>http://lifelinux.com/how-do-i-fix-host-is-blocked-because-of-many-connection-error-in-mysql/#respond</comments>
		
		<dc:creator><![CDATA[lifeLinux]]></dc:creator>
		<pubDate>Sat, 23 Feb 2013 02:26:32 +0000</pubDate>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[Sys Admin]]></category>
		<category><![CDATA[Linux]]></category>
		<guid isPermaLink="false">http://www.lifelinux.com/?p=1566</guid>

					<description><![CDATA[<p>Today, I got following MySQL error in a PHP application: Host &#8216;host_name&#8217; is blocked because of many connection errors; unblock with &#8216;mysqladmin flush-hosts&#8217;. It means that mysqld has received many connection requests from the given host. Default max_connect_errors value is 10, that is remote host will be blocked if there is more than 10 connection [&#8230;]</p>
<p>The post <a rel="nofollow" href="http://lifelinux.com/how-do-i-fix-host-is-blocked-because-of-many-connection-error-in-mysql/">How Do I Fix &#8220;Host is blocked because of many connection error&#8221; In MySQL</a> appeared first on <a rel="nofollow" href="http://lifelinux.com">lifeLinux: Linux Tips, Hacks, Tutorials, Ebooks</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p></p><p>Today, I got following MySQL error in a PHP application: Host &#8216;host_name&#8217; is blocked because of many connection errors; unblock with &#8216;mysqladmin flush-hosts&#8217;. It means that mysqld has received many connection requests from the given host. Default max_connect_errors value is 10, that is remote host will be blocked if there is more than 10 connection errors.<br />
<span id="more-1566"></span><br />
To fix, type the following command</p>
<pre>
# mysqladmin flush-hosts
</pre>
<p>To avoid this happening again, edit my.cnf</p>
<pre>
# vi /etc/my.cnf
</pre>
<p>Add the following line</p>
<pre>
max_connect_errors=10000
</pre>
<p>The value of the max_connect_errors system variable determines how many successive interrupted connection requests are permitted. Restart MySQL to reload configuration file</p>
<pre>
# service mysqld restart
</pre>
<p>Or, the value &#8216;max_connect_errors&#8217; can also be set at runtime, type the following commands</p>
<pre>
# mysql -uroot -p
# mysql> SET GLOBAL max_connect_errors=10000;
</pre>
<g:plusone href="http://lifelinux.com/how-do-i-fix-host-is-blocked-because-of-many-connection-error-in-mysql/" size="standard"  annotation="none"   ></g:plusone><p>The post <a rel="nofollow" href="http://lifelinux.com/how-do-i-fix-host-is-blocked-because-of-many-connection-error-in-mysql/">How Do I Fix &#8220;Host is blocked because of many connection error&#8221; In MySQL</a> appeared first on <a rel="nofollow" href="http://lifelinux.com">lifeLinux: Linux Tips, Hacks, Tutorials, Ebooks</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>http://lifelinux.com/how-do-i-fix-host-is-blocked-because-of-many-connection-error-in-mysql/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Auto Backup Server Files &#038; MySQL To FTP Server</title>
		<link>http://lifelinux.com/auto-backup-server-files-mysql-to-ftp-server/</link>
					<comments>http://lifelinux.com/auto-backup-server-files-mysql-to-ftp-server/#comments</comments>
		
		<dc:creator><![CDATA[lifeLinux]]></dc:creator>
		<pubDate>Tue, 23 Aug 2011 13:12:00 +0000</pubDate>
				<category><![CDATA[Bash Shell]]></category>
		<category><![CDATA[Sys Admin]]></category>
		<category><![CDATA[backup data]]></category>
		<category><![CDATA[backup mysql]]></category>
		<category><![CDATA[backup script]]></category>
		<category><![CDATA[backup service]]></category>
		<category><![CDATA[centralized storage]]></category>
		<category><![CDATA[ftp backup]]></category>
		<category><![CDATA[ftp servers]]></category>
		<category><![CDATA[gnu tar]]></category>
		<category><![CDATA[incremental backup]]></category>
		<category><![CDATA[incremental backups]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[mysql databases]]></category>
		<category><![CDATA[mysql server]]></category>
		<category><![CDATA[mysqldump]]></category>
		<category><![CDATA[nas backup]]></category>
		<category><![CDATA[script generator]]></category>
		<category><![CDATA[shell script]]></category>
		<category><![CDATA[storage array]]></category>
		<category><![CDATA[tape backups]]></category>
		<category><![CDATA[tar command]]></category>
		<category><![CDATA[tar gz]]></category>
		<guid isPermaLink="false">http://www.lifelinux.com/?p=1000</guid>

					<description><![CDATA[<p>This is a simple script take to daily backup server files and MySQL databases to FTP server. Make sure you have lftp client installed. Type the following command if you are using Centos/Fedora/RedHat # yum install lftp If you are using Ubuntu/Debian # sudo apt-get install install lftp Create the folder /backup, enter # mkdir [&#8230;]</p>
<p>The post <a rel="nofollow" href="http://lifelinux.com/auto-backup-server-files-mysql-to-ftp-server/">Auto Backup Server Files &#038; MySQL To FTP Server</a> appeared first on <a rel="nofollow" href="http://lifelinux.com">lifeLinux: Linux Tips, Hacks, Tutorials, Ebooks</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p></p><p>This is a simple script take to daily backup server files and MySQL databases to FTP server. Make sure you have lftp client installed. Type the following command if you are using Centos/Fedora/RedHat</p>
<pre>
# yum install lftp
</pre>
<p><span id="more-1000"></span><br />
If you are using Ubuntu/Debian</p>
<pre>
# sudo apt-get install install lftp
</pre>
<p>Create the folder /backup, enter</p>
<pre>
# mkdir /backup
# chmod 0600 /backup
</pre>
<p>Create backup.sh file, enter</p>
<pre>
# vi /backup/backup.sh
</pre>
<p>Add the following content to backup.sh</p>
<pre>
#!/bin/bash
# Daily backup script
# Backup Server Files & MySQL
# Support backup multiple directories and multiple databases
# Copyright (c) 2010-2011 lifeLinux <http://www.lifelinux.com/>
# This script is licensed under GNU GPL version 2.0 or above

### Webserver directory
WD="/var/www/domain"

### MySQL Server Login Info ###
MUSER="root"
MPASS="MYSQL_ROOT_PASSWORD"
MHOST="localhost"
DBS="DATABASE_NAME_1 DATABASE_NAME_2"
MYSQL="$(which mysql)"
MYSQLDUMP="$(which mysqldump)"
GZIP="$(which gzip)"
TAR="$(which tar)"

### Backup directory
BAK="/backup"

### FTP SERVER Login info ###
FTPU="FTP USER"
FTPP="FTP PASSWORD"
FTPS="FTP SERVER IP"
DAILY=$(date +"%u")

[ ! -d $BAK/$DAILY ] && mkdir -p $BAK/$DAILY || /bin/rm -f $BAK/$DAILY/*

for db in $DBS
do
	FILE=$BAK/$DAILY/mysql-$db.gz
	$MYSQLDUMP -u $MUSER -h $MHOST -p$MPASS $db | $GZIP -9 > $FILE
done

WDS=`dir $WD`

for w in $WDS
do
	FILE=$BAK/$DAILY/source-$w.gz
	$TAR -zcvf $FILE $WD/$w/* 
done

lftp -u $FTPU,$FTPP -e "mkdir $DAILY;cd $DAILY; mput $BAK/$DAILY/*; quit" $FTPS
</pre>
<p>Set cron job</p>
<pre>
# crontab -e
</pre>
<p>If you want to auto backup at 3:00AM, add the following line to crontab</p>
<pre>
00 03 * * * /backup/backup.sh > /dev/null 2>&1
</pre>
<g:plusone href="http://lifelinux.com/auto-backup-server-files-mysql-to-ftp-server/" size="standard"  annotation="none"   ></g:plusone><p>The post <a rel="nofollow" href="http://lifelinux.com/auto-backup-server-files-mysql-to-ftp-server/">Auto Backup Server Files &#038; MySQL To FTP Server</a> appeared first on <a rel="nofollow" href="http://lifelinux.com">lifeLinux: Linux Tips, Hacks, Tutorials, Ebooks</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>http://lifelinux.com/auto-backup-server-files-mysql-to-ftp-server/feed/</wfw:commentRss>
			<slash:comments>2</slash:comments>
		
		
			</item>
		<item>
		<title>How to backup and restore large mysql database</title>
		<link>http://lifelinux.com/how-to-backup-and-restore-large-mysql-database/</link>
					<comments>http://lifelinux.com/how-to-backup-and-restore-large-mysql-database/#respond</comments>
		
		<dc:creator><![CDATA[lifeLinux]]></dc:creator>
		<pubDate>Sun, 01 May 2011 07:00:13 +0000</pubDate>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[Sys Admin]]></category>
		<category><![CDATA[backup data]]></category>
		<category><![CDATA[backup mysql]]></category>
		<category><![CDATA[backup script]]></category>
		<category><![CDATA[backup service]]></category>
		<category><![CDATA[centralized storage]]></category>
		<category><![CDATA[ftp backup]]></category>
		<category><![CDATA[ftp servers]]></category>
		<category><![CDATA[gnu tar]]></category>
		<category><![CDATA[incremental backup]]></category>
		<category><![CDATA[incremental backups]]></category>
		<category><![CDATA[mysql databases]]></category>
		<category><![CDATA[mysql server]]></category>
		<category><![CDATA[mysqldump]]></category>
		<category><![CDATA[nas backup]]></category>
		<category><![CDATA[script generator]]></category>
		<category><![CDATA[shell script]]></category>
		<category><![CDATA[storage array]]></category>
		<category><![CDATA[tape backups]]></category>
		<category><![CDATA[tar command]]></category>
		<category><![CDATA[tar gz]]></category>
		<guid isPermaLink="false">http://www.lifelinux.com/?p=317</guid>

					<description><![CDATA[<p>If you have very large mysql database then it is very hard to backup and restore using the conventional phpmyadmin or any other programs. In this Tutorial I will explain you how to backup and restore a larger database. This tutorial can be used while moving your database from one server to another. First you [&#8230;]</p>
<p>The post <a rel="nofollow" href="http://lifelinux.com/how-to-backup-and-restore-large-mysql-database/">How to backup and restore large mysql database</a> appeared first on <a rel="nofollow" href="http://lifelinux.com">lifeLinux: Linux Tips, Hacks, Tutorials, Ebooks</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p></p><p>If you have very large <strong>mysql database</strong> then it is very hard to backup and restore using the conventional phpmyadmin or any other programs.<br />
In this Tutorial I will explain you how to backup and restore a larger database. This tutorial can be used while moving your database from one server to another.<span id="more-317"></span><br />
First you need to have shell (ssh) access to your server. Then follow the steps:</p>
<h3>To Backup Mysql Database</h3>
<pre>
root@lifelinux:~# mysqldump  -u [username] -p[password] [dbname] > [backup.sql]
</pre>
<p>[username] is your database user name<br />
[password] is the password for your database (Note: there is no space between -p and the password)<br />
[dbname] is The name of your database<br />
[backup.sql] is The file name for your database backup</p>
<h3>Backup Mysql Database with compress</h3>
<p>If your mysql database is very big, you might want to compress the output of mysql dump. Just use the mysql backup command below and pipe the output to gzip, then you will get the output as gzip file.</p>
<pre>
root@lifelinux:~# mysqldump -u [username] -p[password] [dbname] | gzip -9 > [backup.sql.gz]
</pre>
<h3>Restore Mysql Database</h3>
<p>To restore the database you need to create the database in target machine then use this command</p>
<pre>
root@lifelinux:~# mysql -u [username] -p[password] [dbname] < [backup.sql]
</pre>
<h3>Restore Compressed Mysql Database</h3>
<pre>
root@lifelinux:~# gunzip < [backup.sql.gz] | mysql -u [username] -p[password] [dbname]
</pre>
<g:plusone href="http://lifelinux.com/how-to-backup-and-restore-large-mysql-database/" size="standard"  annotation="none"   ></g:plusone><p>The post <a rel="nofollow" href="http://lifelinux.com/how-to-backup-and-restore-large-mysql-database/">How to backup and restore large mysql database</a> appeared first on <a rel="nofollow" href="http://lifelinux.com">lifeLinux: Linux Tips, Hacks, Tutorials, Ebooks</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>http://lifelinux.com/how-to-backup-and-restore-large-mysql-database/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Reset The Root Password Of MySQL Server</title>
		<link>http://lifelinux.com/reset-the-root-password-of-mysql-server/</link>
					<comments>http://lifelinux.com/reset-the-root-password-of-mysql-server/#comments</comments>
		
		<dc:creator><![CDATA[lifeLinux]]></dc:creator>
		<pubDate>Wed, 24 Nov 2010 04:01:31 +0000</pubDate>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[mysql command]]></category>
		<category><![CDATA[mysql password]]></category>
		<category><![CDATA[Recover MySQL password]]></category>
		<category><![CDATA[Recover Password MySQL]]></category>
		<category><![CDATA[restart mysql]]></category>
		<category><![CDATA[start mysql]]></category>
		<category><![CDATA[stop mysql]]></category>
		<guid isPermaLink="false">http://www.lifelinux.com/?p=123</guid>

					<description><![CDATA[<p>By default, MySQL server will be installed with root account and password is blank. If you have set the password for root and forget it, then you will need to reset the root password for MySQL. This topic has detail steps on how to reset password for root on MySQL Server. Step 1: Stop MySQL [&#8230;]</p>
<p>The post <a rel="nofollow" href="http://lifelinux.com/reset-the-root-password-of-mysql-server/">Reset The Root Password Of MySQL Server</a> appeared first on <a rel="nofollow" href="http://lifelinux.com">lifeLinux: Linux Tips, Hacks, Tutorials, Ebooks</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p></p><p>By default, MySQL server will be installed with root account and password is blank. If you have set the password for root and forget it, then you will need to reset the root password for MySQL.<span id="more-123"></span></p>
<p>This topic has detail steps on how to reset password for root on MySQL Server.</p>
<h2>Step 1: Stop MySQL service</h2>
<pre>
service mysqld stop
</pre>
<h2>Step 2: Start MySQL with mysql-safe command</h2>
<pre>
mysql-safe --skip-grant-tables &amp;
</pre>
<p>&#8211;skip-grant-tables is a option to enable anyone connect MySQL Server without password and with all privileges.</p>
<h2>Step 3: Connect MySQL with root account and blank password</h2>
<pre>
mysql -u root -p
</pre>
<h2>Step 4: Change password for root account</h2>
<pre>
mysql&gt;   UPDATE mysql.user SET password = PASSWORD('NEW_PASSWORD') WHERE User = 'root';
mysql&gt;   FLUSH PRIVILEGES;
mysql&gt;   exit;
</pre>
<h2>Step 5: Restart MySQL</h2>
<pre>
service mysqld restart
</pre>
<g:plusone href="http://lifelinux.com/reset-the-root-password-of-mysql-server/" size="standard"  annotation="none"   ></g:plusone><p>The post <a rel="nofollow" href="http://lifelinux.com/reset-the-root-password-of-mysql-server/">Reset The Root Password Of MySQL Server</a> appeared first on <a rel="nofollow" href="http://lifelinux.com">lifeLinux: Linux Tips, Hacks, Tutorials, Ebooks</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>http://lifelinux.com/reset-the-root-password-of-mysql-server/feed/</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
			</item>
		<item>
		<title>How To Make Multiple Updates Using A Single Query In MySQL</title>
		<link>http://lifelinux.com/how-to-make-multiple-updates-using-a-single-query-in-mysql/</link>
					<comments>http://lifelinux.com/how-to-make-multiple-updates-using-a-single-query-in-mysql/#respond</comments>
		
		<dc:creator><![CDATA[admin]]></dc:creator>
		<pubDate>Tue, 23 Nov 2010 07:52:16 +0000</pubDate>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[multiple updates in mysql]]></category>
		<category><![CDATA[multiple updates in mysql with single query]]></category>
		<category><![CDATA[multiple updates using a single query]]></category>
		<category><![CDATA[update with single query]]></category>
		<guid isPermaLink="false">http://www.lifelinux.com/?p=21</guid>

					<description><![CDATA[<p>Q. How to make multiple updates using a single query in mysql ? A. Using CASE &#38; WHEN commands to solve it. As you might know it’s quite easy to make multiple INSERTs in a single query, like this: INSERT INTO table_name (field1, field2) VALUES ('value1', 'value2'), ('value3', 'value4'); However, for some strange reason you [&#8230;]</p>
<p>The post <a rel="nofollow" href="http://lifelinux.com/how-to-make-multiple-updates-using-a-single-query-in-mysql/">How To Make Multiple Updates Using A Single Query In MySQL</a> appeared first on <a rel="nofollow" href="http://lifelinux.com">lifeLinux: Linux Tips, Hacks, Tutorials, Ebooks</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p></p><p><span style="color: #ff0000;">Q</span>. How to make multiple updates using a single query in mysql ?</p>
<p><span style="color: #0000ff;">A</span>. Using CASE &amp; WHEN commands to solve it.<span id="more-21"></span></p>
<p>As you might know it’s quite easy to make multiple INSERTs in a single query, like this:</p>
<pre>INSERT INTO table_name (field1, field2) VALUES
('value1', 'value2'),
('value3', 'value4');
</pre>
<p><!--more-->However, for some strange reason you <strong>can’t</strong> do multiple changes to a table in a single Update query like this:</p>
<pre>UPDATE table_name
SET (field2 = 'valuex' WHERE field1 = 'value1'),
(field2='valuey' WHERE field1 = 'value3');
</pre>
<p>But, you can do a very interesting trick. You can combine an UPDATE with a CASE like this:</p>
<pre>UPDATE table_name SET field2 = CASE
WHEN field1 = 'value1' THEN 'valuex';
WHEN field1 = 'value3' THEN 'valuey';
ELSE field2
END;
</pre>
<p>The ELSE field2 is very important, otherwise you will overwrite the rest of the table with NULL.</p>
<g:plusone href="http://lifelinux.com/how-to-make-multiple-updates-using-a-single-query-in-mysql/" size="standard"  annotation="none"   ></g:plusone><p>The post <a rel="nofollow" href="http://lifelinux.com/how-to-make-multiple-updates-using-a-single-query-in-mysql/">How To Make Multiple Updates Using A Single Query In MySQL</a> appeared first on <a rel="nofollow" href="http://lifelinux.com">lifeLinux: Linux Tips, Hacks, Tutorials, Ebooks</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>http://lifelinux.com/how-to-make-multiple-updates-using-a-single-query-in-mysql/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
