mysql magazine: summer 2008 (issue #5)
TRANSCRIPT
-
8/14/2019 MySQL Magazine: Summer 2008 (Issue #5)
1/42
MySSQQLL MMaaggaazziinnee
IIIINSIDENSIDENSIDENSIDE TTTTHISHISHISHIS IIIISSUESSUESSUESSUE
2 SQLYog Enterprise Edition Version 6.55 Review
10 Ma'atkit Toolkit Tutorial: mk-table-checksum
13 Command Line mysql Client Options
21 MySQL Magazines 2008 Annual Usage Survey
Summer 2008
I s sue 5
RRRREGULAREGULAREGULAREGULAR FFFFEATURESEATURESEATURESEATURES
6 Coding Corner
22 news
42 log-bin
News, articles and feedback for MySQL database administrators and developersusing MySQL on a daily basis to provide some of the best database infrastructure available.
-
8/14/2019 MySQL Magazine: Summer 2008 (Issue #5)
2/42
Page 2 Summer 2008 MySQL Magazine
This software is one of the most popular GUI-based tools for MySQL. Most of the features of the software
are geared to help the daily work of DBAs and developers. The software is rich in features and therefore thisreview will only highlight some of the cool capabilities.
Connection to Remote Servers
SQLYog Enterprise Edition Version 6.55 Review
One nice thing about this software
is that you can easily scan your
database for information. Here is a
quick example. Let's say that you
have several tables in a database with
multiple columns, and you want to
query your database. If you are using
the command line, you would
probably use the following: show
tables status, show fields, show
create table, and show keys.
SQLyog gives you the ability to
see your table information as soon as
Most companies require you to use the ssh
protocol to access their servers. While it is easy to
setup your own ssh tunnel to connect to your
remote database, it is quite cumbersome to do that.
SQLYog allows you to easily do this and lets you save
your secure MySQL connection. I use this all the time
and I do not even think about ssh tunnelinganymore.
On the downside, when I tried to connect to
another database, the software opened a separate
window for me. This made it difficult for me to
switch from one window to another. This can be
annoying if you want to compare two databases but
it could also be a security measure so that you do
SQLYog Reviewcontinues on next page
By Jonathan Cua
not accidentally apply the wrong SQL statements to the wrong database.
Scanning Table StructuresIf you want to find out the structure of a table, you typically have to type several commands from the
MySQL command line. Certainly there is nothing difficult about this, but if you are going to do this for several
tables then it becomes somewhat annoying.
-
8/14/2019 MySQL Magazine: Summer 2008 (Issue #5)
3/42
Page 3 Summer 2008 MySQL Magazine
you connect to your database. When you click on a table you immediately see the table definition, indexe
and columns associated with it. SQLyog actually runs all the above commands in the background so that i
can quickly show you the table structure at once.
You can imagine the time that you can save without typing all of the above commands. Also, when yo
are trying to write your SQL logic, you can ignore the needing to issue a show fields command in order toget the proper spelling of a column.
Multiple Ways to Create SQL QueriesThere are two ways to create queries in SQLyog.
1. T1. T1. T1. TYPE THE QUERY IN A QYPE THE QUERY IN A QYPE THE QUERY IN A QYPE THE QUERY IN A QUERY TAB WINDOW WITHUERY TAB WINDOW WITHUERY TAB WINDOW WITHUERY TAB WINDOW WITH THE AID OF AUTOTHE AID OF AUTOTHE AID OF AUTOTHE AID OF AUTO----COMPLETE ANDCOMPLETE ANDCOMPLETE ANDCOMPLETE AND SQLSQLSQLSQL SYNTAX TEMPLATESYNTAX TEMPLATESYNTAX TEMPLATESYNTAX TEMPLATE....
where you can simply insert SQL templates that give you the proper syntax ready for use.
2. U2. U2. U2. USE THESE THESE THESE THE QQQQUERYUERYUERYUERY BBBBUILDER TO CREATE THEUILDER TO CREATE THEUILDER TO CREATE THEUILDER TO CREATE THE QUERYQUERYQUERYQUERY....
Unlike the MySQL command lin
where you have to type everythin
correctly (SQL code, column names, tabl
names) SQLyog helps you by providing a
auto-complete feature where you simplclick on the TAB button and it wi
complete the word that you are typing
This could be a SQL function, colum
name, or table name.
Also, how many times have yo
forgotten the syntax of a SQL comman
and you had to search for the prope
syntax of it? SQLyog has a built-in featur
This involves dragging
the table from the schema
objects to a blank window.
You can then join tables,
specify filters, group the
columns, and arrange the
sort order. The software
will build the equivalent
SQL command for you andall of this can be done
without typing a single
SQL code.
SQLYog Reviewfrom previous page
SQLYog Reviewcontinues on next page
-
8/14/2019 MySQL Magazine: Summer 2008 (Issue #5)
4/42
Page 4 Summer 2008 MySQL Magazine
the Windows scheduler to run backup and emails you of the result of the backup.
I tested this feature by letting the software save my backup scheduler configuration; the software stored
the information in an XML file where it contained my database username, database password, email address,
and email password all in plain text! I have tried to work around this problem but I could not find a way to
solve this.
Database and Structure Synchronization
SQLyog allows you to synchronize two different databases (both structure and data). It actually creates
the corresponding SQL commands so that if executed the two databases would become synchronized with
each other.
I tested this and I was satisfied with the SQL output of the software. It was able to synchronize two
different databases with little effort on my part. The tool has a wizard that will guide you step-by-step on
what to do. It was simply selecting which database and which tables to synchronize and it did its job.
I use this all the time when releasing new schema into production. This tool makes it easy to apply the
necessary SQL commands to make the production schema the same as the development schema.
Data ModelingSQLyog provides a visual schema designer where you can create your tables, design the relationships and
it will automatically update your database. One nice thing about this feature is that when I want to see the
relationship of two or three tables I just drag them in the browser window and the software will show me the
visual relationship of the tables.
If you are building an Entity Relationship Diagram (ERD) for a big database, then you would probably use
another software. But I find this feature of SQLyog quite handy as I do not have to rely on another software to
create a small ERD.
Database ManagementManaging the database is quite easy with this
software. I was able to create new tables, manage
indexes, add users and remove their permissions
without typing any SQL commands. It is all point and
click.
It also supports the following features: copying of
database to different hosts, creating duplicates of
tables, renaming of tables, re-ordering of the
columns, and changing the engine type of the
database. What made this easy is that the software will
guide you on what you have to do, so when you want
to create copies of your tables, it is simply a matter of
ust clicking on that option.
Backups with SQLyog were easy as well and I found
no difference between doing backups on SQLyog or
mysqldump. An additional feature is that SQLyog uses
SQLYog Reviewfrom previous page
SQLYog Reviewcontinues on next page
-
8/14/2019 MySQL Magazine: Summer 2008 (Issue #5)
5/42
Page 5 Summer 2008 MySQL Magazine
Migration ToolkitThis feature allows you to move non-MySQL data into your MySQL database. Just like the other features, i
has a wizard that will guide you on what you need to do. I have tried this feature a couple of times and i
seems to work just fine. I have not tested this on a large database and I do not know how the software wirespond to a larger dataset. Also, for a large database, I would probably do the migration in small steps such
as making sure that the old and new column definitions match, instead of doing everything in one big step
and finding out in the end that something was wrong in the beginning. So, I would be hesitant to completel
rely on this feature.
ConclusionThis software provides a nice tool for MySQL DBAs and developers. Although SQLyog does not provid
anything unique in terms of features (there are equivalent scripts or tools out there that will do the same job)
SQLyog attempt to provide an all-in-one solution. For more information, please visit the website
http://www.webyog.com.
About the AuthorJonathan Cua is a senior database administrator with over 10 years of experience in open source
technology, large databases and data management systems.
SQLYog Reviewfrom previous page
-
8/14/2019 MySQL Magazine: Summer 2008 (Issue #5)
6/42
Page 6 Summer 2008 MySQL Magazine
C o d i n g
o
rn
e
r
By Peter Brawleyhttp://www.artfulsoftware.com
Here is a case in point. Some firms motivate their sales forces with graduated sales commissionslike thegraduated income tax, but in the salespersons favor. Calculation of these commissions is stepwise, range by
range. Every computer-savvy bookkeeper on the planet knows how to do this in a spreadsheet. How is it done
in MySQL?
For an example assume the following tables for employee sales and commission rates:
Divide and ConquerA MySQL query might call up hundreds of data columns
and millions of data rows, but it will use seven basic
operations at mostselection,join, restriction, aggregation,division, union, and logical branching.
Then why are so many queries hard to write? Call it the
craftsmans dilemma. The set of tools is small and the rules
for using them are few, but problems come in unlimited
size, variety, complexity and disguise. As Kurt Gdel proved,
no algorithm can capture all the possibilities. To get better
at writing queries is to get better at the most famous
problem-solving meta-method in the world: divide and
conquer.
DROP TABLE IF EXISTS sales, comms;CREATE TABLE sales(employeeID int,sales decimal(10,2));
INSERT INTO tblsales VALUES(1,2000),(1,5000),(1,7000),(2,9000),(2,15000),(2,12000);SELECT * FROM tblsales;+------------+----------+| employeeID | sales |+------------+----------+| 1 | 2000.00 || 1 | 5000.00 || 1 | 7000.00 || 2 | 9000.00 || 2 | 15000.00 || 2 | 12000.00 |+------------+----------+CREATE TABLE comms(
commstart DECIMAL(10,2),commend DECIMAL(10,2),pct INT
);
INSERT INTO comms VALUES(0,10000,5), (10000,20000,10), (20000,30000,15),(30000,40000,20), (40000,50000,25), (50000,60000,30);
Divide and Conquercontinues on next page
-
8/14/2019 MySQL Magazine: Summer 2008 (Issue #5)
7/42
Page 7 Summer 2008 MySQL Magazine
SELECT * FROM comms;+-----------+----------+-----+| commstart | commend | pct |+-----------+----------+-----+
| 0.00 | 10000.00 | 5 || 10000.00 | 20000.00 | 10 || 20000.00 | 30000.00 | 15 || 30000.00 | 40000.00 | 20 || 40000.00 | 50000.00 | 25 || 50000.00 | 60000.00 | 30 |+-----------+----------+-----+
One atom of this problem molecule is how to apply one commission range (commstart to commend) to
one sales amount (amt). There are three cases to cover:
1. if amt < commstart, base amount = 0
2. if amt commend, base amount = commend - commstart
It is basic branching logic:
IF( s.amt < c.commstart,
0,
IF( s.amt
-
8/14/2019 MySQL Magazine: Summer 2008 (Issue #5)
8/42
Page 8 Summer 2008 MySQL Magazine
How do we plug the formula into the join? Add the formula to the SELECT list twicefor base amount and
for commission:SELECTs.employeeID ID, s.amt, c.commstart start, c.commend end,
IF( s.amt
-
8/14/2019 MySQL Magazine: Summer 2008 (Issue #5)
9/42
Page 9 Summer 2008 MySQL Magazine
Our Competition is Big.
That's Their Problem.
Kickfire Database Appliance 126:5 Ratio
Kickfire delivers the first high-performance database appliance forMySQL, bringing the power of the world's largest commercial query
processing systems to your world.
10x - 100x improvements in query, reporting and analysis
Self-tuning design supports ad hoc queries
Scalability into the terabytes
Small footprint with dramatic power and cooling savings
Read the Kickfire white paperto find out how to slash hardware buildout.
-
8/14/2019 MySQL Magazine: Summer 2008 (Issue #5)
10/42
Pa e 10 Summer 2008 M SQL
Maatkit Toolkit Tutorial: mk-table-checksum
Most production environments have a master/slave setup of servers. This provides the ability to easily
perform backups, have warm fail-over if you have a hardware failure on the master, etc. Replication between
the master and slave is fairly easy to set up, however as Baron Schwartz points out here:
http://www.xaprb.com/blog/2007/11/08/how-mysql-replication-got-out-of-sync/ it is possible (and
probably quite common) for a master
and slave to drift out of sync.
Fortunately, not only did he point out
the problem, he provides a fix for the
problem. Included in the maatkit toolkit
(http://maatkit.sf.net) is the mk-table-
checksum tool (and the related tool mk-
table-sync which we wont be discussingin this tutorial). It can tell you which
tables on the master and and slave are
out of sync and even tell you within a
fair degree what rows are out of sync.
Here is an example run:
mk-table-checksum chunksize 500000 replicate=test.checksum localhost
What are we doing here? Well, the chunksize option specifies that if tables are larger than 500,000 rows (in
this case) that they should be chunked broken apart when processing. This will mean that a table
doesnt get blocked for too long a period of time. The replicate option specifies that you are wanting the
checksum tool to use the test.checksum table to store results in. This can be very helpful in providing an
accurate picture of your results. The create command for this table should be:
CREATE TABLE `checksum` (`db` char(64) NOT NULL,`tbl` char(64) NOT NULL,`chunk` int(11) NOT NULL,`boundaries` char(64) NOT NULL,`this_crc` char(40) NOT NULL,`this_cnt` int(11) NOT NULL,
`master_crc` char(40) default NULL,`master_cnt` int(11) default NULL,`ts` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,PRIMARY KEY (`db`,`tbl`,`chunk`)) ENGINE=InnoDB DEFAULT CHARSET=latin1;
It doesnt have to be in the test database by the way. You can put it wherever you want. Your option. Just be
sure to specify the right database when running the mk-table-sync command.
The final option is really easy. It just specifies the location of the master server. In this case, I ran the
command on the master server itself so localhost was specified.
mk-table-checksumcontinues on next page
By Keith Murphy
Want to learn about MySQL?
For free?
Sessions scheduled every
Thursday at 15:00 CET
MySQL University is in session!
http://forge.mysql.com/wiki/MySQL_University
-
8/14/2019 MySQL Magazine: Summer 2008 (Issue #5)
11/42
Page 11 Summer 2008 MySQL
mk-table-checksumcontinued from previous page
It will take a while for this command to run if your databases are of a significant size. Once it is done
executing and your slave has caught up (if it lagged behind the master) then you just run the following:
mk-table-checksum replicate=test.checksum replcheck 2 localhost
This will give you the results you want. Here is some sample output:
mk-table-checksum --replicate=test.checksum replcheck 2 localhost
Differences on h=server.slaveDB TBL CHUNK CNT_DIFF CRC_DIFF BOUNDARIESdatabase_1 table_1 0 0 1 `clientid` < 184723database_1 table_2 0 0 1 `clientid` < 184721mysql db 0 -19 1 1=1mysql user 0 -1 1 1=1
This shows that there were some differences on the slave. In the mysql database, on the slave, there ar
nineteen fewer rows in the db table and one less row in the user database. This is because I have differen
permissions on my master and slave servers.
On database_1 I have two tables that are out of sync. The two table_1 tables (on the master and slave) have
the same row count (shown by the cnt_diffcnt_diffcnt_diffcnt_diff column). However, the crc_diffcrc_diffcrc_diffcrc_diff column shows that there ar
differences in the contents of the columns on the two tables. The boundariesboundariesboundariesboundaries column show you which chun
of the table that the differences are located in. You can use this to figure out the exact problem yourself.o
you can use the mk-table-sync tool to do this for you.
There is a custom udf (user defined function) that Baron Schwartz programmed for use in the maatki
toolkit. Essentially the udf provides a replacement for the md5 hash function in MySQL. This custom function
provides an impressive speedup. On two servers I ran the mk-table-checksum tool with the default setup and
then installed the udf and re-ran the checksum tool. Here are the results:
server checksum w/md5 checksum w/fvn
db3 17m10.220s 5m0.090s
db6 112m21.719s 53m58.368s
Clearly it is a great benefit to use this udf if you are running table checksums. So how do you set it up? The
source code is included in the tar.gz file that is distributed from the maatkit website. Just download an
unzip/untar. In the included files there is a udf directory with one file. To compile just:
gcc -fPIC -Wall -I/usr/include/mysql -shared -o fnv_udf.so fnv_udf.cc
The instructions are included in the source code. Once you have it compiled, just copy the resultant fil
(fnv_udf.so) to the /lib directory and then run the command:
mysql mysql -e CREATE FUNCTION fnv_64 RETURNS INTEGER SONAME fnv_udf.so
mk-table-checksumcontinues on next pag
-
8/14/2019 MySQL Magazine: Summer 2008 (Issue #5)
12/42
Pa e 12 Summer 2008 M SQL
This adds the function to your MySQL server setup. To test, log into mysql and make this call:
mysql> SELECT FNV_64(hello, world);
This should returns some results if everything is done properly. Once your MySQL server sees the new
udf maatkit will begin using it automatically.
Baron has an excellent background post on the fvn udf here:
http://www.xaprb.com/blog/2008/03/09/a-very-fast-fnv-hash-function-for-mysql
About the authorKeith Murphy is a MySQL database administrator for The Pythian Group. He is also the editor of MySQL
Magazine.The views and opinions expressed in this article are the authors own and may not reflect the views and
opinions of The Pythian Group.
mk-table-checksumcontinued from previous page
Are You Forging?
The MySQL Forge is the premier place for code, tools,
software previews, worklogs, and projects by and for theMySQL community.
Visit http://forge.mysql.com/ to see whats being forged!
-
8/14/2019 MySQL Magazine: Summer 2008 (Issue #5)
13/42
Page 13 Summer 2008 MySQL
Command Line mysql Client OptionsBy Sheeri K. Cabral
The most commonly used options for the mysql command line client are the connectivity options. These
options are boring because they do not improve your experience with the command line client:
Table 1, Connectivity Options to MySQL
OptionOptionOptionOption Long Option NameLong Option NameLong Option NameLong Option Name DescriptionDescriptionDescriptionDescription ExampleExampleExampleExample
-u uname --user=uname Specify username -u sheeri--user=webuser
-h host --host=host Specify database server; host can be a
short hostname, a fully qualified domain
name (FQDN) or an IP address.
-h 192.168.1.100--host=foo.bar.com
-p
-ppass
--password=pass Enclose pass in quotes if it has special
characters. If no password specifed, askfor password interactively.
-p-psecret
--password='foo!'
-P portnum --port=portnum Specify port -P 3307--port=3308
-S file --socket=file Specify socket; file can be a relative or
absolute path to the socket
-S /tmp/mysql.sock--socket=my.sock
The mysql client has many other useful options. Some options are similar to commands that can be run in
the interactive mysql shell. Others provide ways to change the formatting of the output, improve you
interactive and batch processing experiences, and change how the mysql client uses memory.
When thinking of the mysql command line client, you probably think of the interactive shell:
Welcome to the MySQL monitor. Commands end with ; or \g.Your MySQL connection id is 687673Server version: 5.0.45-community-nt-log MySQL Community Edition (GPL)
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql>
However, the mysql command line client can also be used to process a batch of queries.
Batch OptionsThe -execute option (short name -e) will process a batch list of one or more queries, provided on
command line:shell> mysql -u root -prootpass --execute="SHOW DATABASES;"+--------------------+| Database |+--------------------+| information_schema || mysql || sakila || test |+--------------------+
mysql optionscontinues on next pag
-
8/14/2019 MySQL Magazine: Summer 2008 (Issue #5)
14/42
Pa e 14 Summer 2008 M SQL
mysql optionscontinued from previous page
shell> mysql -u root -prootpass -e "SHOW DATABASES; USE mysql; SHOW TABLES LIKE 'user';"+--------------------+| Database |+--------------------+| information_schema || mysql || sakila || test |+--------------------++------------------------+| Tables_in_mysql (user) |+------------------------+| user |+------------------------+
shell>
You can also run a batch commands by redirecting SQL commands to the mysql command line client tool.
This can be done with pipes or using the redirection operator.
shell> echo SHOW DATABASES | mysql -u root -prootpassDatabaseinformation_schemamysqlsakilatest
shell> echo SHOW DATABASES; >> batch.sql && echo USE mysql; >> batch.sql && echo SHOWTABLES LIKE 'USER'; >> batch.sql
shell> more batch.sql
SHOW DATABASES;USE mysql;SHOW TABLES LIKE 'USER';
shell> mysql -u root -prootpass < batch.sqlDatabaseinformation_schemamysqlsakilatestTables_in_mysql (USER)user
Notice that the output is formatted differently. This is because redirected commands act as if they were in
batch mode. The -B option (long format --batch) disables interactive mode and enables the --silent option.
The --silent option replaces the default table formatting of the output with tab-separated rows, each on a
new line. To get non-table formatting using the execute option, use either the -B or the --silent option:
shell>mysql -u root -prootpass -B --execute="SHOW DATABASES;"Databaseinformation_schemamysqlsakilatest
Note: All the examples in thisarticle have been designed and
tested to work on both Linux and
Windows; they will likely work on
Solaris and Mac OS X as well.
mysql optionscontinues on next page
-
8/14/2019 MySQL Magazine: Summer 2008 (Issue #5)
15/42
Page 15 Summer 2008 MySQL
mysql optionscontinued from previous page
mysql optionscontinues on next pag
shell>mysql -u root -prootpass --silent -e "SHOW DATABASES;"Databaseinformation_schemamysqlsakilatest
If you want table-style formatting in batch mode, use the -t option (long format --table):
C:\Documents and Settings\Owner.TcationTreas>mysql
-u root -prootpass -t < batch.sql+--------------------+| Database |+--------------------+| information_schema || mysql || sakila || test |+--------------------+
+------------------------+| Tables_in_mysql (user) |+------------------------+| user |+------------------------+
Note that all of the options to mysql can be specified in
the [mysql] or [client] group of an option file, such as
/etc/my.cnf and ~/.my.cnf and my.ini. Simply use the long
name and omit the -- in front of the long name. So if you
want to disable table formatting all the time, simply put
silent in the [client] directive of a configuration file.
MySQL, MySQL logos and
the Sakila dolphin are
registered trademarks of
MySQL AB in the United
States, the European
Union and other countries.
MySQL Magazine is not
affiliated with MySQL AB,
and the content is not
endorsed, reviewed,
approved nor controlled
by MySQL AB.
Output OptionsIf you find yourself copying and pasting outpu
frequently, you probably curse MySQL's table-styl
formatting. The good news is that the --silent option
works with the interactive mysql command line as wel
Note that in silent mode, the usual MySQL heade
showing information like the version, connection ID and
welcome message are suppressed, as well as the Bye
message upon exit:
shell>mysql -u root -prootpass --silentmysql> SHOW DATABASES;Databaseinformation_schemamysqlsakilatestmysql> exit
shell>
Have a topic for afuture editionof
the MySQL Magazine? Sendarticles and ideas to:Keith Murphy, Editor
Download pDownload pDownload pDownload previous editionsrevious editionsrevious editionsrevious editions
of the MySQL Magazineof the MySQL Magazineof the MySQL Magazineof the MySQL Magazine at:at:at:at:
http://www.mysqlzine.nethttp://www.mysqlzine.nethttp://www.mysqlzine.nethttp://www.mysqlzine.net
andandandandhttp://paragonhttp://paragonhttp://paragonhttp://paragon----cs.com/mag/cs.com/mag/cs.com/mag/cs.com/mag/
-
8/14/2019 MySQL Magazine: Summer 2008 (Issue #5)
16/42
Pa e 16 Summer 2008 M SQL
While using silent or table mode, it may be desirable not to have the column names printed. The --skip-
column-names option does just that:
shell> mysql -u root -prootpass --skip-column-names
Welcome to the MySQL monitor. Commands end with ; or \g.Your MySQL connection id is 21Server version: 5.0.45-community-nt-log MySQL Community Edition (GPL)
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql> show databases;+--------------------+| information_schema || mysql || sakila || test |+--------------------+
4 rows in set (0.00 sec)
mysql> exitBye
shell>mysql -u root -prootpass --silent --skip-column-namesmysql> show databases;information_schemamysqlsakilatestmysql> exit
shell>The \G command in the interactive mysql command line shell is very useful when used at the end of a
query instead of ; or \g, it outputs a query in vertical format. The -E option (long format --vertical) makes the
output print vertically without having to use the \G command with every query. This vertical option can be
used interactively or in batch mode:shell> mysql -u root -prootpass --vertical mysql -e "SHOW TABLE STATUS LIKE 'user';*************************** 1. row ***************************Name: userEngine: MyISAMVersion: 10Row_format: DynamicRows: 2
Avg_row_length: 104Data_length: 312Max_data_length: 281474976710655Index_length: 2048Data_free: 104Auto_increment: NULLCreate_time: 2007-07-04 09:49:18Update_time: 2007-09-23 16:14:15Check_time: NULLCollation: utf8_binChecksum: NULLCreate_options:Comment: Users and global privilegesshell>
mysql optionscontinued from previous page
mysql optionscontinues on next page
-
8/14/2019 MySQL Magazine: Summer 2008 (Issue #5)
17/42
Page 17 Summer 2008 MySQL
mysql optionscontinued from previous page
mysql optionscontinues on next page
If you want to have fancier output, the -H option (long format html) and -X option (long format xml) wil
output html and xml styles, respectively:
shell>mysql -u root -prootpass --html mysqlWelcome to the MySQL monitor. Commands end with ; or \g.Your MySQL connection id is 28Server version: 5.0.45-community-nt-log MySQL Community Edition (GPL)
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql> show tables;Tables_in_mysqlcolumns_privdbfunchelp_categoryhelp_keywordhelp_relationhelp_topichostprocprocs_privtables_privtime_zonetime_zone_leap_secondtime_zone_name
time_zone_transitiontime_zone_transition_typeuser17 rows in set (0.00 sec)
mysql> exitBye
shell> mysql -u root -prootpass --xml -e "USE mysql; SHOW TABLE STATUS LIKE 'user';
userMyISAM10Dynamic210431228147497671065520481042007-07-04 09:49:182007-09-23 16:14:15
utf8_binUsers and global privileges
-
8/14/2019 MySQL Magazine: Summer 2008 (Issue #5)
18/42
Pa e 18 Summer 2008 M SQL
mysql optionscontinued from previous page
mysql optionscontinues on next page
Logging OutputYou may already know about the --tee and --disable-tee options, which are similar to the mysql
interactive commands tee and notee. --tee=name will append output into the outfile specified as well asdisplaying it on screen. This is similar to:
mysql> tee nameLogging to file 'name'
To stop writing to the outfile while in the interactive client shell, the notee command is used:
mysql> noteeOutfile disabled.
The equivalent option to mysql is --disable-tee will disable the outfile. Using --disable-tee still allows
for the tee and notee commands to be run in the interactive client shell. Thus, using --disable-tee only
makes sense if you want to override a --tee option specified in an option file.
Other OptionsAnother option that is similar to a command on the interactive command line is --prompt=name, similar to
the prompt command on the interactive command line. This sets the mysql prompt to name. The default is
mysql>. Diego Medina has a sample prompt on the MySQL Forge at:
http://forge.mysql.com/tools/tool.php?id=126
shell>mysql -u root -prootpass --prompt="mysql [\h] {\u} (\d) > "Welcome to the MySQL monitor. Commands end with ; or \g.Your MySQL connection id is 44Server version: 5.0.45-community-nt-log MySQL Community Edition (GPL)
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql [localhost] {root} ((none)) > use mysql;Database changedmysql [localhost] {root} (mysql) >
\h, \u, and \d are special character sequences that refer to the host, username, and database, respectively.
A complete list of special character sequences to use with --prompt can be found at
http://dev.mysql.com/doc/refman/5.0/en/mysql-commands.html.
Another useful interactive option is --pager, which specifies the pager to use to display results. The most
common usage is --pager=more (or less), but you can also use any appropriate shell command:
-
8/14/2019 MySQL Magazine: Summer 2008 (Issue #5)
19/42
Page 19 Summer 2008 MySQL
mysql optionscontinued from previous page
mysql optionscontinues on next pag
shell> mysql -u root -prootpass --pager="grep info"Welcome to the MySQL monitor. Commands end with ; or \g.Your MySQL connection id is 68Server version: 5.0.45-community-nt-log MySQL Community Edition (GPL)
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql> show databases;| information_schema |4 rows in set (0.02 sec)
mysql> use information_schemaReading table information for completion of table and column namesYou can turn off this feature to get a quicker startup with -A
Database changed
mysql> show tables;| Tables_in_information_schema |16 rows in set (0.03 sec)
mysql>
Some folks find it annoying that MySQL will
display an error, but in order to see a warning you
have to type SHOW WARNINGS after noticing that a
warning was generated. You can set the --show-
warnings option to automatically print warning
statements just like error statements.
I will end with one of my favorite options to themysql command line client, --sigint-ignore. This
ignores the SIGINT command, otherwise known as
CTRL-C. CTRL-C means copy in many programs,
and I often hit CTRL-C after highlighting some text
because I mean to copy it. This sends a sigint or
break signal to the mysql server, which is not the
desired result. The --sigint-ignore option means
that I can hit CTRL-C to my heart's content and not
cause anything to happen. You will have to test this
on your own system, as it is difficult to show that akeystroke had no effect in an article.
For a complete listing of what your client can do,
use the --help option to mysql. As you might
expect, --help shows syntax and available options
for your version ofmysql. However, --help also
notes the order in which the applicable option files
are read, and which groups are applied:
Cant Get Enough?
If a quarterly dose of MySQL news andtechnical articles is not enough, visit PlanetMySQL at http://planetmysql.org to readthe MySQL employee and community blogs.There are several new articles daily;bloggers can submit feeds as well.
http://planetmysql.org
-
8/14/2019 MySQL Magazine: Summer 2008 (Issue #5)
20/42
Pa e 20 Summer 2008 M SQL
shell> mysql --help | moremysql Ver 14.12 Distrib 5.0.16, for pc-linux-gnu (i386) using readline 5.0
Copyright (C) 2002 MySQL ABThis software comes with ABSOLUTELY NO WARRANTY. This is free software,and you are welcome to modify and redistribute it under the GPL licenseUsage: mysql [OPTIONS] [database]-?, --help Display this help and exit.-I, --help Synonym for -?......[more options deleted]......--show-warnings Show warnings after every statement.
Default options are read from the following files in the given order:/etc/mysql/my.cnf ~/.my.cnfThe following groups are read: mysql client
The last part of the output of --help is the default variable settings after the applicable configuration files
and groups are read:
Variables (--variable-name=value)and boolean options {FALSE|TRUE} Value (after reading options)--------------------------------- -----------------------------auto-rehash TRUEcharacter-sets-dir (No default value)default-character-set latin1compress FALSEdatabase (No default value)delimiter ;......[more default values deleted]......secure-auth FALSEshow-warnings FALSE
Hopefully this article has helped you be more productive using the command line mysql client.
About the authorSheeri K. Cabral is a MySQL DBA for The Pythian Group. She founded Technocation, Inc.
(www.technocation.org), a not-for-profit organization dedicated to providing free educational resources for
IT professionals. In her spare time, she fills Technocations site with videos from conferences and user
groups, blog postings, and occasionally podcasts. For all her volunteer work, Cabral won MySQLs
Community Advocate Award in 2007 and 2008.
The views and opinions expressed in this article are the authors own and may not reflect the views and
opinions of The Pythian Group.
mysql optionscontinued from previous page
-
8/14/2019 MySQL Magazine: Summer 2008 (Issue #5)
21/42
Page 21 Summer 2008 MySQL
Surveycontinues on next pag
MySQL Magazine's 2008 Annual MySQL Usage Survey
By Keith Murphy
It has been my desire to do this survey for quite some time. With the help of Mark Schoonover wedeveloped thirty-four questions covering a range of subjects. There were over 400 responses to the survey
with people chiming in from all over the world. Because of space constraints I am not going to spend any
time giving analyses of the results here. In my log-bin column I manage to get in a few thoughts however.
Q1 Primary Job Function
0
20
40
60
80
100
120
140
160
180
48
4 6
59
59 7 8
159
60
9
Internet/Intranet/ExtranetManagement/Development/Strategy
E-BusinessManagement/Development/Strategy
E-CommerceManagement/Development/Strategy
New Media Manage-ment/Strategy
Webmaster/Web Devel-opment
Other E-Business/InternetManagement/Development/Strategy
IS/MIS/DP
Network SystemsDataCommunications/Telecommunications
Software/Applications De-velopment/Programming
SystemsEngineering/Analysis/Integration/Technical Services
Other
-
8/14/2019 MySQL Magazine: Summer 2008 (Issue #5)
22/42
Pa e 22 Summer 2008 M SQL
Surveycontinued from previous page
Q2 What country do you live in?
Survey continues on next page
AustraliaBrazil
BelgiumCanada
ChinaEurope
FinlandFrance
GermanyIndia
ItalyNetherlands
PeruPoland
RomaniaScotland
SerbiaSweden
UKUSA
South AmericaUkraine
0
5
10
15
20
25
30
6
1
3
7
3
1 1
2
3
2
4
2
1 1
2
1 1
8
4
27
2
1
NewsThis issue brings us a couple of announcements about major versions of software that can be used to
support MySQL. Monday, July the 14th, saw the release of SQLyog 7.0. We have a complete review of the
previous release in this very issue. New features of this release include:
New GRID design for easier navigation
Multiple selection in GRIDs with SHIFT+CLICK.
Improved Data Synchronization. Now typically 2-8 times faster than before depending on data.
Option to generate a SQL sync script was added.
Drastically improved the speed of exports.
New more user friendly design for the Schema Synchronization (renamed from Structure
Synchronization).
Added automatic and manual update check
In addition, one of our new advertisers, dbWatch Software, is opening a sales office in the United
States. Their product dbWatch (v8.1) is a heterogeneous database monitoring/reporting tool currently
supports Oracle, SQL Server, and MySQL.
-
8/14/2019 MySQL Magazine: Summer 2008 (Issue #5)
23/42
Page 23 Summer 2008 MySQL
Surveycontinued from previous page
Q3 Is your position local or remote?
0
50
100
150
200
250
300
350
310
80
Local ( I work in an office )
Remote
Q4 Years of MySQL Experience
0
20
40
60
80
100
120
140
160
46
121
136
70
19
-
8/14/2019 MySQL Magazine: Summer 2008 (Issue #5)
24/42
Pa e 24 Summer 2008 M SQL
Surveycontinued from previous page
Q5 Salary
0
5
10
15
20
25
30
35
30
15
20
12
27
12
17
13
20
17
24
16
19
24
1516
26
27
4
28
< $20,000
$20,000-$29,999
$30,000-$34,999
$35,000-$39,999
$40,000-$44,999
$45,000-$49,999
$50,000-$54,999
$55,000-$59,999
$60,000-$64,999
$65,000-$69,999
$70,000-$74,999
$75,000-$79,999
$80,000-$84,999
$85,000-$89,999
$90,000-$94,999
$95,000-$99,999
$100,000-$109,999
$110,000-$119,999
$120,000-$129,999
> $130,000
Surveycontinues on next page
-
8/14/2019 MySQL Magazine: Summer 2008 (Issue #5)
25/42
Page 25 Summer 2008 MySQL
Surveycontinues on next pag
Surveycontinued from previous page
Q6 Do you have additional duties?
0
50
100
150
200
250
300
214
108
272
26
System Administration
Network Administration
Programmer
Other
-
8/14/2019 MySQL Magazine: Summer 2008 (Issue #5)
26/42
Pa e 26 Summer 2008 M SQL
Surveycontinues on next page
Surveycontinued from previous page
Q7 What is your organization's primary business activity?Online RetailerInternet Service Provider (ISP) or Applica-
tion Service Provider (ASP)
Communications Carrier
Aerospace
Banking/Finance/Accounting
Insurance/Real Estate/Legal
Federal Government (including military)
State/Local Government
Medical/Dental/Healthcare
Transportation/Utilities
Construction/Architecture/EngineeringData Processing Services
Wholesale/Retail/Distribution
Education
Marketing/Advertising/Entertainment
Research/Development Lab
Business Services/Constultant
Computer Manufacturer (Hardware,
software, peripherals)
Computer/Network Services/Consultant
Computer Related
Reailer/Wholesaler/Distributor
0
10
20
30
40
50
60
70
80
28
71
5
1
18
1
6 7
13
52
22
3
3836
10
19
28
65
1
-
8/14/2019 MySQL Magazine: Summer 2008 (Issue #5)
27/42
Page 27 Summer 2008 MySQL
Surveycontinues on next pag
Surveycontinued from previous page
Q8 Do you have any MySQL Certifications?
0
50
100
150
200
250
300
350
400
343
1711 8
30
7
No
MySQL 4.x Base
MySQL 4.x Professional
Certified MySQL Associate(CMA)
Certified MySQL DatabaseAdministrator (CMDBA)
Certified MySQL ClusterAdministrator (CMCDBA)
Certified MySQL Developer(CMDEV)
-
8/14/2019 MySQL Magazine: Summer 2008 (Issue #5)
28/42
Pa e 28 Summer 2008 M SQL
Surveycontinues on next page
Surveycontinued from previous page
Q9 If you do have MySQL Certification, how did you prepare for it?
0
10
20
30
40
50
60
70
80
67
2
10
35
Self Study
Conference TutorialMySQL Training Course
Company Internal MySQLTraining Course
Other
-
8/14/2019 MySQL Magazine: Summer 2008 (Issue #5)
29/42
Page 29 Summer 2008 MySQL
Surveycontinues on next pag
Surveycontinued from previous page
Q10 Which MySQL Certification are you planning on obtaining this year?
0
50
100
150
200
250
300
350
288
13
41
18
39
None
Certified MySQL Associate(CMA)
Certified MySQL DatabaseAdministrator (CMDBA)
Certified MySQL ClusterAdministrator (CMCDBA)
Certified MySQL Developer(CMDEV)
Q11 What operating systems do you run MySQL on
Ubuntu
RedHat
CentOS
Slackware
Debian
Solaris SPARC
Solaris Intel
Windows 2000/2003
FreeBSD
MAC OS/X
Fedora
Other0
20
40
60
80
100
120
140
160
180
155
164
122
7
120
28 28
123
41
77
710
-
8/14/2019 MySQL Magazine: Summer 2008 (Issue #5)
30/42
Pa e 30 Summer 2008 M SQL
Surveycontinues on next page
Surveycontinued from previous page
Q12 What versions of MySQL do you use? (multiple choice)
0
50
100
150
200
250
300
350
22
164
313
206
16
MySQL 3.x
MySQL 4.x
MySQL 5.0.x
MySQL 5.1.x
MySQL 6.x
Q13 Do you work with other RDBS? (multiple choice)
No
Oracle
MSSQL
Sybase
PostgreSQL
DB2
SQLlite
Other0
20
40
60
80
100
120
140
160
137
106
101
22
99
9
27
19
-
8/14/2019 MySQL Magazine: Summer 2008 (Issue #5)
31/42
Page 31 Summer 2008 MySQL
Surveycontinued from previous page
Q14 Which MySQL high availability solution are you currently using? (multiple choice)
0
50
100
150
200
250
203
31
153
55
26
Q15 Have you or your company outsourced DBA duties?
0
50
100
150
200
250
300
350
400
34
350
TRUE
FALSE
Surveycontinues on next pag
None
MySQL with DRBDMySQL Simple Replication
MySQL Complex Replication
MySQL Cluster
-
8/14/2019 MySQL Magazine: Summer 2008 (Issue #5)
32/42
Pa e 32 Summer 2008 M SQL
Surveycontinued from previous page
Q16 Have you or your company ever outsourced programming duties?
0
50
100
150
200
250
300
117
270
TRUE
FALSE
Q17 Have you used the embedded version of MySQL (libmysqld)?
TRUE
FALSE0
50
100
150
200
250
300
350
400
40
341
Surveycontinues on next page
-
8/14/2019 MySQL Magazine: Summer 2008 (Issue #5)
33/42
Page 33 Summer 2008 MySQL
Surveycontinued from previous page
Q18 Which connectors do you use? (multiple choice)
0
50
100
150
200
250
39
102
86
1611
35
43
197
133
40
None
MySQL C API
MySQL Connector/J
MySQL Connector/NET 5.1
MySQL Connector/NET 5.2
MySQL Connector/ODBC 3.x
MySQL Connector/ODBC 5.x
DBD::MySQL
PHP PDO_MYSQLND
Python DB-API
Q19 Which programming languages do you use?(multiple choic
C/C++
C#
JavaMono
PHP
Perl
Ruby
Python
VB .NET
Visual Basic
bash/csh/ksh/zsh
Other0
50
100
150
200
250
300
110
32
124
5
247
218
46
75
18 20
138
29
Surveycontinues on next pa
-
8/14/2019 MySQL Magazine: Summer 2008 (Issue #5)
34/42
Pa e 34 Summer 2008 M SQL
Surveycontinued from previous page
Q20 Do you identify yourself as part of the community of MySQL users?
0
20
40
60
80
100
120
140
160
180
142
162
75
13
Yes
Somewhat
No
Don't Care
Q21 Do you use the MySQL Forge?
Yes
Somewhat
No
Don't Care0
20
40
60
80
100
120
140
160
180
142
162
75
13
Surveycontinues on next page
-
8/14/2019 MySQL Magazine: Summer 2008 (Issue #5)
35/42
Page 35 Summer 2008 MySQL
Surveycontinues on next page
Surveycontinued from previous page
Q22 Have you reported MySQL bugs?
0
50
100
150
200
250
300
126
266
TRUE
FALSE
Q23 Have you contributed to MySQL documentation
TRUE
FALSE0
50
100
150
200
250
300
350
400
33
357
-
8/14/2019 MySQL Magazine: Summer 2008 (Issue #5)
36/42
Pa e 36 Summer 2008 M SQL
Surveycontinues on next page
Surveycontinued from previous page
Q24 Have you contributed code to MySQL?
0
50
100
150
200
250
300
350
400
22
367
TRUE
FALSE
Q25 How often do you blog about MySQL?
Never
Multiple times a week.
Once a week.
Bimonthly
Once a month.
Every other month.
Too infrequent to remember.0
50
100
150
200
250
215
1318
14
2431
82
-
8/14/2019 MySQL Magazine: Summer 2008 (Issue #5)
37/42
Page 37 Summer 2008 MySQL
Surveycontinues on next pag
Surveycontinued from previous page
Q26 What is your favorite blog?BlogBlogBlogBlog CountCountCountCount
http://www.mysqlperformance.com 100http://www.planetmysql.com 77xaprb (Baron Schwartz) 44datacharmer (Giuseppe Maxia) 19krow (Brian Aker) 14Jay Pipes 10Pythian 9Jeremy Cole 8Sheeri Cabral 7Keith Murphy 7Q27 With the recent discussion on oursql-sources mailing list regrading the MySQL Contributor License
Agreement (CLA), should MySQL change the CLA to make it easier for the community to contribute code back
to MySQL?
0
20
40
60
80
100
120
140
160
180
165
Yes
No
Don't Care
-
8/14/2019 MySQL Magazine: Summer 2008 (Issue #5)
38/42
Pa e 38 Summer 2008 M SQL
Surveycontinues on next page
Surveycontinued from previous page
Q28 Do you think the community edition of MySQL will fork if the current CLA remains unchanged?
0
20
40
60
80
100
120
140
160
180
110
117
154
Yes
No
Don't Care
Q29 Which storage engines do you use? (multiple choice)
MyISAM
InnoDB
MERGEMEMORY (HEAP)
BDB
EXAMPLE
FEDERATED
ARCHIVE
CSV
BLACKHOLE
FALCON0
50
100
150
200
250
300
350
400
344 344
37
100
102
3037
2026
6
-
8/14/2019 MySQL Magazine: Summer 2008 (Issue #5)
39/42
Page 39 Summer 2008 MySQL
Surveycontinues on next page
Surveycontinued from previous page
Q30 The main reason for using Innodb?
0
50
100
150
200
250
192
78 78
33 Transaction support
Row-level locking
Foreign key support
I don't use InnoDB Q31 Do you use Federated?
Yes, in production
No, but I've tried it
No, I haven't tried it
I don't know what Federatedis
0
50
100
150
200
250
19
70
191
112
-
8/14/2019 MySQL Magazine: Summer 2008 (Issue #5)
40/42
Pa e 40 Summer 2008 M SQL
Surveycontinues on next page
Surveycontinued from previous page
Q32 I don't use federated because:
0
50
100
150
200
250
212
8
35
24
I don't need it
It doesn't have the features Ineed
It's not stable enough
It's not efficient
Q33 What is most important to you about MySQL server?
Performance
Reliability
Ease of Use
Other0
20
40
60
80
100
120
140
160
139 140
70
34
-
8/14/2019 MySQL Magazine: Summer 2008 (Issue #5)
41/42
Page 41 Summer 2008 MySQL
Surveycontinued from previous page
Q34 Are you a current customer of Sun/MySQL?
0
50
100
150
200
250
300
350
89
301
TRUE
FALSE
-
8/14/2019 MySQL Magazine: Summer 2008 (Issue #5)
42/42