MySQL vs Oracle: Documenting observations/nuggets as I dive into MySQL

Posted : May 19, 2004 at 12:08 pm [America/Los_Angeles]

No, I am not here to bash Oracle or MySQL or both. Sorry, biling is almost an art that few possess. I ain’t one of them.

So, here’s the deal. I have worked with Oracle’s flavor of SQL for most of my professional life so far. During this time, MySQL has gotten my attention more so during installation of open-source softwares (like Movable Type) than as my application’s RDBMS backend. It all changed yesterday as I literally had to dive into MySQL for my current project

Here are some of my observations/notes:

1. In Oracle, you use ‘SQLPlus’ if you want to run queries. In MySQL, it’s ‘mysql’. If you like using GUI-based tools to do your SQL, in Oracle, you may be using Quest’s TOAD, TOra or the many commercial products out there. In the case of MySQL, I tend to flip-flop between ‘mysql’ client, TOAD for MySQL or MySQL Control Center (MySQLCC).

2. In Oracle, there is a concept of “DUAL” table (it’s really not a table) which is used too often to do things like:

SQL> SELECT 1+1 FROM DUAL;
       1+1
----------
         2
SQL> SELECT SQRT(4) FROM DUAL;

   SQRT(4)
----------
         2
SQL>

In MySQL, you don’t need the “FROM DUAL”:

mysql> select 1+1 ;
+-----+
| 1+1 |
+-----+
|   2 |
+-----+
1 row in set (0.03 sec)
mysql> select sqrt(4);
+----------+
| sqrt(4)  |
+----------+
| 2.000000 |
+----------+
1 row in set (0.89 sec)
mysql>

3. In SQLPlus, there are a bunch of directives made available which makes it easy to spool, make SQL output look pretty, time queries, etc.

set timing on
set feed on
set echo on
set term on
set serveroutput on size 1000000
col mycurdt format A20

In MySQL, the SQL output is definitely much prettier by default which makes the life of an application developer that much simpler:

mysql> use mt;
Database changed
mysql> select * from ind_sites;
+---------+-------------+----------------------+---------------------+
| site_id | site_author | site_url             | site_created_on     |
+---------+-------------+----------------------+---------------------+
|       4 | Jivha       | http://www.jivha.com | 2004-05-18 21:55:29 |
+---------+-------------+----------------------+---------------------+
1 row in set (3.31 sec)
mysql>
mysql> select * from ind_sites G
*************************** 1. row ***************************
        site_id: 4
    site_author: Jivha
       site_url: http://www.jivha.com
site_created_on: 2004-05-18 21:55:29
1 row in set (0.03 sec)
mysql>

Notice, the \G option that was used to run the query and how it neatly arranged the columns vertically (as opposed to horizontally). I am pretty sure there is no easy way to do this in SQLPlus. However, SQLPlus is probably much more powerful thanks to the bazillion directives (as shown above) that you can use to configure it to your taste. Personally, I don’t care too much about the many directives that SQLPLus has. All I really need, and I have not yet figured it out, is how to enable spooling in ‘mysql’ client.

4. While using these command-line clients to access Oracle or MySQL is great, it sure is a pain that the prompts by default is:

SQL> (for Oracle's SQLPlus)

mysql> (for MySQL)

If you wanted to set your SQL prompt in Oracle, this site will tell you how to do it. I like the fact that you’ve an option in Oracle whereby you can have your prompt set as soon as you log in. Here’s how you can set your prompt in MySQL (in versions > 4.0.x):

% mysql
mysql> PROMPT d>_
PROMPT set to 'd>_'
(none)> USE mtdb;
Database changed
mtdb> USE test;
Database changed
test>

I have not yet found out how to make this thing be run automatically so that I would not have to type ‘PROMPT \d>\_’ everytime I log into a MySQL database. If you know, I’d be interested.

That’s all for now. I am sure I will have more later.

- Anand

Viewed: 2761 times

9 Comments

For mysql, my favorite tool is phpMyAdmin, but that naturally enough requires having apache and php configured right. Since most of my databases are for the web anyways, having it deployed on a permanent (& hidden from the world) server works well for me.

A great book for this sort of thing is the new SQL Pocket Reference from O’Reilly. Rather than treat each rdbms (oracle, mysql, db2, microsoft) separately, it groups concepts together, so that (for example) when looking up “nulls” it has the details of how all 4 of them support nulls (like what is the mysql equivilant for the oracle nvl() function).

So if you really know one of them, this is a great book for finding the matching syntax for the same concepts in the other 3 (if it is supported at all), plus which one’s syntax is the actual ANSI-compliant version.

Posted by: Joe Shelby at May 19, 2004 @ 1:51 pm

Going from mysql to Oracle can be quite hard if you use the command line. As a tool, sqlplus is quite possibly the worst that could be imagined.

The mysql [and other db’s] command line is far more functional with all the usual tricks you’d expect from a unix command line. Search, completion, previous-line etc.

Posted by: Henri Yandell at May 19, 2004 @ 3:31 pm

Nice. Thanks Joe. Must say I did not know about the SQL Pocket Reference.

As for phpMyAdmin, I did install it once some time back and was pretty impressed by the kind of capabilities it provided. Have not had a chance to revisit it. This might be a good time to do just that..:-)

Posted by: Anand Sharma at May 19, 2004 @ 3:32 pm

What’s MySQL’s LOB (CLOB / BLOB) handling like?

Odds are it couldn’t be any worse than Oracle’s (although with any luck they might have finally straightened it out in 10g - I’m not keeping my hopes up though).

Posted by: Oracle Victim at May 19, 2004 @ 9:23 pm

Anand,

> I have not yet found out how to make this thing be run
> automatically

–prompt=
is runtime option of mysql

You can either use alias or wrapper script to run mysql or simply put this option in my.cnf file under [mysql] section. If you want it for personalized use ~/.my.cnf i.e. .my.cnf in your home directory (in case of Unix)

[mysql]
prompt=”This is a prompt :)\ “

Posted by: Alexander Keremidarski at May 20, 2004 @ 4:17 am

Thanks Alexander. Must say I did not know about the stuff you mentioned. Will definitely try it out and let you know.

Posted by: Anand Sharma at May 20, 2004 @ 9:10 am

Dear ‘Oracle victim’..;-)

I wish I had answers for you, but it will be a while before I have dived far enough into MySQL to know about it’s CLOB/BLOB handling. I think TEXT is MySQL’s equivalent of CLOB and using it was as simple as using any VARCHAR. In Oracle, I believe you have to have a special handling of CLOBs vis-a-vis VARCHAR2.

Note: Yes, that reminds me. In Oracle, we normally use VARCHAR2 while in MySQL it’s called VARCHAR. I never quite found out what was the 2 in VARCHAR2. I know Oracle also has a VARCHAR, but I’ve never used it. Can’t remember why of the top of my head right now..;-)

Posted by: Anand Sharma at May 20, 2004 @ 9:15 am

From Oracle 9i onward, VARCHAR2 and VARCHAR are identical. I can’t even remember why they were different in earlier versions, although it may have been something to do with multi-byte support. I’m getting old, my memory is fading… ;-)

I’m glad to hear MySQL is “sensible” in its implementation of large text fields - sounds like it’s much more like MS SQL Server in that regard (MSSQL also uses the “text” type rather than CLOB, not that that really means anything).

<mini rant>
I still can’t believe how many hours I’ve spent over the years cursing Oracle’s CLOB / BLOB implementation (particularly in the way it’s surfaced via JDBC). Every new version seemed to break the code that worked on the previous version! And don’t get me started on trying to write database-independent CLOB handling code!! :-\
</mini rant>

Posted by: Oracle Victim at May 20, 2004 @ 5:30 pm

I thought this site is going to discuss Segmentation fault problem in mysql.

Posted by: Senthil at February 21, 2006 @ 11:20 pm