Class #2 of the MySQL class is scheduled for this Monday, May 9nd at 7:00pm at CalTek and will cover the various clients used to access a MySQL server.
Due to space limitations the class is now full so no more students are currently being accepted.
*Complete syllabus for Class #2 are continued in the further reading section.*
_Instructor:_
*Steve Glasser :: steve_AT_fpig_(dot)_net*
_Class Contact:_
*Sharon Lake :: sharon_AT_linuxchixla_(dot)_org*
_Lab Help:_
*Solomon Chang :: skevin521_AT_yahoo_(dot)_com*
*_CLASS #2 SYLLABUS_*
Class 2 – Using the MySQL client. (Chapter 3 / MySQL-M 3.1, 4, 25)
_10% exam material_
- Invoking Command-Line Client Programs from Shell Prompt
- short vs. long
- shell> mysql -V or -h
- shell> mysql --version or --host
- options followed by values
- --host=myhost.example.com
- -h myhost.example.com
- -hmyhost.example.com
- default values and changing default values through my.cnf
- Windows my.ini /my.cnf
- *nix global /etc/my.cnf, local /home/user/.my.cnf
- Connection Parameter Options
- Host (default value localhost)
- --host=host_name / -h host_name / -hhost_name
- Port (default value 3306)
- --port=port_number / -P port_number
- Socket (default value *nix /tmp/mysql.sock, Windows pipe name 'MySQL')
- --socket=socket_name / -S socket_name
- Windows NT servers --enable-named-pipe option
- User (default value *nix system login name, Windows 'ODBC')
- --user=user_name / -u user_name / -uuser_name
- Password (no default value)
- --password=password_value or -ppassword_value
- Note spacing (-ppassword_value)
- OK to omit the password_value in initial connection parameter as with either span STYLE="font-weight: medium">–password or -p flag a password prompt will appear
- If you omit the password option then your MySQL account must be specifically set up to allow you to connect without a password.
- Compress
- --compress / -C
- Using Custom Option Files
- --defaults-file=file_location
- Must be first option after the command name
- For an option specified multiple times in the same or separate option file(s), the option found last takes precedence.
- Options on the command line take precedence over options found in options files
- Selecting Default (or Current) Database
- Naming on command line when connecting
- shell> mysql --user=username --password database_name
shell> mysql --user=lroot --password world - shell> mysqldump --user=username --password database_name > database_name.sql
shell> mysqldump --user=root --password world > world.sql
- Specifying with sql statements
- mysql> SELECT * FROM database_name.database_table;
- Select or Change default database
- mysql> USE database_name;
mysql> SELECT * FROM database_table;
- MySQL Client Program
- Interactive mode
- useful for day-to-day, one time queries, etc.
- Batch mode
- running prewritten queries, complex queries that are difficult to type, or to be run automatically by scheduler without user intervention.
- Using MySQL Client Interactively
- Connect to server and database
- shell> mysql -u root -p -h localhost world
- A mysql> prompt will appear ready to accept sql statements
- mysql> is primary prompt
- -> generic secondary prompt: waiting for next line of statement or statement terminator
- '> specific secondary prompt: waiting for end of single-quoted string
- “> specific secondary prompt: waiting for end of double-quoted string
- `> specific secondary prompt: waiting for end of backtick-quoted identifier.
- Canceling a statement with clear query \c
- sql statement need to be terminated in order for the MySQL server to execute.
- The terminators ; and \g are interchangeable
- mysql> SELECT * FROM world;
- mysql> SELECT * FROM world\g
- The terminator \G (capital G) displays query results with each column value on a separate line
- mysql> SELECT * FROM world\G
- Executing statements from text or source file. If statement in source file end with an error, mysql ignores remainder of file. To execute entire file regardless of statement errors use the --force or -f option. A source file can contain other execute other source files, but careful of endless source loops.
- mysql> SOURCE source_path/file_name;
- shell> mysql database_name < source_path/file_name
- MySQL output
- Interactive Mode displays with bars and dashes in tabular format
- Batch Mode produces tab-delimited output between data values
- Output options
- --batch or -B to display with tabs even if used interactively
- --raw or -r option to suppress newline and carriage return escape-sequences like \n or \r
- --table or -t to display tabular format in table even if used in batch mode
- --html or -H to produce output in HTML format
- --xml or -X for XML format
- Summary of Client Commands.
- Long form is case insensitive, short form case sensitive.
- Long form can only be executed at the mysql> primary prompt unless you invoke with --named-commands options. Short form can be executed on any input line
- mysql> sql statements: SELECT,INSERT, UPDATE, and DELETE
- mysql> QUIT or \q
- mysql> SOURCE or \.
- mysql> STATUS or \s
- mysql> HELP or \h
- mysql> CLEAR or \c
- Using --safe-updates option (--i-am-a-dummy)
- Limits UPDATE and DELETE statement to those either containing a WHERE clause or a LIMIT clause.
- Restricts returned rows to 1,000 unless the statement has a LIMIT clause.
- Multiple-table SELECT statements are allowed only if MySQL will examine no more than 1,000,000 rows to process the query.
- mysqlimport
- mysqldump
- Reloading mysqldump output
- Checking tables with mysqlcheck and myisamchk
- MySQL Connectivity Drivers
- MySQL Connector/ODBC
- MySQL Connector/J