Click to search Andy Jarrett.co.uk RSS feed

Loading Twitter

MySQL Workbench now available for Mac

MySQL Workbench 5.2.16 beta is now available for Mac after a long stale development period. After moving the windows version forward its good to see they are concentrating back development for other OS's. You can learn and find out more via their blog at http://wb.mysql.com/

Comments Comments (0) | Print Print | Send Send | 1152 Views

Change auto increments starting number

If you ever have the need to change the starting number on a auto increment column (on a MySQL table) its pretty simple

view plain print about
1ALTER TABLE tablename AUTO_INCREMENT = 12345

Comments Comments (0) | Print Print | Send Send | 1197 Views

Case sensitive selects in MySQL

There has been a couple of reasons recently that I needed to do a look up on a MySQL table using a case-sensitive Select statement. Its actually as easy as using "LIKE BINARY" instead of "LIKE" e.g.

view plain print about
1SELECT username, password
2FROM tablename
3WHERE password LIKE BINARY 'SOmE PAssWOrD'
Obviously if you are on a CFML engine don't forget
<cfqueryparam cfsqltype="cf_sql_varchar" value="SOmE PAssWOrD" />

Comments Comments (1) | Print Print | Send Send | 988 Views

My blog has moved

Please update your bookmarks and feeds for my site.

I now have a Mango Blog at:

http://www.andyjarrett.com/blog

Feed URL: http://feeds.feedburner.com/andyjarrett

Comments Comments (0) | Print Print | Send Send | 1196 Views

Getting remote access to MySQL

After setting up my server yesterday I had issue with getting remote access to MySQL it was like it wasn't even running. After some digging around and annoying a linux user (always make sure you know a *nix admin guy, and buy him a scotch or two to say thanks) I found out is was running and it just wasn't bound to the machine's IP address but instead to localhost. For security reasons remote access disabled, but sometimes you need it for one reason or another.

  1. Login via SSH
  2. Edit the my.cnf. On Ubuntu you can do this
    view plain print about
    1$ sudo nano /etc/my.cnf
  3. Once file open look for bind-address=127.0.0.1 and change it for your host machine IP address. So if you host machine is 10.0.1.1 your configuration file would look like:
    view plain print about
    1# Instead of skip-networking the default is now to listen only on
    2# localhost which is more compatible and is not less secure.
    3bind-address = 10.0.1.1
  4. Save, close and restart your mysql service to take change in effect
    view plain print about
    1$ /etc/init.d/mysql restart

Comments Comments (4) | Print Print | Send Send | 1548 Views

Sequel Pro update

Sequel pro, which is my prefered MySQL GUI have just released a 0.9.4. You can download it now at sequelpro.com/download.html.

Whats covered?

Comments Comments (1) | Print Print | Send Send | 1197 Views

CocoaMySQL is reborn as Sequel Pro

CocoaMySQL was an old project on sourceforge.net which as the title implies is a Cocoa GUI client for MySQL. Being Cocoa means it looks/feels like an OSX application and also as a native app made very quick to open and interrogate data.

It did have a couple of bugs so recently I was happy to find out that the CocoaMySQL had been abandoned (I knew that bit) and it's source code has been used to create a new project called Sequel Pro which has hosted its code on Google Code.

You can see the CocoaMySQL influence within the client but the look has been very much updated. 0.9.3 is the current release and they are towards a 1.0 release which should include an updated SQL framework, bug fixes etc. Check out www.sequelpro.com and code.google.com/p/sequel-pro/

Comments Comments (7) | Print Print | Send Send | 1368 Views

MySQL limit cffunction for Query and QoQ's

Query of a Query functionality was introduced in ColdFusion 5 and it gives the developer the ability to re-query a returned recordset. While it does implement the core set of SQL SELECT commands the one bit of functionality I miss is MySQL's Limit function (I miss this in ANY relational database thats not MySQL as it makes paginiation a doddle).

Limit in MySQL works as such:
view plain print about
1SELECT * FROM myTable LIMIT 0, 10

The above code will display the first 10 results from your your (table is 0 indexed)

view plain print about
1SELECT * FROM myTable LIMIT 5, 5

Starting from the 5th record this will bring back rows 6, 7, 8, 9, and 10

The idea behind the my <cffunction> is to mimic Limit with a passed in query. Of course this function can be used on any returned recordset but a lot of DB's have there own way of handling this which you might want to investigate first.

view plain print about
1<cffunction name="limit" returntype="query" description="WORKS LIKE MYSQL LIMIT(N,N)">
2    <cfargument name="inQry" type="query" hint="I am the query" />
3    <cfargument name="arg1" type="numeric" />
4    <cfargument name="arg2" type="numeric" />
5    
6    <cfscript>
7        var outQry = arguments.inQry;
8        var a1 = arguments.arg1-1;
9        var a2 = arguments.arg2-1;
10
11        if(arg1 GT 1){
12            outQry.RemoveRows(JavaCast( "int", 0 ), JavaCast( "int", arg1 ));
13        }
14        
15        outQry.RemoveRows(JavaCast( "int", arg2 ),JavaCast( "int", outQry.recordcount-arg2));
16    
17        return outQry;
18    
</cfscript>
19</cffunction>

Comments Comments (4) | Print Print | Send Send | 2764 Views

MySQL now a part of Sun

The company behind Java is acquiring MySQL for $1 billion in cash and stock options. From Jonathan Schwartz,Chief Executive Officer and President Sun Microsystem

"Sun will be unveiling new global support offerings into the MySQL marketplace. We'll be investing in both the community, and the marketplace - to accelerate the industry's phase change away from proprietary technology to the new world of open web platforms."

Hopefully this will mean that some money will go into the flaky MySQL Query Browser + Administrator that support MySQL

Read more about it here and here

Comments Comments (0) | Print Print | Send Send | 2291 Views

Find and Replace in MySQL

I needed to do a find and replace on a couple of fields in a table and was stuck on the best way to this. Initially I was going to download a database dump and via a text editor find/replace and then re-upload but then I found out that MySQL has a Replace() function.

All you need to do is

view plain print about
1UPDATE yourTable SET yourField = replace(yourField,from_str,to_str);

The "from_str" performs a case-sensitive match when searching! Obviously you can also expand this to add any other logic like a WHERE clause etc.

This probably works with other DB's ... I would of thought anyway

Comments Comments (6) | Print Print | Send Send | 5205 Views

More Entries

BlogCFC by Raymond Camden + Twitter @AndyJ + ColdFusion jobs + Contact Me + Snippets/Downloads + RSS .