Home |  MySQL Buzz |  FAQ |  Feeds |  Submit your blog feed |  Feedback |  Archive |  Aggregate feed RSS 2.0 English Deutsch Español Français Italiano 日本語 Русский Português 中文
Previous 30 Newer Entries Showing entries 61 to 90 of 90

Displaying posts with tag: tips (reset)

Linux/OSX: find out what network ports are in use
+0 Vote Up -0Vote Down

To get a quick idea of what ports you have open on your local box, you can use nmap.

~ jhaddad$ nmap localhost
Starting Nmap 5.00 ( http://nmap.org ) at 2010-01-05 11:06 PST
Interesting ports on localhost (127.0.0.1):
Not shown: 499 closed ports, 492 filtered ports
PORT STATE SERVICE
80/tcp open http
88/tcp open kerberos-sec
548/tcp open afp
631/tcp open ipp
3306/tcp open mysql
3325/tcp open unknown
5900/tcp open vnc
9000/tcp open cslistener
10000/tcp open snet-sensor-mgmt

For more detailed information, try netstat:

netstat -an

You’ll get a breakdown of every socket open on your machine – useful for figuring out who’s connected and from where.

The OSX














  [Read more...]
A handy regular expression for 'tokenizing' a SQL statement
+5 Vote Up -0Vote Down
Often times I find myself having to handle a particular portion of a SQL statement via a script. I've written a lot of specialized regular expressions over time to handle these tasks, but the one that I've had to write the most is a basic 'tokenizer' which understands the quoting semantics of a MySQL statement. That is, it understands `BackTick`, 'Single Quote' and "Double Quoted" strings.

#PHP Heredoc syntax
$regex = <<< END_OF_REGEX
/
  [^ \"'`(),]*\([^)]*\)    #match functions like concat(x,"y",`a`.`z`) or sum(`xyz`);
  |\([^)]*?\)              #match grouped items
  |"[^"]*?"                #match double quoted items
  |'[^']*?'                #match single quoted items
  |`[A-Za-z0-9_ .'\"()+\\-&^%\$+?%\\/\\\\!`]+`  #match backtick mysql names
  |[^ ,]+                  #match keywords, operators and aliases
  |,
/xi
END_OF_REGEX;


EDIT: After some



  [Read more...]
MySQL and Postgres command equivalents (mysql vs psql)
+0 Vote Up -0Vote Down

Users toggling between MySQL and Postgres are often confused by the equivalent commands to accomplish basic tasks. Here's a chart listing some of the differences between the command line client for MySQL (simply called mysql), and the command line client for Postgres (called psql).

MySQL (using mysql)Postgres (using psql)Notes \c Clears the buffer\r (same) \d string Changes the delimiterNo equivalent \e Edit the buffer with external editor\e (same)Postgres also allows \e filename which will become the new buffer \g Send current query to the server\g (same) \h Gives help - general or specific\h (same) \n Turns the pager off\pset pager off (same)The pager is only used when needed based on number of rows; to force it on, use  [Read more...]
Effect of adaptive_flushing
+1 Vote Up -0Vote Down

I recently had the chance to witness the effects of innodb_adaptive_flushing on the performance of InnoDB Plugin 1.0.5 in the wild, which Yasufumi wrote about previously here and here.

The server in question was Solaris 10 with 8 disk RAID10 and 2 32GB SSDs used for ZIL and L2ARC, 72G RAM and 40G buffer pool. We started it up with innodb_adaptive_flushing=OFF and innodb_doublewrite=OFF, then ramped up traffic and everything looked stable ... but I noticed one troubling thing: ~2GB of uncheckpointed data.

mysql> SHOW INNODB STATUS\G
....
Database pages      2318457
Old database pages  855816
Modified db pages   457902
Log flushed up to   10026890404067
Last checkpoint at
  [Read more...]
“Shard early, shard often”
+1 Vote Up -0Vote Down

I wrote a post a while back that said why you don't want to shard.  In that post that I tried to explain that hardware advances such as 128G of RAM being so cheap is changing the point at which you need to shard, and that the (often omitted) operational issues created by sharding can be painful.

What I didn't mention was that if you've established that you will need to eventually shard, is it better to just get it out of the way early?  My answer is almost always no. That is to say I disagree with a statement I've been hearing recently; "shard early, shard often".  Here's why:

  • There's an order of magnitude better performance that can be gained by focusing on query/index/schema optimization.  The gains from sharding are usually much
  [Read more...]
Tokyo Tyrant -The Extras Part III : Write Bottleneck
+1 Vote Up -0Vote Down

This is part 3 of my Tyrant extra's, part 1 focused on durability, part 2 focused on the perceived performance wall.

#3.  Tokyo Cabinet Can have only a single writer thread, bottlenecking performance

When writing an application using Tokyo Cabinet only one connection can be opened as a “writer”  while the rest are readers.  Tyrant allows for multiple “writes”  to be sent in from multiple applications but it still single threads them when writing out to disk.   If you run several threads all just inserting into Tyrant your will see tyrant hit 100% Cpu on 1 core, and your writes will start to peter out quickly.

In my tests when I was not disk bound (FS Cache writes) I was able to complete 4Million

  [Read more...]
Tokyo Tyrant – The Extras Part II : The Performance Wall
+1 Vote Up -0Vote Down

Continuing my look at Tokyo Tyrant/Cabinet and addressing some of the concerns I have seen people have brought up this is post #2.

#2.  As your data grows does  Tokyo Cabinet slow down?

Yes your performance can degrade. One obvious performance decrease with a larger dataset  is you start to increase the likelihood that your data no longer fits into memory.  This decreases the number of memory operations and trades them for more expensive disk based operations.    As fast as any application is, as you read off disk opposed to memory performance is going to drop off substantially.  One of the more difficult things to test with Tyrant is disk bound performance.  The FS Cache can make Tyrant seem like small amounts of memory will still make it scream.  Once your data set is larger then that, people start to claim they hit the

  [Read more...]
MySQL-Memcached or NOSQL Tokyo Tyrant – part 3
+4 Vote Up -1Vote Down

This is part 3 of our series.  In part 1 we talked about boosting performance with memcached on top of MySQL, in Part 2 we talked about running 100% outside the data with memcached, and now in Part 3 we are going to look at a possible solution to free you from the database.  The solution I am going to discuss here is Tokyo Cabinet and Tyrant.

I am not going to give you a primer  or Tutorial on Tyrant and Cabinet, there are plenty of these out there already.  Instead I want to see what sort of performance we can see compared to MySQL and Memcached, and later on other NoSQL solutions.  Tokyo actually allows you to use several types of databases that are supported,

  [Read more...]
How (not) to find unused indexes
+2 Vote Up -0Vote Down

I've seen a few people link to an INFORMATION_SCHEMA query to be able to find any indexes that have low cardinality, in an effort to find out what indexes should be removed.  This method is flawed - here's the first reason why:

PLAIN TEXT SQL:
  • CREATE TABLE `sales` (
  • `id` int(11) NOT NULL AUTO_INCREMENT,
  • `customer_id` int(11) DEFAULT NULL,
  • `status` enum('archived','active') DEFAULT NULL,
  • PRIMARY KEY (`id`),
  • KEY `status` (`status`)
  • ) ENGINE=MyISAM AUTO_INCREMENT=65691 DEFAULT CHARSET=latin1;
  •  
  • mysql&gt; SELECT count(*), STATUS FROM sales GROUP BY STATUS;
  • +----------+---------+
  • | count(*) | STATUS  |
  •   [Read more...]
    MySQL-Memcached or NOSQL Tokyo Tyrant – part 2
    +1 Vote Up -0Vote Down

    Part 1 of our series set-up our "test"  application and looked at boosting performance of the application by buffer MySQL with memcached.  Our test application is simple and requires only 3 basic operations per transaction 2 reads and 1 write.  Using memcached combined with MySQL we ended up nearly getting a 10X performance boost from the application.  Now we are going to look at what we could achieve if we did not have to write to the database at all.  So let's look at what happens if we push everything including writes into memcached.

    Wow that's shockingly fast isn't it! I guess being completely in memory helps for this app.  What is

      [Read more...]
    MySQL-Memcached or NOSQL Tokyo Tyrant – part 1
    +2 Vote Up -0Vote Down

    All to often people force themselves into using a database like MySQL with no thought into whether if its the best solution to there problem. Why?  Because their other applications use it, so why not the new application?  Over the past couple of months I have been doing a ton of work for clients who use their database like most people use memcached .  Lookup a row based on a key, update the data in the row, stuff the row back in the database.  Rinse and repeat.  Sure these setups vary sometimes, throwing in a “lookup” via username, or even the rare count.  But for the most part they are designed to be simple.

    A classic example is a simple online game.  An online game may only require that an application retrieve a single record from the database.  The record may contain all the vital stats for the game, be updated and stuffed back into

      [Read more...]
    Free and easy schema diff and patch
    +6 Vote Up -2Vote Down

    The easiest way to see the differences between two schemas on a non-Windows machine is to run:

    mysqldump -h server1 --no-data --all-databases > file1.sql
    mysqldump -h server2 --no-data --all-databases > file2.sql
    diff file1.sql file2.sql

    However, this will show also trivial differences, such as the value of AUTO_INCREMENT. It also does not give you a way to patch one schema to be like another.

    We frequently are asked to “do a schema diff and create a script that will ‘patch’ one server.” Usually this is done to take a development or test schema and move it to production for a release.

    We like to use the best tool for the job, and while diff is good, I like to use MySQL workbench. The OSS (Community) edition provides



      [Read more...]
    How to generate per-database traffic statistics using mk-query-digest
    +7 Vote Up -0Vote Down

    We often encounter customers who have partitioned their applications among a number of databases within the same instance of MySQL (think application service providers who have a separate database per customer organization ... or wordpress-mu type of apps). For example, take the following single MySQL instance with multiple (identical) databases:

    SHOW DATABASES;
    +----------+
    | Database |
    +----------+
    | db1      |
    | db2      |
    | db3      |
    | db4      |
    | mysql    |
    +----------+
    

    Separating the data in this manner is a great setup for being able to scale by simply migrating a subset of the databases to a different physical host when the existing host begins to get overloaded. But MySQL doesn't allow us to examine statistics on a per-database basis.

    Enter Maatkit.

    There is an often-ignored gem in

      [Read more...]
    Which adaptive should we use?
    +3 Vote Up -3Vote Down

    As you may know, InnoDB has 2 limits for unflushed modified blocks in the buffer pool. The one is from physical size of the buffer pool. And the another one is oldness of the block which is from the capacity of transaction log files.

    In the case of heavy updating workload, the modified ages of the many blocks are clustered. And to reduce the maximum of the modified ages InnoDB needs to flush many of the blocks in a short time, if these are not flushed at all. Then the flushing storm affect the performance seriously.

    We suggested the "adaptive_checkpoint" option of constant flushing to avoid such a flushing storm. And finally, the newest InnoDB Plugin 1.0.4 has the new similar option "adaptive_flushing" as native.

    Let's check the adaptive flushing options at this post.

    HOW THEY WORK

    <

      [Read more...]
    3 ways MySQL uses indexes
    +5 Vote Up -0Vote Down

    I often see people confuse different ways MySQL can use indexing, getting wrong ideas on what query performance they should expect. There are 3 main ways how MySQL can use the indexes for query execution, which are not mutually exclusive, in fact some queries will use indexes for all 3 purposes listed here.

    Using index to find rows The main purpose of the index is to find rows quickly - without scanning whole data set. This is most typical reason index gets added on the first place. Most popular index type in MySQL - BTREE can speed up equality and prefix range matches. So if you have index on (A,B) This index can be used to lookup rows for WHERE clauses like A=5 ; A BETWEEN 5 AND 10 ; A=5 AND B BETWEEN 5 AND 10 it however will NOT be able to help

      [Read more...]
    XtraDB: The Top 10 enhancements
    +4 Vote Up -1Vote Down

    Note: This post is part 2 of 4 on building our training workshop.

    Last week I talked about why you don't want to shard. This week I'm following up with the top 10 enhancements that XtraDB has over the built-in InnoDB included in MySQL 5.0 and 5.1.  Building this list was not really a scientific process - It's always difficult to say which feature is better than another, because a lot of it depends on the individual workload.  My ranking method was to pick the features that have the highest impact and are most applicable to all workloads first:

  • CPU scalability fixes - XtraDB improves performance on systems with

  •   [Read more...]
    Why you don’t want to shard.
    +6 Vote Up -1Vote Down

    Note: This blog post is part 1 of 4 on building our training workshop.

    The Percona training workshop will not cover sharding. If you follow our blog, you'll notice we don't talk much about the subject; in some cases it makes sense, but in many we've seen that it causes architectures to be prematurely complicated.

    So let me state it: You don't want to shard.

    Optimize everything else first, and then if performance still isn't good enough, it's time to take a very bitter medicine. The reason you need to shard basically

      [Read more...]
    Copying InnoDB tables between servers
    +2 Vote Up -0Vote Down

    The feature I announced some time ago http://www.mysqlperformanceblog.com/2009/06/08/impossible-possible-moving-innodb-tables-between-servers/ is now available in our latest releases of XtraBackup 0.8.1 and XtraDB-6.

    Now I am going to show how to use it (the video will be also available on percona.tv).
    Let's take tpcc schema and running standard MySQL ® 5.0.83, and assume we want to copy order_line table to different server. Note I am going to do it online, no needs to lock or shutdown server.

    To export table you need


      [Read more...]
    Recovery after DROP [ TABLE | DATABASE ]
    +2 Vote Up -0Vote Down

    In your recovery practice we often face the problem when data lost by execution DROP TABLE or DROP DATABASE statement. In this case even our InnoDB Data Recovery tool can't help, as table / directory with files was deleted (if you have innodb-file-per-table). And the same for MyISAM, all .MYD / .MYI / .frm - files are deleted in this case.

    So first step after DROP is to restore files, and for ext3 file system there are two utilities which can help of you are fast (and lucky) enough.
    First one is ext3grep http://code.google.com/p/ext3grep/, with some instruction on this page http://www.xs4all.nl/~carlo17/howto/undelete_ext3.html.
    And also there is

      [Read more...]
    Is DRBD the right choice for me?
    +3 Vote Up -0Vote Down

    It seems pretty common to find customers install DRBD for the wrong reasons. There are many pros/cons to compare DRBD to replication, but I've managed to cut down my spiel I give to customers to these two points:

    • DRBD's aim (assuming replication mode C) is to provide 100% consistency, and then as much uptime as possible.
    • MySQL Replication (with a manager such as MMM) aims to have 100% availability, at the potential loss of some data surrounding a failure.

    So if you are installing DRBD with the aim of purely "availability", and are not worried about losing that last write on the crash to your master database that (hopefully) happens only once every few years, you may be using the wrong technology.

    While the prized "1 minute failover" is possible in DRBD, it doesn't

      [Read more...]
    Just do the math!
    +2 Vote Up -0Vote Down

    One of the most typical reasons for performance and scalability problems I encounter is simply failing to do the math. And these are typically bad one because it often leads to implementing architectures which are not up for job they are intended to solve.

    Let me start with example to make it clear. Lets say you're doing some reports from your apache log files - how many distinct visitors hit the page and stuff like that. You picked full logs because they are great in flexibility - you can run any adhoc queries and drill down as much as you like. Initially traffic was small and young and with 10000 page views a day you few days of history the queries there instant which gave you a confidence this approach will work.

    As the time passes and you get 1.000.000 events per day and looking to do reporting for up to the whole year worth of data you find things not

      [Read more...]
    Replace or Rename: that is the question.
    +0 Vote Up -1Vote Down

    Forget tedious hours of searching links to the renamed object and replacing them.

    To save your efforts, dbForge Studio for MySQL automates renaming of tables, columns of tables, views, aliases, stored routines, local variables, triggers, events, UDFs, and users and even offers a convenient preview of the changes before applying them.

    To rename an object in the script, right-click it and select the Rename option from the menu. The Rename dialog box opens where you can enter a new name and view all references to the renamed object in the expressions, strings, and even comments.

    All you have to do is to select required references and press

      [Read more...]
    How to pretty-print my.cnf with a one-liner
    +2 Vote Up -0Vote Down

    When I'm looking at a server, I often want to see the /etc/my.cnf file nicely formatted, and with comments stripped. This Perl one-liner will pretty-print the file:

    PLAIN TEXT CODE:
  • perl -ne 'm/^([^#][^\s=]+)\s*(=.*|)/ && printf("%-35s%s\n", $1, $2)' /etc/my.cnf
  • [client]                           
  • port                               = 3306
  • socket                             = /var/run/mysqld/mysqld.sock
  • [mysqld_safe]       
  •   [Read more...]
    The feature I love in TokuDB
    +3 Vote Up -0Vote Down

    Playing with TokuDB updates I noticed in SHOW PROCESSLIST unsual for MySQL State.

    PLAIN TEXT CODE:
  • mysql> show processlist;
  • +----+------+-----------+--------+---------+------+---------------------------+-----------------------------+
  • | Id | User | Host      | db     | Command | Time | State                     | Info                        |
  • +----+------+-----------+--------+---------+------+---------------------------+-----------------------------+
  • |  3 | root | localhost | sbtest | Query   |   30 | Updated about 764000 rows | update sbtest set email=zip |
  •   [Read more...]
    webinar on Data Reduction and Smoothing in MySQL
    Employee +0 Vote Up -0Vote Down

    If you have missed Michael McFadden's session at the last MySQL Conference, here's a chance to catch up.

    On June 11, at 17:00 UTC Michael McFadden will present at a free webinar, on the subject of Faster Data Reduction and Smoothing for Analysis & Archival in MySQL (http://www.mysql.com/news-and-events/web-seminars/display-361.html).

    Don't let the "For ISVs" distract you. This session is a collection of very practical and down to earth tips for tasks that can be in the TODO list of any DBA.

    In addition to being practical, Michael's advice is justified by rigorous statistical analysis, and the tips he provides

      [Read more...]
    webinar on Data Reduction and Smoothing in MySQL
    Employee +0 Vote Up -0Vote Down

    If you have missed Michael McFadden's session at the last MySQL Conference, here's a chance to catch up.

    On June 11, at 17:00 UTC Michael McFadden will present at a free webinar, on the subject of Faster Data Reduction and Smoothing for Analysis & Archival in MySQL (http://www.mysql.com/news-and-events/web-seminars/display-361.html).

    Don't let the "For ISVs" distract you. This session is a collection of very practical and down to earth tips for tasks that can be in the TODO list of any DBA.

    In addition to being practical, Michael's advice is justified by rigorous statistical analysis, and the tips he

      [Read more...]
    webinar on Data Reduction and Smoothing in MySQL
    Employee +0 Vote Up -0Vote Down

    If you have missed Michael McFadden's session at the last MySQL Conference, here's a chance to catch up.

    On June 11, at 17:00 UTC Michael McFadden will present at a free webinar, on the subject of Faster Data Reduction and Smoothing for Analysis & Archival in MySQL (http://www.mysql.com/news-and-events/web-seminars/display-361.html).

    Don't let the "For ISVs" distract you. This session is a collection of very practical and down to earth tips for tasks that can be in the TODO list of any DBA.

    In addition to being practical, Michael's advice is justified by rigorous statistical analysis, and the tips he

      [Read more...]
    A rule of thumb for choosing column order in indexes
    +1 Vote Up -0Vote Down

    I wanted to share a little rule of thumb I sometimes use to decide which columns should come first in an index. This is not specific to MySQL, it's generally applicable to any database server with b-tree indexes. And there are a bunch of subtleties, but I will also ignore those for the sake of simplicity.

    Let's start with this query, which returns zero rows but does a full table scan. EXPLAIN says there are no possible_keys.

    PLAIN TEXT SQL:
  • SELECT * FROM tbl WHERE STATUS='waiting' AND source='twitter'
  •  AND no_send_before <= '2009-05-28 03:17:50' AND tries <= 20
  •  ORDER BY date ASC LIMIT 1;
  • Don't try to figure out the meaning of the query, because that'll

      [Read more...]
    Using netcat to copy MySQL Database
    +2 Vote Up -0Vote Down

    This is mainly a cheat sheet for me to remember. Nothing rocket science.

    It often makes sense to use netcat/nc to copy MySQL database between hosts in trusted networks. It bypasses encryption overhead of SSH and depending on configuration can be significantly faster.

    Also note MySQL should be down when you copy data unless you're copying from snapshot etc.

    So to copy go to the mysql data directory on both boxes; such as cd /var/lib/mysql . Make sure target directory is empty. Now on the TARGET server do nc -l 4000 | tar xvf - and on the SOURCE server do tar -cf - . | nc target_ip 4000

    Also note - the port you're using should be open in the firewall.


    Entry posted by peter |

      [Read more...]
    Designing Views With Query Builder
    +0 Vote Up -0Vote Down

    If you often need to create and modify views in your MySQL development you will like dbForge Studio for MySQL in-place query editing feature. This feature allows integration of powerful Query Builder tool with view editor without annoying copy/paste.

    Suppose you have previously created view with some SELECT statement. To view and design this statement with Query Builder you need to perform these steps:

  • Open view editor.
  • Right-click on SELECT statement.
  • In pop-up menu select ‘Design SQL…’ command.
  • In opened Query Builder re-design you SELECT statement (See picture below).
  • After you click OK new statement automatically gets pasted into the view  editor.
  • If you need to design new SELECT statement when you are creating view use

      [Read more...]
    Previous 30 Newer Entries Showing entries 61 to 90 of 90

    Planet MySQL © 1995, 2013, Oracle Corporation and/or its affiliates   Legal Policies | Your Privacy Rights | Terms of Use

    Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.