developer.com
Search EarthWeb
CodeGuru | Gamelan | Jars | Wireless | Discussions
Navigate developer.com
Architecture & Design  
Database  
Java
Languages & Tools
Microsoft & .NET
Open Source  
Project Management  
Security  
Techniques  
Voice  
Web Services  
Wireless/Mobile
XML  
Technology Jobs  

   Developer.com Webcasts:
  The Impact of Coding Standards and Code Reviews

  Project Management for the Developer

  Defining Your Own Software Development Methodology

  more Webcasts...




See the Winners!


Developer Jobs

Be a Commerce Partner
Rackmount LCD Monitor
Promos and Premiums
Disney World Tickets
Computer Deals
Online Education
Imprinted Gifts
GPS
Hurricane Shutters
Home Improvement
Best Price
Remote Online Backup
Auto Insurance Quote
Web Hosting Directory
Online Universities

 
Biz Resources
Contact Management Software
Domain Name Services
Internet Security


Download these IBM resources today!
e-Kit: IBM Rational Systems Development Solution
With systems teams under so much pressure to develop products faster, reduce production costs, and react to changing business needs quickly, communication and collaboration seem to get lost. Now, theres a way to improve product quality and communication.

Webcast: Asset Reuse Strategies for Success--Innovate Don't Duplicate!
Searching for, identifying, updating, using and deploying software assets can be a difficult challenge.

eKit: Rational Build Forge Express
Access valuable resources to help you increase staff productivity, compress development cycles and deliver better software, fast.

Download: IBM Data Studio v1.1
Effectively design, develop, deploy and manage your data, databases, and database applications throughout the data management life.

eKit: Rational Asset Manager
Learn how to do more with your reusable assets, learn how Rational Asset Manager tracks and audits your assets in order to utilize them for reuse.
Developer News -
Sun Latest to Help App Vendors Get 'SasSy'    April 24, 2008
Ubuntu's 'Hardy' Cozy With Windows    April 24, 2008
The $4.6B Business of The Social    April 22, 2008
Office 2007 Fails The OOXML Test    April 22, 2008
Free Tech Newsletter -

Project Management Guide: Developing a Web Site. Best Practices, Tips and Strategies. Download Exclusive eBook Now.

Secrets of the MySQL Client Command Line
By W. Jason Gilmore

Go to page: 1  2  Next  

Graphically oriented MySQL administration tools abound, but for true speed and no-frills management perhaps nothing is more effective than the command-line driven MySQL client. However, the inordinate amount of typing due to executing common queries, determining what database you're currently logged into, and monitoring database server performance quickly can become tedious. In this article, I'll unveil a few of MySQL's command-line hidden features that can eliminate those extra keystrokes and along the way make you a much more efficient user of this powerful client.

Changing the Client Prompt

If I had a dollar for every time I ran show tables just as a reminder of which database was currently selected, I'd be writing this article from an exotic beach locale. The fact is, when regularly jumping among an IDE, shell prompt, and MySQL client prompt it can be very easy to forget your spot. Eliminate this problem in its entirety by changing MySQL's prompt by using the prompt command:

mysql>prompt mysql (\d)>

Once executed, the currently selected database will appear in the prompt, like so:

mysql (corporate)>

It's also easy to lose track of which database server you're logged in to, not to mention which account you're using. To fix this, modify your prompt using the \u and \h options:

mysql>prompt mysql (\u@\h)>

This produces a prompt similar to the following:

mysql (root@www.wjgilmore.com)>

To render the change permanent, add the command to your .my.cnf file like so:

[mysql] prompt=mysql \\d>

The database, user, and host options are just a few of many available to you. See the MySQL documentation for more information.

Use Shell Aliases to Execute Common MySQL Commands

Suppose your new web application is really starting to take off, with new users registering by the hour. Like a stock IPO, chances are you and your colleagues are regularly peeking the user count. But, constantly logging in to and out of MySQL just to execute a simple query is aggravating. However, if you're otherwise logged in to the server, you can create a shell alias that will log in to the MySQL server, select the appropriate database, and execute a specific command:

%>alias usrcount="mysql -u appadmin -p myapplication
                        -e \"select count(id) from users\""

In this example, you're logging in to the local MySQL server using the appadmin user account, selecting the myapplication database, and passing in the SELECT query for execution using the little-known -e option. Now, any time you want to determine how many users are in the system, just execute the following command and provide the appadmin user password:

%>usrcount
Enter password:
+-------------+
| count(id)   |
+-------------+
|         348 |
+-------------+

To make the alias permanent, add it to your .bashrc or similar shell configuration file.

Rendering Query Results in Vertical Format

Easily reviewing SELECT query results in a shell window can be particularly difficult when a table consists of numerous columns. Remedying this inconvenience is easily done by appending the \G switch to the query:

mysql>SELECT * from users WHERE id=1\G

Executing this query with the \G switch attached formats the output like so:

mysql test>select * from users where id=1\G
*************************** 1. row *********
       id: 1
     name: Jason
    email: jason@example.com
telephone: (614)999-9999
     city: Columbus
1 row in set (0.00 sec)

Create a CSV File From Query Results

If you're using a database professionally, chances are a colleague has asked you to dump data from the database into an Excel file to perform further analysis. Did you know you can modify a SELECT query to do all of the CSV formatting for you, and place the data in a textfile? All you need to do is identify how the fields and lines should be terminated. For example, to dump a table named users to a CSV file named users.csv, execute this command:

mysql>SELECT * FROM users INTO OUTFILE '/home/jason/users.csv'
   FIELDS TERMINATED BY '\t\' ->LINES TERMINATED BY '\n';

Go to page: 1  2  Next  


Tools:
Add www.developer.com to your favorites
Add www.developer.com to your browser search box
IE 7 | Firefox 2.0 | Firefox 1.5.x
Receive news via our XML/RSS feed


developer.com Archives

Work With InterSystems. Not Separate Systems. Rapidly develop and deploy connectable applications.
Five Trends for Application Development. Download Your Complimentary Report. Exclusive. Act Now.
Developing Intelligent Communications? Visit the Avaya DevConnect Center on DevX.
Whitepaper: XML Processing in Applications--Take the Next Step
Guide to Developing a Web Site. Best Practices, Tips and Strategies. Download Exclusive eBook Now.



JupiterOnlineMedia

internet.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

Jupitermedia Corporate Info


Legal Notices, Licensing, Reprints, & Permissions, Privacy Policy.

Advertise | Newsletters | Tech Jobs | Shopping | E-mail Offers

Solutions
Whitepapers and eBooks
Microsoft Article: HyperV-The Killer Feature in WinServer ‘08
Avaya Article: How to Feed Data into the Avaya Event Processor
Microsoft Article: Install What You Need with Win Server ‘08
HP eBook: Putting the Green into IT
Whitepaper: HP Integrated Citrix XenServer for HP ProLiant Servers
Intel Go Parallel Portal: Interview with C++ Guru Herb Sutter, Part 1
Intel Go Parallel Portal: Interview with C++ Guru Herb Sutter, Part 2--The Future of Concurrency
Avaya Article: Setting Up a SIP A/S Development Environment
IBM Article: How Cool Is Your Data Center?
Microsoft Article: Managing Virtual Machines with Microsoft System Center
HP eBook: Storage Networking , Part 1
Microsoft Article: Solving Data Center Complexity with Microsoft System Center Configuration Manager 2007
MORE WHITEPAPERS, EBOOKS, AND ARTICLES
Webcasts
Intel Video: Are Multi-core Processors Here to Stay?
On-Demand Webcast: Five Virtualization Trends to Watch
HP Video: Page Cost Calculator
Intel Video: APIs for Parallel Programming
HP Webcast: Storage Is Changing Fast - Be Ready or Be Left Behind
Microsoft Silverlight Video: Creating Fading Controls with Expression Design and Expression Blend 2
MORE WEBCASTS, PODCASTS, AND VIDEOS
Downloads and eKits
Sun Download: Solaris 8 Migration Assistant
Sybase Download: SQL Anywhere Developer Edition
Red Gate Download: SQL Backup Pro and free DBA Best Practices eBook
Red Gate Download: SQL Compare Pro 6
Iron Speed Designer Application Generator
MORE DOWNLOADS, EKITS, AND FREE TRIALS
Tutorials and Demos
How-to-Article: Preparing for Hyper-Threading Technology and Dual Core Technology
eTouch PDF: Conquering the Tyranny of E-Mail and Word Processors
IBM Article: Collaborating in the High-Performance Workplace
HP Demo: StorageWorks EVA4400
Intel Featured Algorhythm: Intel Threading Building Blocks--The Pipeline Class
Microsoft How-to Article: Get Going with Silverlight and Windows Live
MORE TUTORIALS, DEMOS AND STEP-BY-STEP GUIDES