<?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>Jim&#039;s Code Bucket &#187; MySQL</title>
	<atom:link href="http://jamesborder.com/category/mysql/feed/" rel="self" type="application/rss+xml" />
	<link>http://jamesborder.com</link>
	<description>misc code snippets</description>
	<lastBuildDate>Mon, 16 Aug 2010 15:29:41 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>MySQL Dump/Restore</title>
		<link>http://jamesborder.com/2010/07/mysql-dumprestore/</link>
		<comments>http://jamesborder.com/2010/07/mysql-dumprestore/#comments</comments>
		<pubDate>Mon, 19 Jul 2010 14:55:37 +0000</pubDate>
		<dc:creator>me</dc:creator>
				<category><![CDATA[MySQL]]></category>

		<guid isPermaLink="false">http://jamesborder.com/?p=583</guid>
		<description><![CDATA[MySQL Dump/Restore
Dump ALL MySQL Databases
mysqldump &#8211;user=user_name &#8211;password=password -A > /PATH/TO/DUMPFILE.SQL
Dump Individual or Multiple MySQL Databases
mysqldump &#8211;user=user_name &#8211;password=password &#8211;databases DB_NAME1 DB_NAME2 DB_NAME3 > /PATH/TO/DUMPFILE.SQL
Dump only certain tables from a MySQL Database
mysqldump &#8211;user=user_name &#8211;password=password &#8211;databases DB_NAME &#8211;tables TABLE_NAME > /PATH/TO/DUMPFILE.SQL
To make dumps compatible with older versions add the following switch:
&#8211;compatible=mysqlXXX 
Use the following to reload the contents [...]]]></description>
			<content:encoded><![CDATA[<p>MySQL Dump/Restore</p>
<p>Dump ALL MySQL Databases<br />
mysqldump &#8211;user=user_name &#8211;password=password -A > /PATH/TO/DUMPFILE.SQL</p>
<p>Dump Individual or Multiple MySQL Databases<br />
mysqldump &#8211;user=user_name &#8211;password=password &#8211;databases DB_NAME1 DB_NAME2 DB_NAME3 > /PATH/TO/DUMPFILE.SQL</p>
<p>Dump only certain tables from a MySQL Database<br />
mysqldump &#8211;user=user_name &#8211;password=password &#8211;databases DB_NAME &#8211;tables TABLE_NAME > /PATH/TO/DUMPFILE.SQL</p>
<p>To make dumps compatible with older versions add the following switch:<br />
&#8211;compatible=mysqlXXX </p>
<p>Use the following to reload the contents of a database:</p>
<p>mysql &#8211;verbose &#8211;user=user_name &#8211;password=password DB_NAME < /PATH/TO/DUMPFILE.SQL</p>
]]></content:encoded>
			<wfw:commentRss>http://jamesborder.com/2010/07/mysql-dumprestore/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Enable remote connections to mysql</title>
		<link>http://jamesborder.com/2010/05/enable-remote-connections-to-mysql/</link>
		<comments>http://jamesborder.com/2010/05/enable-remote-connections-to-mysql/#comments</comments>
		<pubDate>Thu, 20 May 2010 03:27:53 +0000</pubDate>
		<dc:creator>me</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[MySQL]]></category>

		<guid isPermaLink="false">http://jamesborder.com/?p=534</guid>
		<description><![CDATA[THIS IS FOR MYSQL ONLY! NOT YOUR FIREWALL! NOT YOUR IPTABLES! NOTHIN BUT MYSQL!
Find your my.cnf
Debian/Ubuntu -> /etc/mysql/my.cnf
Red Hat Linux/Fedora/Centos -> /etc/my.cnf
sudo vi /etc/mysql/my.cnf
Make sure bind-address set to your server IP address, (the ip address of that machine, it will probably say 127.0.0.1)
bind-address = 192.158.5.1
Also make sure line skip-networking is removed or commented out
# skip-external-networking
sudo [...]]]></description>
			<content:encoded><![CDATA[<p><code>THIS IS FOR MYSQL ONLY! NOT YOUR FIREWALL! NOT YOUR IPTABLES! NOTHIN BUT MYSQL!</p>
<p>Find your my.cnf<br />
Debian/Ubuntu -> /etc/mysql/my.cnf<br />
Red Hat Linux/Fedora/Centos -> /etc/my.cnf</p>
<p>sudo vi /etc/mysql/my.cnf</p>
<p>Make sure bind-address set to your server IP address, (the ip address of that machine, it will probably say 127.0.0.1)</p>
<p>bind-address = 192.158.5.1<br />
Also make sure line skip-networking is removed or commented out<br />
# skip-external-networking</p>
<p>sudo /etc/init.d/mysql restart</p>
<p>Let us assume that you are always making connection from remote IP called 202.54.10.20 for database called webdb for user webadmin then you need to grant access to this IP address.<br />
At mysql> prompt type following command for existing database:</p>
<p>Code:<br />
update db set Host='202.54.10.20' where Db='webdb';<br />
update user set Host='202.54.10.20' where user='webadmin';</p>
<p><!--</p>
<p>Restart your mysql service to take change in effect:# /etc/init.d/mysql restart<br />
Step # 5 Grant access to remote IP address</p>
<p># mysql -u root -p mysqlGrant access to new database<br />
If you want to add new database called foo for user bar and remote IP 202.54.10.20 then you need to type following commands at mysql> prompt:mysql> CREATE DATABASE foo;<br />
mysql> GRANT ALL ON foo.* TO bar@’202.54.10.20′ IDENTIFIED BY ‘PASSWORD’;<br />
How Do I Grant access to existing database?</p>
<p>Let us assume that you are always making connection from remote IP called 202.54.10.20 for database called webdb for user webadmin, To grant access to this IP address type the following command At mysql> prompt for existing database:mysql> update db set Host=’202.54.10.20′ where Db=’webdb’;<br />
mysql> update user set Host=’202.54.10.20′ where user=’webadmin’;<br />
Step # 5: Logout of MySQL</p>
<p>Type exit command to logout mysql:mysql> exit<br />
Step # 6: Open port 3306</p>
<p>You need to open port 3306 using iptables or BSD pf firewall.<br />
A sample iptables rule to open Linux iptables firewall</p>
<p>/sbin/iptables -A INPUT -i eth0 -p tcp –destination-port 3306 -j ACCEPT</p>
<p>OR only allow remote connection from your web server located at 10.5.1.3:</p>
<p>/sbin/iptables -A INPUT -i eth0 -s 10.5.1.3 -p tcp –destination-port 3306 -j ACCEPT</p>
<p>OR only allow remote connection from your lan subnet 192.168.1.0/24:</p>
<p>/sbin/iptables -A INPUT -i eth0 -s 192.168.1.0/24 -p tcp –destination-port 3306 -j ACCEPT</p>
<p>A sample FreeBSD / OpenBSD pf rule ( /etc/pf.conf)</p>
<p>pass in on $ext_if proto tcp from any to any port 3306</p>
<p>OR allow only access from your web server located at 10.5.1.3:</p>
<p>pass in on $ext_if proto tcp from 10.5.1.3 to any port 3306  flags S/SA synproxy state</p>
<p>Step # 7: Test it</p>
<p>From remote system or your desktop type the command:<br />
$ mysql -u webadmin –h 65.55.55.2 –p<br />
Where,</p>
<p>* -u webadmin: webadmin is MySQL username<br />
* -h IP or hostname: 65.55.55.2 is MySQL server IP address or hostname (FQDN)<br />
* -p : Prompt for password</p>
<p>You can also use telnet to connect to port 3306 for testing purpose:$ telnet 65.55.55.2 3306</p>
<p>--><code></code></p>
]]></content:encoded>
			<wfw:commentRss>http://jamesborder.com/2010/05/enable-remote-connections-to-mysql/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>mysql_secure_installation</title>
		<link>http://jamesborder.com/2010/05/mysql_secure_installation/</link>
		<comments>http://jamesborder.com/2010/05/mysql_secure_installation/#comments</comments>
		<pubDate>Sat, 08 May 2010 02:31:49 +0000</pubDate>
		<dc:creator>me</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Mac]]></category>
		<category><![CDATA[MySQL]]></category>

		<guid isPermaLink="false">http://jamesborder.com/?p=520</guid>
		<description><![CDATA[if you install mysql run this command please&#8230; 
mysql_secure_installation
what does it do?
asks you set a password for root account
remove root accounts that are accessible from outside the local host.
remove anonymous-user accounts.
remove the test database, which by default can be accessed by anonymous users.
see&#8230; it&#8217;s important
here&#8217;s what happens
me@ubuntop:~$ mysql_secure_installation
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS [...]]]></description>
			<content:encoded><![CDATA[<p>if you install mysql run this command please&#8230; </p>
<p>mysql_secure_installation</p>
<p>what does it do?</p>
<p>asks you set a password for root account<br />
remove root accounts that are accessible from outside the local host.<br />
remove anonymous-user accounts.<br />
remove the test database, which by default can be accessed by anonymous users.</p>
<p>see&#8230; it&#8217;s important</p>
<p>here&#8217;s what happens</p>
<p>me@ubuntop:~$ mysql_secure_installation</p>
<p>NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL<br />
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!</p>
<p>In order to log into MySQL to secure it, we&#8217;ll need the current<br />
password for the root user.  If you&#8217;ve just installed MySQL, and<br />
you haven&#8217;t set the root password yet, the password will be blank,<br />
so you should just press enter here.</p>
<p>Enter current password for root (enter for none):<br />
OK, successfully used password, moving on&#8230;</p>
<p>Setting the root password ensures that nobody can log into the MySQL<br />
root user without the proper authorisation.</p>
<p>You already have a root password set, so you can safely answer &#8216;n&#8217;.</p>
<p>Change the root password? [Y/n] n<br />
 &#8230; skipping.</p>
<p>By default, a MySQL installation has an anonymous user, allowing anyone<br />
to log into MySQL without having to have a user account created for<br />
them.  This is intended only for testing, and to make the installation<br />
go a bit smoother.  You should remove them before moving into a<br />
production environment.</p>
<p>Remove anonymous users? [Y/n] Y<br />
 &#8230; Success!</p>
<p>Normally, root should only be allowed to connect from &#8216;localhost&#8217;.  This<br />
ensures that someone cannot guess at the root password from the network.</p>
<p>Disallow root login remotely? [Y/n] y<br />
 &#8230; Success!</p>
<p>By default, MySQL comes with a database named &#8216;test&#8217; that anyone can<br />
access.  This is also intended only for testing, and should be removed<br />
before moving into a production environment.</p>
<p>Remove test database and access to it? [Y/n] y<br />
 &#8211; Dropping test database&#8230;<br />
ERROR 1008 (HY000) at line 1: Can&#8217;t drop database &#8216;test&#8217;; database doesn&#8217;t exist<br />
 &#8230; Failed!  Not critical, keep moving&#8230;<br />
 &#8211; Removing privileges on test database&#8230;<br />
 &#8230; Success!</p>
<p>Reloading the privilege tables will ensure that all changes made so far<br />
will take effect immediately.</p>
<p>Reload privilege tables now? [Y/n] y<br />
 &#8230; Success!</p>
<p>Cleaning up&#8230;</p>
<p>All done!  If you&#8217;ve completed all of the above steps, your MySQL<br />
installation should now be secure.</p>
<p>Thanks for using MySQL!</p>
]]></content:encoded>
			<wfw:commentRss>http://jamesborder.com/2010/05/mysql_secure_installation/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Removing mysql from my mac</title>
		<link>http://jamesborder.com/2009/09/removing-mysql-from-my-mac/</link>
		<comments>http://jamesborder.com/2009/09/removing-mysql-from-my-mac/#comments</comments>
		<pubDate>Wed, 09 Sep 2009 21:30:55 +0000</pubDate>
		<dc:creator>me</dc:creator>
				<category><![CDATA[Mac]]></category>
		<category><![CDATA[MySQL]]></category>

		<guid isPermaLink="false">http://jamesborder.com/?p=328</guid>
		<description><![CDATA[Yes I admit I have mangled MySql on my macbook very badly and it had to go&#8230;. here is what it took to do it
sudo rm /usr/local/mysql
sudo rm -rf /usr/local/mysql*
sudo rm -rf /Library/StartupItems/MySQLCOM
sudo rm -rf /Library/PreferencePanes/My*
edit /etc/hostconfig and remove the line MYSQLCOM=-YES-
rm -rf ~/Library/PreferencePanes/My*
sudo rm -rf /Library/Receipts/mysql*
sudo rm -rf /Library/Receipts/MySQL*
]]></description>
			<content:encoded><![CDATA[<p>Yes I admit I have mangled MySql on my macbook very badly and it had to go&#8230;. here is what it took to do it</p>
<p>sudo rm /usr/local/mysql<br />
sudo rm -rf /usr/local/mysql*<br />
sudo rm -rf /Library/StartupItems/MySQLCOM<br />
sudo rm -rf /Library/PreferencePanes/My*<br />
edit /etc/hostconfig and remove the line MYSQLCOM=-YES-<br />
rm -rf ~/Library/PreferencePanes/My*<br />
sudo rm -rf /Library/Receipts/mysql*<br />
sudo rm -rf /Library/Receipts/MySQL*</p>
]]></content:encoded>
			<wfw:commentRss>http://jamesborder.com/2009/09/removing-mysql-from-my-mac/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Reset Mysql Root Password</title>
		<link>http://jamesborder.com/2009/08/reset-mysql-root-password/</link>
		<comments>http://jamesborder.com/2009/08/reset-mysql-root-password/#comments</comments>
		<pubDate>Mon, 03 Aug 2009 07:09:44 +0000</pubDate>
		<dc:creator>me</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[MySQL]]></category>

		<guid isPermaLink="false">http://jamesborder.com/?p=354</guid>
		<description><![CDATA[Stop Mysql:
/etc/init.d/mysqld stop
Create a script to run the reset query
vi /root/mysql.reset.sql
add the reset query:
UPDATE mysql.user SET Password=PASSWORD(&#8216;YOUR-NEW-MYSQL-PASSWORD&#8217;) WHERE User=&#8217;root&#8217;;
FLUSH PRIVILEGES;
execute the script:
# mysqld_safe &#8211;init-file=/root/mysql.reset.sql &#038;
Sample output:
nohup: ignoring input and redirecting stderr to stdout
Starting mysqld daemon with databases from /var/lib/mysql
mysqld_safe[20970]: started
# killall mysqld
# /etc/init.d/mysql start
]]></description>
			<content:encoded><![CDATA[<p>Stop Mysql:<br />
/etc/init.d/mysqld stop</p>
<p>Create a script to run the reset query<br />
vi /root/mysql.reset.sql</p>
<p>add the reset query:<br />
UPDATE mysql.user SET Password=PASSWORD(&#8216;YOUR-NEW-MYSQL-PASSWORD&#8217;) WHERE User=&#8217;root&#8217;;<br />
FLUSH PRIVILEGES;</p>
<p>execute the script:<br />
# mysqld_safe &#8211;init-file=/root/mysql.reset.sql &#038;</p>
<p>Sample output:<br />
nohup: ignoring input and redirecting stderr to stdout<br />
Starting mysqld daemon with databases from /var/lib/mysql<br />
mysqld_safe[20970]: started</p>
<p># killall mysqld<br />
# /etc/init.d/mysql start</p>
]]></content:encoded>
			<wfw:commentRss>http://jamesborder.com/2009/08/reset-mysql-root-password/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MySQL table &gt; column comments</title>
		<link>http://jamesborder.com/2009/06/mysql-table-column-comments/</link>
		<comments>http://jamesborder.com/2009/06/mysql-table-column-comments/#comments</comments>
		<pubDate>Thu, 18 Jun 2009 21:33:03 +0000</pubDate>
		<dc:creator>me</dc:creator>
				<category><![CDATA[MySQL]]></category>

		<guid isPermaLink="false">http://jamesborder.com/site/mysql_table_column_comments/#When:21:33:03Z</guid>
		<description><![CDATA[How to read &#38; update MySQL table column comments
So why would you wanna do that? Cuz you can store info in the comments that can be read out and feed automated CMS systems
SELECT COLUMN_COMMENT
FROM information_schema.COLUMNS
WHERE TABLE_SCHEMA = &#39;simpl_example&#39; AND TABLE_NAME = &#39;your_table_name&#39;;
]]></description>
			<content:encoded><![CDATA[<p>How to read &amp; update MySQL table column comments<br />
So why would you wanna do that? Cuz you can store info in the comments that can be read out and feed automated CMS systems</p>
<p>SELECT COLUMN_COMMENT<br />
FROM information_schema.COLUMNS<br />
WHERE TABLE_SCHEMA = &#39;simpl_example&#39; AND TABLE_NAME = &#39;your_table_name&#39;;</p>
]]></content:encoded>
			<wfw:commentRss>http://jamesborder.com/2009/06/mysql-table-column-comments/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MySQL User Restrictions</title>
		<link>http://jamesborder.com/2009/06/mysql-user-restrictions/</link>
		<comments>http://jamesborder.com/2009/06/mysql-user-restrictions/#comments</comments>
		<pubDate>Sat, 13 Jun 2009 03:13:50 +0000</pubDate>
		<dc:creator>me</dc:creator>
				<category><![CDATA[MySQL]]></category>

		<guid isPermaLink="false">http://jamesborder.com/site/mysql_user_restrictions/#When:03:13:50Z</guid>
		<description><![CDATA[When you need to restrict users to a specific database do this&#8230;.
log in as a/the admin user:
mysql &#45;u root &#45;h localhost &#45;p
(enter your password)
then run these commands:
CREATE Database databasename;
CREATE USER &#8216;username&#8217;@&#8217;%&#8217; IDENTIFIED BY &#8216;password&#8217;;
REVOKE ALL PRIVILEGES,GRANT OPTION from &#8216;username&#8217;@&#8217;%&#8217;;
GRANT ALL ON databasename.* TO &#8216;username&#8217;@&#8217;%&#8217;;
Line 1 creates a database named: databasename (mmmm&#8230; insert the database name [...]]]></description>
			<content:encoded><![CDATA[<p>When you need to restrict users to a specific database do this&#8230;.<br />
log in as a/the admin user:</p>
<p>mysql &#45;u root &#45;h localhost &#45;p</p>
<p>(enter your password)</p>
<p>then run these commands:</p>
<p>CREATE Database databasename;<br />
CREATE USER &#8216;username&#8217;@&#8217;%&#8217; IDENTIFIED BY &#8216;password&#8217;;<br />
REVOKE ALL PRIVILEGES,GRANT OPTION from &#8216;username&#8217;@&#8217;%&#8217;;<br />
GRANT ALL ON databasename.* TO &#8216;username&#8217;@&#8217;%&#8217;;</p>
<p>Line 1 creates a database named: databasename (mmmm&#8230; insert the database name you want here)<br />
Line 2 creates a user named username and gives them a password<br />
Line 3 Takes a way all username privileges<br />
Line 4 gives username all privileges on all the tables in databasename</p>
]]></content:encoded>
			<wfw:commentRss>http://jamesborder.com/2009/06/mysql-user-restrictions/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Generate Passwords with MyQL</title>
		<link>http://jamesborder.com/2009/04/generate-passwords-with-myql/</link>
		<comments>http://jamesborder.com/2009/04/generate-passwords-with-myql/#comments</comments>
		<pubDate>Sun, 26 Apr 2009 17:14:34 +0000</pubDate>
		<dc:creator>me</dc:creator>
				<category><![CDATA[MySQL]]></category>

		<guid isPermaLink="false">http://jamesborder.com/site/generate_passwords_with_myql/#When:17:14:34Z</guid>
		<description><![CDATA[Many applications store MD5&#45;crypted passwords in the database. If you want to quickly create a new MD5&#45;ed password, or you have forgotten your password, use the following query to get a new one:
SELECT MD5(”m0ntypy7hon”);
This query will return “4f249cbc2c10d41f866b64decd365e39″ which is the encrypted version of the string “ m0ntypy7hon”. 
There are other function that crypt stings [...]]]></description>
			<content:encoded><![CDATA[<p>Many applications store MD5&#45;crypted passwords in the database. If you want to quickly create a new MD5&#45;ed password, or you have forgotten your password, use the following query to get a new one:</p>
<p>SELECT MD5(”m0ntypy7hon”);</p>
<p>This query will return “4f249cbc2c10d41f866b64decd365e39″ which is the encrypted version of the string “ m0ntypy7hon”. </p>
<p>There are other function that crypt stings in MySQL using different algorithms, most notably PASSWORD() which is using MySQL”s own crypting algorithm.</p>
<p>SELECT PASSWORD( &#8220;m0ntypy7hon&#8221; ) ; </p>
<p>returns: &#8220;5216be9f6ead4434&#8221;</p>
]]></content:encoded>
			<wfw:commentRss>http://jamesborder.com/2009/04/generate-passwords-with-myql/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MySql Find/replace</title>
		<link>http://jamesborder.com/2009/04/mysql-findreplace/</link>
		<comments>http://jamesborder.com/2009/04/mysql-findreplace/#comments</comments>
		<pubDate>Sat, 25 Apr 2009 15:58:25 +0000</pubDate>
		<dc:creator>me</dc:creator>
				<category><![CDATA[MySQL]]></category>

		<guid isPermaLink="false">http://jamesborder.com/site/mysql_find_replace/#When:15:58:25Z</guid>
		<description><![CDATA[UPDATE yourtable SET targetfield = REPLACE(targetfield, &#8220;foo&#8221;,&#8220;bar&#8221;);
This statement will replace all occurrences of the string “foo” with the string “bar” in all records of the “ targetfield” column. Apart from the string “bar” the rest of the text contained in the field will be unchanged.
]]></description>
			<content:encoded><![CDATA[<p>UPDATE yourtable SET targetfield = REPLACE(targetfield, &#8220;foo&#8221;,&#8220;bar&#8221;);</p>
<p>This statement will replace all occurrences of the string “foo” with the string “bar” in all records of the “ targetfield” column. Apart from the string “bar” the rest of the text contained in the field will be unchanged.</p>
]]></content:encoded>
			<wfw:commentRss>http://jamesborder.com/2009/04/mysql-findreplace/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Mysql toggle a field value</title>
		<link>http://jamesborder.com/2009/04/mysql-toggle-a-field-value/</link>
		<comments>http://jamesborder.com/2009/04/mysql-toggle-a-field-value/#comments</comments>
		<pubDate>Sat, 04 Apr 2009 03:23:43 +0000</pubDate>
		<dc:creator>me</dc:creator>
				<category><![CDATA[MySQL]]></category>

		<guid isPermaLink="false">http://jamesborder.com/site/mysql_toggle_a_field_value/#When:03:23:43Z</guid>
		<description><![CDATA[UPDATE `my_table` SET `my_field` = (SELECT CASE `my_field` WHEN ‘1’ THEN ‘0’ ELSE ‘1’ END) WHERE `my_table_ID_Field` = ‘1’
UPDATE `my_table` SET `my_other_field` = (SELECT CASE `my_other_field` WHEN ‘foo’ THEN ‘bar’ ELSE ‘foo’ END) WHERE `my_table_ID_Field` = ‘1’
Here is the test table
CREATE TABLE `my_table` (
&#160; `my_table_ID_Field` int(11) NOT NULL auto_increment,
&#160; `my_field` int(11) NOT NULL,
&#160; `my_other_field` varchar(64) [...]]]></description>
			<content:encoded><![CDATA[<p>UPDATE `my_table` SET `my_field` = (SELECT CASE `my_field` WHEN ‘1’ THEN ‘0’ ELSE ‘1’ END) WHERE `my_table_ID_Field` = ‘1’</p>
<p>UPDATE `my_table` SET `my_other_field` = (SELECT CASE `my_other_field` WHEN ‘foo’ THEN ‘bar’ ELSE ‘foo’ END) WHERE `my_table_ID_Field` = ‘1’</p>
<p>Here is the test table</p>
<p>CREATE TABLE `my_table` (<br />
&nbsp; `my_table_ID_Field` int(11) NOT NULL auto_increment,<br />
&nbsp; `my_field` int(11) NOT NULL,<br />
&nbsp; `my_other_field` varchar(64) NOT NULL,<br />
&nbsp; PRIMARY KEY  (`my_table_ID_Field`)<br />
);</p>
<p>&#8212;&#8212;Dumping data for table `my_table`&#8212;</p>
<p>INSERT INTO `my_table` VALUES(1, 0, &#8216;foo&#8217;);</p>
]]></content:encoded>
			<wfw:commentRss>http://jamesborder.com/2009/04/mysql-toggle-a-field-value/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
