Thursday, 10 September 2009

mysql hostname prompt when host is localhost

mysql hostname prompt when host is localhost: "
I manage several mysql servers and often on these servers for security reasons the SUPER account is not allowed external network access, so access is made to localhost. When connecting to several hosts at the same time, for example from different ssh sessions, this can be inconvenient as the \h prompt only ever shows localhost and not the hostname of the server to which I’m connected.

The following small patch against 5.1.36 which can also be found here adds a new \H option which behaves the same as \h except in this case the hostname is shown.

diff --git a/Docs/mysql.info b/Docs/mysql.info
index 7747201..dffacfd 100644
--- a/Docs/mysql.info
+++ b/Docs/mysql.info
@@ -20512,6 +20512,8 @@ sequences.
`\D'        The full current date
`\d'        The default database
`\h'        The server host
+`\H'        Same as `\h' except that if the server host is localhost
+            the client's hostname will be used
`\l'        The current delimiter (new in 5.1.12)
`\m'        Minutes of the current time
`\n'        A newline character
diff --git a/client/mysql.cc b/client/mysql.cc
index 5f360b8..b24fb14 100644
--- a/client/mysql.cc
+++ b/client/mysql.cc
@@ -39,6 +39,10 @@
#include <signal.h>
#include <violite.h>

+#ifdef SOLARIS
+extern "C" int gethostname(char *name, int namelen);
+#endif
+
#if defined(USE_LIBEDIT_INTERFACE) && defined(HAVE_LOCALE_H)
#include <locale.h>
#endif
@@ -4657,12 +4661,27 @@ static const char* construct_prompt()
case 'd':
processed_prompt.append(current_db ? current_db : "(none)");
break;
+      /* \H is the same as \h except if \h returns localhost in which case *
+       * we provide the client's hostname.                                 *
+       */
case 'h':
+      case 'H':
{
const char *prompt;
+        char  myhostname[255];
prompt= connected ? mysql_get_host_info(&mysql) : "not_connected";
-    if (strstr(prompt, "Localhost"))
-      processed_prompt.append("localhost");
+
+    if (strstr(prompt, "Localhost") || strstr(prompt, "localhost"))
+          if ( *c == 'h' ) {
+        processed_prompt.append("localhost");
+          }
+          else
+          {
+            if (gethostname(myhostname,sizeof(myhostname)) < 0)
+              processed_prompt.append( "gethostname(3) returned an error" );
+            else
+              processed_prompt.append( myhostname );
+          }
else
{
const char *end=strcend(prompt,' ');

This gives the output as shown below:

$ hostname
my.computer.domain.com
$ client/mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 6892
Server version: 5.0.xx MySQL Community Server (GPL)

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> prompt \h
PROMPT set to '\h '
localhost prompt \H
PROMPT set to 'prompt \H '
prompt my.computer.domain.com quit
Bye
$

As this uses the FQDN it may be necessary to add another option to show only the host’s short name but for now this patch is useful for me. I expect the patch should work against most other versions of MySQL. Perhaps this is useful enough to warrant putting in the main MySQL sources?

PlanetMySQL Voting:
Vote UP /
Vote DOWN"

Wednesday, 9 September 2009

BASH Script: Run a command in a loop....

to stop a process that is being controlled by another process that has accidentally been left running on your pc at work.

while true; do kill -SIGSTOP < processId > sleep 5; done

Monday, 7 September 2009

MenuetOS Running in VirtualBox on Linux

It's as simple as download the floppy disk image. Yes all 1.2MB.  Fire up VirutalBox and create a new machine exactly as you would for any other install.  I selected Other to both questions about which OS and version i was using.  You'll need to assign 512MB minimum RAM and turn on all the CPU extensions and double check your boot order is Floppy first. When enabling the floppy device, you get to select an image file. I noticed that it didn't seem to recognise the .IMG file by default so I had to switch to All files view. After that, just click Start, and about 3 seconds later you'll be up and running.  Fully. Ready to go.

Now, does anybody know how to get online with this OS?  Help!

Oh,.. and one more thing, it's a real pain to get your mouse pointer back. The usual right-ctrl key doesn't work.  Probably getting swallowed up far earlier in the event tree by MenuetOS.  You can get it back - mainly by mashing the keyboard around the bottom row of the keyboard (alt, shift, windows key, space, tab).  Somehow seems to allow the host to recapture the mouse etc.

Have fun.

Sunday, 6 September 2009

How to find un-indexed queries in MySQL, without using the log

How to find un-indexed queries in MySQL, without using the log: "
You probably know that it’s possible to set configuration variables to log queries that don’t use indexes to the slow query log in MySQL. This is a good way to find tables that might need indexes.


But what if the slow query log isn’t enabled and you are using (or consulting on) MySQL 5.0 or earlier, where it can’t be enabled on the fly unless you’re using a patched server such as Percona’s enhanced builds? You can still capture these queries.


The key is knowing what it really means for a query to “not use an index.” There are two conditions that trigger this — not using an index at all, or not using a “good” index. Both of these set a bit. If either bit is set, the query is captured by the filter and logged. Both of these bits also set a corresponding bit in the protocol, so the TCP response to the client actually says “here comes the result of your query, and by the way it didn’t use an index.” This is very useful information.


I’m sure you can see where this is going. Let’s use tcpdump to capture queries, consume the output with mk-query-digest, and filter out all but ones that don’t use an index or use no good index:


$ sudo tcpdump -i lo port 3306 -s 65535  -x -n -q -tttt \
| mk-query-digest --type tcpdump \
--filter '($event->{No_index_used} eq "Yes" || $event->{No_good_index_used} eq "Yes")'


If I run a few full table scans now, and then cancel mk-query-digest, I’ll get output like the following (abbreviated for clarity):


#              pct   total     min     max     avg     95%  stddev  median
# Count        100       8
# Exec time    100     5ms   511us   857us   604us   839us   106us   582us
# 100% (8)    No_index_used
select * from t\G


You can see I ran the query 8 times and each time it reported back that it didn’t use an index. This is a dead-easy way to find queries that might not have an index available!


Want to print out tables from those queries? You can do that too. Just add --group-by tables --report-format profile to the command above, and instead of grouping queries together by the query text, it’ll group them by the tables they mention. Then the report will contain one item per table and you’ll just see a summary at the end, like so:


# Rank Query ID           Response time    Calls   R/Call     Item
# ==== ================== ================ ======= ========== ====
#    1 0x                     0.0037 100.0%       8   0.000467 test.t


Aha, looks like test.t is the problem table!


Related posts:
  1. Finding queries with duplicate columns A while ag
  2. Learn about Maatkit at the MySQL Conference I’m
  3. Maatkit version 3119 released Your month

Related posts brought to you by Yet Another Related Posts Plugin.

PlanetMySQL Voting:
Vote UP /
Vote DOWN
"

How to Enable Bookmark Syncing in Chrome, Without an Add-on [Google Chrome]

How to Enable Bookmark Syncing in Chrome, Without an Add-on [Google Chrome]: "
Okay, so just a few minutes ago we pointed out that Xmarks now syncs bookmarks with Chrome—albeit in closed alpha test. Now Google announces that the latest Chrome dev channel release—4.0.201.1—adds bookmark synchronization without any add-ons.
It's interesting timing, to be sure, and we'd guess the Xmarks folks were probably watching the dev channel and decided to rush the announcement to beat Google to the punch. The fact is, Xmarks still offers something fairly different from what Google's sync tool will offer: namely, Xmarks will be able to sync between Chrome and virtually any other popular browser, including Firefox, IE, and Safari.
Chrome's sync tool will only work with Chrome, which means if you haven't decided you're ready to be a full-on Chrome adopter, Xmarks will probably remain the better option. Still, it's great to see progress all around with bookmark syncing in Chrome.

You'll need to use the Google Chrome Channel Chooser to join the Dev channel to get this release, start Chrome with the --enable-sync flag (right-click your Chrome shortcut, select Properties, then add --enable-sync behind the target as I've done in the screenshot), then just go to Wrench -> Sync my bookmarks.
Dev Channel Update [Google Chrome Releases]




"

Saturday, 5 September 2009

Google Points At WebFinger. Your Gmail Address Could Soon Be Your ID.

Google Points At WebFinger. Your Gmail Address Could Soon Be Your ID.: "
picture-1111There’s some excitement around the web today among a certain group of high profile techies. What are they so excited about? Something called WebFinger, and the fact that Google is apparently getting serious about supporting it. So what is it?

It’s an extension of something called the “finger protocol” that was used in the earlier days of the web to identify people by their email addresses. As the web expanded, the finger protocol faded out, but the idea of needing a unified way to identify yourself has not. That’s why you keep hearing about OpenID and the like all the time.

But those standards, while open, have failed to latch on in a meaningful way with the public at large. One of the holdups is that you have to set up a website or service you use to be your OpenID. It’s relatively easy to do, and you may already have one ready to go, but just not realize it. But it’s still kind of tricky to explain to a regular web user — wait, you login with your website?

But something everyone on the web knows is their email address. And they’re conditioned by services like Google and Facebook to use it as their identifier. The problem with it has been that it’s just a string of text, nothing more. You cannot attach information to it to let others know a bit more about you — something vital for true identification. Then idea behind WebFinger is that you should be able to attach any information you choose to your email address.

The excitement today is that a group of Googlers have apparently finally not only gotten Google’s support to pursue the project, but that they have started working the technical details. As Googler Brad Fitpatrick writes today:

In other words, we’ve eliminated both technical & political hurdles. We can now work on this spec, implement, push, try, rinse, repeat…. until we’re all reasonable happy.

Googler Brett Slatkin (incidentally, Fitzpatrick’s partner in making PubSubHubbub) explains to us that while it hasn’t been turned on yet, and that there’s still a lot of work to do on the spec, the idea is to go into testing mode soon. Fitzpatrick notes that there will be a small experiment going on internally with some Googlers’ Gmail accounts.

Without knowing much about the technical details behind it, the core idea behind WebFinger immediately strikes me as a good one. It’s taking something everyone knows on the web (your email address) and making it immensely more valuable as a way to identify yourself and information about you. Exactly what kind of information? Here are some of the ideas from the WebFinger Google Code page:

  • public profile data
  • pointer to identity provider (e.g. OpenID server)
  • a public key
  • other services used by that email address (e.g. Flickr, Picasa, Smugmug, Twitter, Facebook, and usernames for each)
  • a URL to an avatar
  • profile data (nickname, full name, etc)
  • whether the email address is also a JID, or explicitly declare that it’s NOT an email, and ONLY a JID, or any combination to disambiguate all the addresses that look like something@somewhere.com
  • or even a public declaration that the email address doesn’t have public metadata, but has a pointer to an endpoint that, provided authentication, will tell you some protected metadata, depending on who you authenticate as.

This is definitely something to watch for in the coming months.

[photo: flickr/chris owens]



Crunch Network: CrunchGear drool over the sexiest new gadgets and hardware.






"

Friday, 4 September 2009

Clinic 10077: What's New in Windows 7 for IT Professionals

Clinic 10077: What's New in Windows 7 for IT Professionals: "This two-hour clinic provides you with an overview of the new and enhanced deployment, security, manageability, and performance features in Windows 7. It describes how these features meet the day-to-day needs of IT professionals.



This clinic covers the following topics.

- Overview of Deployment Enhancements

- Overview of Security Enhancements

- Overview of Manageability and Performance Enhancements



IT professionals completing this clinic should have basic familiarity with deploying, managing, and maintaining Windows Vista or the Windows XP operating system.


This clinic has the same content as the previous version in an updated viewer with a new look and feel."

Check out some other Windows 7 Training books here:  Windows 7 Training Resources

Sike's shared items