Google
 

Tuesday, November 16, 2004

Installing Firebird on FreeBSD

http://81.138.11.136:8080/tikifirebird/wiki/index.php?page=FirebirdOnFreeBSD

By far the easiest way to install Firebird is via a package, or the ports tree.
When people in the FreeBSD community get a package running on FreeBSD, they often submit how they did it as a 'port', back to FreeBSD.
( This saves you working out what configure scripts to change, which make to use (make, gmake, bmake, aimk, etc) )

So we'll follow the road they've already blazed. Of course, feel free to download the source tarball, and get it building yourself, but it could take a while...


If you can't find a pre-compiled binary package on FreeBSD.org, firebirdsql.org, or ibphoenix.com, sync up your ports tree.
(Building it yourself ensure's it's built using optimisations for the processor you're running, too)


once ports tree is updated, do:


code:


cd /usr/ports/databases/firebird
make install



Once this is finished, all dependencies are installed, the database is installed, the startup scripts are in place, the firebird user is added, and we're ready to go.

As the comment at the end of the install process suggests, we should change the password of the sysdba user, so lets do that now.

Starting Firebird
This involves running

code:

/usr/local/etc/rc.d/000.firebird.sh start
killall -HUP inetd


Or, simply reboot

Setting up Firebird's SYSDBA User

code:

cd /usr/local/firebird
./bin/gsec -user SYSDBA -pass masterkey
( the ./bin/ is required if you haven't got /usr/local/firebird/bin in your path )
GSEC> modify SYSDBA -pw

( We might add a user while we're here )
GSEC> add testuser -pw testuser

( Now quit out )
GSEC> quit



Done. Now we're ready for databases. the Firebird runs as the user firebird, thusly needs read/write permissions to a directory to store the databases.
I usually make one called '/usr/db':

code:

mkdir /usr/db
chown firebird /usr/db
chgrp firebird /usr/db
chown 770 /usr/db



There we have a nice, secure little home for our databases.
This directory isn't created by the install,as people will always want their databases stored in a different place, on a different HDD controller, etc.

Lets make a database

using your favourite editor, start a file in your home directory called 'fire1.sql', and in it, put the following:

code:

CREATE DATABASE "localhost:/usr/db/fire1.gdb".
COMMIT.

CREATE TABLE tbl_test1(
str_name VARCHAR(100) NOT NULL,
str_phone VARCHAR(20),
PRIMARY KEY(str_name)
).


Then save, and exit the file

Now, well create the database
( It may pay to put '/usr/local/firebird/bin' in your path, to save using the full path to the binaries every time )

code:

isql -u testuser -p testuser < fire1.sql


Logging in for the very first time
Lets log in, and have a look. Run:

isql -u testuser -p testuser localhost:/usr/db/fire1.gdb

Database: localhost:/usr/db/fire1.gdb, User: testuser
SQL>

You're in! Lets see what's inside:
( Note. Put a semi-colon at the end of every command. It's the terminator at the moment )


SQL> show tables;
TBL_TEST1
SQL>

Let see how that table's made up:
SQL> show table tbl_test1;
STR_NAME VARCHAR(200) Not Null
STR_PHONE VARCHAR(20) Nullable
CONSTRAINT INTEG_2:
Primary key (STR_NAME)
SQL >

Lovely! put some data in
SQL> insert into tbl_test1 (str_name, str_phone)
CON> values ('henry','12345678');
SQL>

( Note the 'CON>' appears while a statement is continuing )

Let's select everything in the table
SQL> select * from tbl_test1;
STR_NAME STR_PHONE
===== ===
henry 12345678

Lets put some more in
SQL> insert into tbl_test1 (str_name, str_phone)
CON> values ('jane','87654321');
SQL>

Select all
SQL> select * from tbl_test1;
STR_NAME STR_PHONE
==== ========
henry 12345678
jane 87654321

Select henry
select * from tbl_test1 where str_name = 'henry';

select people starting with 'h'
select * from tbl_test where str_name like 'h%';

select the first record
select first 1 * from tbl_test1;

select 1 record, but skip 1
select first 1 skip 1 * from tbl_test1;

select any records with the letter 'e' in them
select * from tbl_test1 where str_name containing 'e';

As you can see, the SQL is very similar to other databases.

No comments: