Manage your Blog

Create your blog now! Easy and Free

Ubuntuland

Get Paid to Blog About the Things You Love

Category: Databases

08/05/2008 GMT 1

Basic MySQL User Utility Commands

ubuntuland @ 07:45

Basic MySQL User Utility Commands

SE Syntax
USE db_name
The USE db_name statement tells MySQL to use the db_name database as the default
database for subsequent queries. The database remains current until the end of the session or until another USE statement is issued:
mysql> USE db1;
mysql> SELECT count(*) FROM mytable; # selects from db1.mytable
mysql> USE db2;
mysql> SELECT count(*) FROM mytable; # selects from db2.mytable
Making a particular database current by means of the USE statement does not preclude you from accessing tables in other databases. The example below accesses the author table from the db1 database and the editor table from the db2 database:
mysql> USE db1;
mysql> SELECT author_name,editor_name FROM author,db2.editor
WHERE author.editor_id = db2.editor.editor_id;
The USE statement is provided for Sybase compatibility.

WordLinx - Get Paid To Click

DESCRIBE Syntax
{DESCRIBE | DESC} tbl_name {col_name | wild}
DESCRIBE is a shortcut for SHOW COLUMNS FROM.
DESCRIBE provides information about a table’s columns. col_name may be a column name or a string containing the SQL ‘%’ and ‘_’ wild-card characters.
If the column types are di erent than you expect them to be based on a CREATE TABLE statement, note that MySQL sometimes changes column types.
This statement is provided for Oracle compatibility.
The SHOW statement provides similar information.
MySQL Transactional and Locking Commands
BEGIN/COMMIT/ROLLBACK Syntax
By default, MySQL runs in autocommit mode. This means that as soon as you execute an update, MySQL will store the update on disk.
If you are using transactions safe tables (like InnoDB, BDB, you can put MySQL into non- autocommit mode with the following command:
SET AUTOCOMMIT=0

fiat500_468x60.gif

After this you must use COMMIT to store your changes to disk or ROLLBACK if you want to ignore the changes you have made since the beginning of your transaction.
If you want to switch from AUTOCOMMIT mode for one series of statements, you can use the BEGIN or BEGIN WORK statement:
BEGIN;
SELECT @A:=SUM(salary) FROM table1 WHERE type=1;
UPDATE table2 SET summmary=@A WHERE type=1;
COMMIT;
Note that if you are using non-transaction-safe tables, the changes will be stored at once, independent of the status of the autocommit mode.
If you do a ROLLBACK when you have updated a non-transactional table you will get an error (ER_WARNING_NOT_COMPLETE_ROLLBACK) as a warning. All transactional safe tables will be
restored but any non-transactional table will not change.
If you are using BEGIN or SET AUTOCOMMIT=0, you should use the MySQL binary log for backups instead of the older update log. Transactions are stored in the binary log in one chunk, upon COMMIT, to ensure that transactions which are rolled back are not stored.
The following commands automatically end a transaction (as if you had done a COMMIT
before executing the command):
ALTER TABLE BEGIN
CREATE INDEX
DROP DATABASE DROP TABLE RENAME TABLE
TRUNCATE



banner 12


LOCK TABLES/UNLOCK TABLES Syntax
LOCK TABLES tbl_name [AS alias] {READ | [READ LOCAL] | [LOW_PRIORITY] WRITE}
[, tbl_name {READ | [LOW_PRIORITY] WRITE} ...]
...
UNLOCK TABLES
LOCK TABLES locks tables for the current thread. UNLOCK TABLES releases any locks held by the current thread. All tables that are locked by the current thread are automatically unlocked when the thread issues another LOCK TABLES, or when the connection to the server is closed.
The main reasons to use LOCK TABLES are for emulating transactions or getting more speed when updating tables. This is explained in more detail later.
If a thread obtains a READ lock on a table, that thread (and all other threads) can only read from the table. If a thread obtains a WRITE lock on a table, then only the thread holding the lock can READ from or WRITE to the table. Other threads are blocked.
The di erence between READ LOCAL and READ is that READ LOCAL allows non-con icting INSERT statements to execute while the lock is held. This can’t however be used if you are going to manipulate the database files outside MySQL while you hold the lock.
When you use LOCK TABLES, you must lock all tables that you are going to use and you must use the same alias that you are going to use in your queries! If you are using a table multiple times in a query (with liases), you must get a lock for each alias!
WRITE locks normally have higher priority than READ locks, to ensure that updates are processed as soon as possible. This means that if one thread obtains a READ lock and then another thread requests a WRITE lock, subsequent READ lock requests will wait until the WRITE thread has gotten the lock and released it. You can use LOW_PRIORITY WRITE locks to allow other threads to obtain READ locks while the thread is waiting for the WRITE lock.
You should only use LOW_PRIORITY WRITE locks if you are sure that there will eventually be a time when no threads will have a READ lock.
LOCK TABLES works as follows:
1. Sort all tables to be locked in a internally defined order (from the user standpoint the order is undefined).
2. If a table is locked with a read and a write lock, put the write lock before the read lock.
3. Lock one table at a time until the thread gets all locks.


Get Paid for Your Opinion


If you are using a LOW_PRIORITY_WRITE lock for a table, this means only that MySQL will wait for this particlar lock until there is no threads that wants a READ lock. When the thread has got the WRITE lock and is waiting to get the lock for the next table in the lock table list, all other threads will wait for the WRITE lock to be released. If this becomes a serious problem with your application, you should consider converting some of your tables to transactions safe tables.
Note that you should not lock any tables that you are using with INSERT DELAYED. This is because that in this case the INSERT is done by a separate thread.
Normally, you don’t have to lock tables, as all single UPDATE statements are atomic; no other thread can interfere with any other currently executing SQL statement. There are a
few cases when you would like to lock tables anyway:
• If you are going to run many operations on a bunch of tables, it’s much faster to lock the tables you are going to use. The downside is, of course, that no other thread can update a READ-locked table and no other thread can read a WRITE-locked table.
The reason some things are faster under LOCK TABLES is that MySQL will not ush the key cache for the locked tables until UNLOCK TABLES is called (normally the key cache is ushed after each SQL statement). This speeds up inserting/updateing/deletes on MyISAM tables.
• If you are using a table handler in MySQL that doesn’t support transactions, you must use LOCK TABLES if you want to ensure that no other thread comes between a SELECT and an UPDATE. The example shown below requires LOCK TABLES in order to execute safely:
mysql> LOCK TABLES trans READ, customer WRITE;
mysql> select sum(value) from trans where customer_id= some_id;
mysql> update customer set total_value=sum_from_previous_statement where customer_id=some_id;
mysql> UNLOCK TABLES;
Without LOCK TABLES, there is a chance that another thread might insert a new row in the trans table between execution of the SELECT and UPDATE statements.
By using incremental updates (UPDATE customer SET value=value+new_value) or the LAST_INSERT_ID() function, you can avoid using LOCK TABLES in many cases.
You can also solve some cases by using the user-level lock functions GET_LOCK() and RELEASE_LOCK(). These locks are saved in a hash table in the server and implemented with pthread_mutex_lock() and pthread_mutex_unlock() for high speed.
NOTE: LOCK TABLES is not transaction-safe and will automatically commit any active trans-
actions before attempting to lock the tables.


no one deals like we do!


SET TRANSACTION Syntax
SET [GLOBAL | SESSION] TRANSACTION ISOLATION LEVEL
[READ UNCOMMITTED |READ COMMITTED | REPEATABLE READ | SERIALIZABLE]
Sets the transaction isolation level for the global, whole session or the next transaction.
The default behavior is to set the isolation level for the next (not started) transaction.
If you set the GLOBAL privilege it will a ect all new created threads. You will need the PROCESS privilege to do do this.
Setting the SESSION privilege will a ect the following and all future transactions.
You can set the default isolation level for mysqld with --transaction-isolation=....

Since Version 3.23.23, MySQL has support for full-text indexing and searching. Full-text indexes in MySQL are an index of type FULLTEXT. FULLTEXT indexes can be created from VARCHAR and TEXT columns at CREATE TABLE time or added later with ALTER TABLE or CREATE INDEX. For large datasets, adding FULLTEXT index with ALTER TABLE (or CREATE INDEX) would be much faster than inserting rows into the empty table with a FULLTEXT index.
Full-text search is performed with the MATCH function.
mysql> CREATE TABLE articles (
-> id INT UNSIGNED AUTO_INCREMENT NOT NULL PRIMARY KEY,
-> title VARCHAR(200),
-> body TEXT,
-> FULLTEXT (title,body)
-> );
Query OK, 0 rows affected (0.00 sec)
mysql> INSERT INTO articles VALUES
-> (0,’MySQL Tutorial’, ’DBMS stands for DataBase Management ...’),
-> (0,’How To Use MySQL Efficiently’, ’After you went through a ...’),
-> (0,’Optimising MySQL’,’In this tutorial we will show how to ...’),
-> (0,’1001 MySQL Trick’,’1. Never run mysqld as root. 2. Normalise ...’),
-> (0,’MySQL vs. YourSQL’, ’In the following database comparison we ...’),
-> (0,’MySQL Security’, ’When configured properly, MySQL could be ...’);
Query OK, 5 rows affected (0.00 sec)
Records: 5 Duplicates: 0 Warnings: 0
mysql> SELECT * FROM articles WHERE MATCH (title,body) AGAINST (’database’);
+----+-------------------+---------------------------------------------+
| id | title | body
|
+----+-------------------+---------------------------------------------+
| 5 | MySQL vs. YourSQL | In the following database comparison we ... |


var bdv_ref_pid=83713;var bdv_ref_type='i';var bdv_ref_option='p';var bdv_ref_eb='0';var bdv_ref_gif_id='ref_468x60_yellow_pbl';var bdv_ref_width=468;var bdv_ref_height=60;

make money

MySQL Technical Reference for Version 4.0.1-alpha
| 1 | MySQL Tutorial | DBMS stands for DataBase Management ... |
+----+-------------------+---------------------------------------------+
2 rows in set (0.00 sec)
The function MATCH matches a natural language query AGAINST a text collection (which is simply the set of columns covered by a FULLTEXT index). For every row in a table it returns relevance - a similarity measure between the text in that row (in the columns that are part of the collection) and the query. When it is used in a WHERE clause (see example above) the rows returned are automatically sorted with relevance decreasing. Relevance
is a non-negative oating-point number. Zero relevance means no similarity. Relevance is computed based on the number of words in the row, the number of unique words in that row, the total number of words in the collection, and the number of documents (rows) that contain a particular word.
The above is a basic example of using MATCH function. Rows are returned with relevance decreasing.
mysql> SELECT id,MATCH (title,body) AGAINST (’Tutorial’) FROM articles;
+----+-----------------------------------------+
| id | MATCH (title,body) AGAINST (’Tutorial’) |
+----+-----------------------------------------+
| 1 |
0.64840710366884 |
| 2 |
0 |
| 3 |
0.66266459031789 |
| 4 |
0 |
| 5 |
0 |
| 6 |
0 |
+----+-----------------------------------------+
5 rows in set (0.00 sec)
This example shows how to retrieve the relevances. As neither WHERE nor ORDER BY clauses are present, returned rows are not ordered.
mysql> SELECT id, body, MATCH (title,body) AGAINST (
-> ’Security implications of running MySQL as root’) AS score
-> FROM articles WHERE MATCH (title,body) AGAINST
-> (’Security implications of running MySQL as root’);
+----+-----------------------------------------------+-----------------+
| id | body
| score |
+----+-----------------------------------------------+-----------------+
| 4 | 1. Never run mysqld as root. 2. Normalise ... | 1.5055546709332 |
| 6 | When configured properly, MySQL could be ... | 1.31140957288 |
+----+-----------------------------------------------+-----------------+
2 rows in set (0.00 sec)
This is more complex example - the query returns the relevance and still sorts the rows with relevance decreasing. To achieve it one should specify MATCH twice. Note, that this will cause no additional overhead, as MySQL optimiser will notice that these two MATCH calls are identical and will call full-text search code only once.
MySQL uses a very simple parser to split text into words. A “word” is any sequence of letters, numbers, ‘’’, and ‘_’. Any “word” that is present in the stopword list or just too short (3 characters or less) is ignored.

MySQL Language Reference

Every correct word in the collection and in the query is weighted, according to its significance in the query or collection. This way, a word that is present in many documents will have lower weight (and may even have a zero weight), because it has lower semantic value in this particular collection. Otherwise, if the word is rare, it will receive a higher weight. The weights of the words are then combined to compute the relevance of the row.
Such a technique works best with large collections (in fact, it was carefully tuned this way).
For very small tables, word distribution does not re ect adequately their semantical value, and this model may sometimes produce bisarre results.
mysql> SELECT * FROM articles WHERE MATCH (title,body) AGAINST (’MySQL’);
Empty set (0.00 sec)
Search for the word MySQL produces no results in the above example. Word MySQL is present in more than half of rows, and as such, is e ectively treated as a stopword (that is, with semantical value zero). It is, really, the desired behavior - a natural language query should not return every second row in 1GB table.
A word that matches half of rows in a table is less likely to locate relevant documents.
In fact, it will most likely find plenty of irrelevant documents. We all know this happens far too often when we are trying to find something on the Internet with a search engine.
It is with this reasoning that such rows have been assigned a low semantical value in this particular dataset.
Fulltext restrictions
• All parameters to the MATCH function must be columns from the same table that is part of the same fulltext index.
• The argument to AGAINST must be a constant string.
6.8.2 Fine-tuning MySQL Full-text Search
Unfortunately, full-text search has few user-tunable parameters yet, although adding some is very high on the TODO. If you have a MySQL source distribution you can more control on the MySQL sources unless you know what you are doing!
• Minimal length of word to be indexed is defined by MySQL variable ft_min_word_ length. Change it to the value you prefer, and rebuild your FULLTEXT indexes.
• The stopword list is defined in myisam/ft_static.c Modify it to your taste, recompile
MySQL and rebuild your FULLTEXT indexes.
• The 50% threshold is caused by the particular weighting scheme chosen. To disable it, change the following line in myisam/ftdefs.h:
#define GWS_IN_USE GWS_PROB to
#define GWS_IN_USE GWS_FREQ
and recompile MySQL.
This section includes a list of the fulltext features that are already implemented in the 4.0 tree.
• REPAIR TABLE with FULLTEXT indexes, ALTER TABLE with FULLTEXT indexes, and OPTIMIZE TABLE with FULLTEXT indexes are now up to 100 times faster.
• MATCH ... AGAINST is going to supports the following boolean operators:
• +word means the that word must be present in every row returned.
• -word means the that word must not be present in every row returned.
• < and > can be used to decrease and increase word weight in the query.
• ~ can be used to assign a negative weight to a noise word.
• * is a truncation operator.
Boolean search utilises a more simplistic way of calculating the relevance, that does not have a 50% threshold.
• Make all operations with FULLTEXT index faster.
• Phrase search, proximity operators
• Boolean search can work without FULLTEXT index (yes, very slow).
• Support for "always-index words". They could be any strings the user wants to treat
as words, examples are "C++", "AS/400", "TCP/IP", etc.
• Support for full-text search in MERGE tables.
• Support for multi-byte charsets.
• Make stopword list to depend of the language of the data.
• Stemming (dependent of the language of the data, of course).
• Generic user-supplyable UDF (?) preparser.
• Make the model more exible (by adding some adjustable parameters to FULLTEXT in CREATE/ALTER TABLE).


Unusual Gifts ideas

 

Latest Posts

 

Linux Links

 

Toys! Free 			shipping on Toys!

Free 			Shipping!

 

29/02/2008 GMT 1

Firebird 2.0.3 included in Ubuntu 8.04 Hardy Heron

ubuntuland @ 15:38

Firebird (sometimes erroneously called FirebirdSQL) is a relational database management system offering many ANSI SQL-2003 features.

It runs on Linux, Windows, and a variety of Unix platforms. Started as a fork of Borland's open source release of InterBase, the Firebird codebase is maintained by the Firebird Project at SourceForge.

New code modules added to Firebird are licensed under the Initial Developer's Public License (IDPL). The original code released by Inprise (as Borland was then called) is licensed under the InterBase Public License 1.0. Both licenses are modified versions of the Mozilla Public License 1.1.

History

Firebird 1.0 was essentially a bug-fixed version of the InterBase 6.0 open source edition with some minor new features. Development on the Firebird 2 codebase began with the porting of the Firebird 1.0 C code to C++, together with a major code-cleaning undertaking. Firebird 1.5 was the first release of the Firebird 2 codebase and as such a significant milestone for the developers and the whole project.

* Firebird 2.0 was released in 2006. The latest stable version is 2.0.3 which was released in September 2007.

* Firebird 2.1 went into beta testing in mid-2007 and is likely to be released soon.

* Firebird 3.0 will merge code from several codebases, including Firebird 2.1, Vulcan, and Fyracle. The schedule at [1] indicates an Alpha version for release in Q4 2008.

Around the 20th birthday of the InterBase/Firebird product line, original creator Jim Starkey recollected:

"September 4, 2004 is the 20th anniversary of what is now Firebird. I quit my job at DEC in August, took a three day end-of-summer holiday, and began work on September 4, 1984 in my new career as a software entrepreneur. As best as I can reconstruct, the first two files were cpre.c and cpre.h (C preprocessor), later changed to gpre.c and gpre.h. The files were created on a loaner DEC Pro/350, a PDP-11 personal computer that went exactly nowhere, running XENIX. Gpre was my first C program, XENIX was my first experience with Unix, and the Pro/350 was my very last (but not lamented) experience with PDP-11s."

More information on Firebird's history can be found on the InterBase/Firebird History pages.

Features

* Full support of Stored Procedures and Triggers
* Full ACID compliant transactions
* Referential Integrity
* Multi Generational Architecture (sometimes called MVCC)
* Very small footprint
* Fully featured internal language for Stored Procedures and Triggers (PSQL)
* Support for External Functions (UDFs)
* Little or no need for specialized DBAs
* Almost no configuration needed - just install and start using
* Big community and lots of places where you can get free and good support
* Optional single file embedded version - great to create CDROM catalogs, single user or evaluation versions of applications
* Dozens of third party tools, including GUI administrative tools, replication tools, etc.
* Careful writes - fast recovery, no need for transaction logs
* Many ways to access your database: native/API, dbExpress drivers, ODBC, OLEDB, .Net provider, JDBC native type 4 driver, Python module, PHP, Perl, etc.
* Native support for all major operating systems, including Windows, Linux, Solaris, MacOS.
* Incremental Backups
* 64bits builds available
* Full cursor implementation in PSQL

The new Alpha version of ubuntu named Hardy Heron includes firebird 2.0.3 stable.

The current sub-release is v.2.0.3.
More details about Firebird 2.0.x ...

Did you know that you can report bugs directly to the Project developers? There is a common-sense procedure to follow, so that your report is useful to us: we do ask that you read the article How to Report Bugs Effectively (available in several languages) before you proceed. Then, post your bug report to the firebird-support or the firebird-devel list and ask if you need to post it to Tracker.

Is there a feature you would like to request?

Maybe it is already in Firebird's development programme. You can check up at the Tracker site using the Find Issues search tool. You can even vote on it! And if there is a feature YOU want that nobody else has registered yet, write up a good description and add it as a Feature Request.

You will need to create an account in Tracker to report bugs, request features or vote.
It is simple! just go there and follow the sign-up instructions.

The complete Release Notes are available in PDF format.


Firebird Project Development News

February 2008 CURRENTLY TESTING


25-Feb-2008 Jaybird 2.1.3 Released

Jaybird 2.1.3 release fixes a bug related to character case issues affecting the DatabaseMetaData class.
21-Feb-2008 Firebird 2.0.3 Superserver Released for Solaris x86

Firebird V2.03 Superserver for Solaris 10 (Intel x86) has been added to the catalogue and is available for download, thanks to continued porting by Paul Beach and Alex Peshkov.
12-Feb-2008 64-bit V.2.1 RC1 Builds for MacOSX Intel

Firebird 2.1 RC1 builds for MacOSX 10.5 x86 are ready to download and test.
9-Feb-2008 Rebuilt Firebird 2.0.3 MacOSX Superserver Kits

New kits for the Superserver installations on both i386 and PPC can be downloaded now. No changes to the engine but an installer problem has been fixed.
30-Jan-2008 Rebuilt Firebird 2.0.3 Ports for MacOSX on PowerPC

The ports of Firebird 2.0.3 Superserver and Classic for MacOSX PPC have been rebuilt with some fixes. New builds for Classic and Superserver PPC are available via the Firebird 2.0.3 Downloads page.
23-Jan-2008 Firebird 2.1 Release Candidate Ready

The Firebird Project team is happy to announce that download kits for the first V.2.1 release candidate are now available - Windows and Linux 32-bit and 64-bit platforms now, MacOSX soon. You are invited to test it furiously and report your experiences (good or bad) back to the firebird-devel list.
As always, please be patient if the files you want haven't made it out to the mirrors at your first attempt.
23-Jan-2008 Roadmap 2008

Dmitry Yemanov introduces the new Roadmap for 2008.

Latest News Post
LinuxLinks
Social Bookmarking
Add to: Mr. Wong Add to: Webnews Add to: Icio Add to: Oneview Add to: Linkarena Add to: Favoriten Add to: Seekxl Add to: Kledy.de Add to: Social Bookmarking Tool Add to: BoniTrust Add to: Power Oldie Add to: Bookmarks.cc Add to: Favit Add to: Newskick Add to: Newsider Add to: Linksilo Add to: Readster Add to: Folkd Add to: Yigg Add to: Digg Add to: Del.icio.us Add to: Reddit Add to: Jumptags Add to: Upchuckr Add to: Simpy Add to: StumbleUpon Add to: Slashdot Add to: Netscape Add to: Furl Add to: Yahoo Add to: Spurl Add to: Google Add to: Blinklist Add to: Blogmarks Add to: Diigo Add to: Technorati Add to: Newsvine Add to: Blinkbits Add to: Ma.Gnolia Add to: Smarking Add to: Netvouz Information