• Home
  • MySQL
  • PHP
  • Apache
  • About
  • Contact Us
 
 
 
  • MySQL 5.5 Reference Manual
  • MySQL 5.1 Reference Manual
  • MySQL 3.23/4.0/4.1 Manual
  • MySQL 4.0 Russian Manual


MySQL 5.5 Reference Manual :: 4 MySQL Programs :: 4.5 MySQL Client Programs :: 4.5.1 mysql — The MySQL Command-Line Tool
« 4.5 MySQL Client Programs

4.5.1.1 mysql Options »
Section Navigation      [Toggle]
  • 4.5 MySQL Client Programs
  • 4.5.1 mysql — The MySQL Command-Line Tool
    • 4.5.1.1 mysql Options
    • 4.5.1.2 mysql Commands
    • 4.5.1.3 mysql Server-Side Help
    • 4.5.1.4 Executing SQL Statements from a Text File
    • 4.5.1.5 mysql Tips
  • 4.5.2 mysqladmin — Client for Administering a MySQL Server
  • 4.5.3 mysqlcheck — A Table Maintenance Program
  • 4.5.4 mysqldump — A Database Backup Program
  • 4.5.5 mysqlimport — A Data Import Program
  • 4.5.6 mysqlshow — Display Database, Table, and Column Information
  • 4.5.7 mysqlslap — Load Emulation Client

4.5.1. mysql — The MySQL Command-Line Tool

[+/-]

4.5.1.1. mysql Options
4.5.1.2. mysql Commands
4.5.1.3. mysql Server-Side Help
4.5.1.4. Executing SQL Statements from a Text File
4.5.1.5. mysql Tips

mysql is a simple SQL shell (with GNU readline capabilities). It supports interactive and noninteractive use. When used interactively, query results are presented in an ASCII-table format. When used noninteractively (for example, as a filter), the result is presented in tab-separated format. The output format can be changed using command options.

If you have problems due to insufficient memory for large result sets, use the --quick option. This forces mysql to retrieve results from the server a row at a time rather than retrieving the entire result set and buffering it in memory before displaying it. This is done by returning the result set using the mysql_use_result() C API function in the client/server library rather than mysql_store_result().

Using mysql is very easy. Invoke it from the prompt of your command interpreter as follows:

shell> mysql db_name

Or:

shell> mysql --user=user_name --password=your_password db_name

Then type an SQL statement, end it with “;”, \g, or \G and press Enter.

Typing Control-C causes mysql to attempt to kill the current statement. If this cannot be done, or Control-C is typed again before the statement is killed, mysql exits. Previously, Control-C caused mysql to exit in all cases.

You can execute SQL statements in a script file (batch file) like this:

shell> mysql db_name < script.sql > output.tab
Copyright © 1997, 2010, Oracle and/or its affiliates. All rights reserved. Legal Notices
Previous / Next / Up / Table of Contents

User Comments

Posted by kayalshri Raj on May 27 2009 6:32am  

We can create mysql qry files using following the way,

vim /usr/local/bin/mysqlconnect
mysql -uusername -ppassword dbname -hhostname
shell>mysqlconnect

vim /usr/local/bin/mysqlqry
mysql -uusername -ppassword dbname -e "select * from tablename"
shell>mysqlqry

Posted by Oswald Kienapfel on February 17 2010 7:29pm  

Note that the above shortcuts (such as creating mysqlconnect in linux) will avoid putting the password into the history file, but it is visible in the script itself so ensure the script is NOT world readable. (ie. chmod o-r mysqlconnect)

Top / Previous / Next / Up / Table of Contents
Copyright © 2011, doc0.ru
All rights reserved