Firebird for Linux

xiaoxiao2021-03-06  15

In July 2000, Borland (ie, the current Inprise) announced the source code of its database product Interbase. The Firebird database is derived from the database. At that time, InterBase was bundled with the customer / server version of the Delphi product in some sales. Now, InterBase has become a "flamingo" in an open source.

Why use Firebird?

Some people may ask, open source databases have been enough, do you need other databases? The author believes that for small businesses users, the current open source database has two deficiencies: it is too big (such as mysql, postgreSQL); either too small, and lack function and document (such as HypersonicsQL and MCKOI). In many applications, users need to have a size and fully functional database.

Firebird is relatively small, and its RPM version is only 2.6MB. This makes it possible to be an ideal "embedded database" that can be used to bundle with other application servers and applications. Firebird has the functions of most of the mature databases, such as supporting stored procedures, SQL compatibility. If the user has experience using DB2 or PostgreSQL, it will find that Firebird is very similar to their syntax, and the data type and data processing method are also very similar.

Firebird's design ideas are small, fast and minimized management. This is applicable to developers who need a database for storing data, but do not want to spend too much time to adjust data performance. In fact, in many cases, we do not need to store the association between programs or complex tables. At this time, Firebird will find an ideal balance point between the size and functions.

Install Firebird

We can download Firebird from http://firebird.SourceForge.Net/index.php, as shown in Figure 1:

Figure 1 Very rich Firebird home page

There are now two versions of Firebird server software for download, which is Firebird Super Server and Firebird Classic Server. Simply, the difference between the two is different. Super Server uses threads to provide services for multiple client connection, while Classic Server is the interbase method, which provides a stand-alone server process for each connection. If you want to learn more about the differences, you can view http://www.ibphoenix.com/main.nfs?a= ibphoenix & page = ibp_ss_vs_classic. For users of "embedded database", there is not much difference between these two versions. In theory, if the application has a lot of users, SUPER Server will be a better choice. Below, the author will introduce as examples (this example is FirebirdsS-1.0.2.908-1.i386.2.908-1.i386.2.2.908-1.i386.2.2.908-1.i386.2.908-1.i386.2.908-1.i386.2.2.908-1.i386.rpm). The database is only 2.5MB, and the requirements for the system are also very low. In fact, as long as the hardware system can run Linux, you can run this database.

The environment where this database is installed herein is Red Hat 8.0. The installation process is described below.

First do the following command:

# echo localhost.localdomain >> / etc / hosts.equiv

This command will add localhost to the list of identifiable servers. Switch to the directory where the download file is located, run the command:

# rpm -ivh firebirdss-1.0.2.908-1.i386.rpm

After the installation is complete, create a boot script in the /etc/init.d directory, which automatically starts Firebird when the server is started. If you encounter an error during the installation process, check if ncurses4 (5.0 or more versions) and GLIBC (2.2 or higher) are installed, the inspection methods are as follows: # rpm -qa | grep ncurses

NCURS-DEVEL-5.2-28

NCURSES-5.2-28

# rpm -qa | GREP GLIBC

GLIBC-2.2.93-5

GLIBC-Devel-2.2.93-5

GLIBC-KernHeaders-2.4-7.20

GLIBC-Common-2.2.93-5

In general, the default installation Linux system has installed NCURSES4 and GLIBC, so pay attention to see if the version of the two packages meets the requirements.

Firebird also creates an interbase directory in the / OPT directory and place the executable here. We need to let the database can be available in the whole system, to edit / etc / profile for this, and insert the following:

Export Interbase_Home = / OPT / Interbase

Export Path = $ PATH: $ Interbase_Home / Bin

Save the file and restart the system, check if the firebird is started correctly.

Use system

The user name of the default system administrator account is SYSDBA, the default password is MasterKey. During use, the author discovers that the system is not case sensitive to the username. Users can use this account to create other users. Available system management tools are:

◆ GSEC

This is a secure system program that can create, modify, and delete database users, change your password. GSEC must be run in sysdba, call and execute the following command as root:

$ GSEC -USER SYSDBA -PASSWORD MASTERKEY

A GSEC> prompt will appear, you can display the current user using the display command, as shown below:

GSEC> DISPLAY

User Name Uid Gid Full Name

-----------------------------------

Sysdba 0 0

The default password is unsafe, it is recommended to change the Sysdba password. You can change your password using the following command:

GSEC> Modify sysdba -pw newpassword

NewPassword, new password in the command. The password is preferably used in combination of numbers and letters, and often changes.

◆ ISQL

This is an interactive SQL tool, similar to Oracle's SQL * Plus and PostgreSQL's psql command. It can be used to test and run the SQL query. Firebird comes with a database instance called Employee, you can use it to test the SQL command, the code is as follows:

# CD / OPT / Interbase / Bin

# ./isql /opt/interbase/examples/employee.gdb

Database: /opt/interbase/examples/employee.gdb

SQL>

This will connect to the Employee database and display the SQL> prompt. You can enter the SQL command here for the query (pay attention to the ";" number). In addition, since some systems related to the database are also installed with ISQL tools, so be sure to switch to the "/ OPT / Interbase / Bin" directory to run the ISQL tool. Now enter the following command at the SQL> prompt:

SQL> SELECT EMP_NO, FULL_NAME, JOB_CODE, JOB_COUNTRY from Employee, will display the following:

EMP_NO FULL_NAME JOB_CODE JOB_COUNTRY

======= =================== ========

2 Nelson, Robert VP USA

4 Young, Bruce ENG USA

5 lambert, Kim ENG USA

8 Johnson, Leslie Mktg USA

9 Forest, Phil Mngr USA

11 Weston, K. J. SREP USA

12 Lee, Terri Admin USA

14 Hall, STEWART FINAN USA

15 Young, Katherine MNGR USA

20 Papadopoulos, Chris MNGR USA

24 Fisher, Pete ENG USA

28 Bennet, Ann Admin England

29 de Souza, Roger ENG USA

34 Baldwin, Janet Sales USA

36 Reeves, Roger Sales England

37 Stansbury, Willie Eng England

44 Phong, Leslie Eng USA

45 Ramanathan, Ashok Eng USA

46 Steadman, Walter CFO USA

52 Nordstrom, Carol Prel USA

If you want to view all the tables in the database, enter the following command:

SQL> Show Tables;

The following information will be displayed:

Country Customer

Department Employee

Employee_Project Job

Phone_List Project

Proj_dept_budget salary_history

Sales

To exit from ISQL, just enter "quit;".

Create your own database

So far, we have implemented some commands as SYSDBA and view some database exemplary. Next, create a database and create a user who has the right to view and change the database, and then perform a database test in the operating system.

Creating a database requires the ISQL tool. Firebird stores files in a discrete form. As a convention, the file extension is generally .GDB, the user can also store files in any extension. First create a database as SYSDBA, then store it under the $ interbase_home directory with TEST.

First create a directory called "TestDb" in the / opt / interbase directory (note to assign appropriate permissions for it). Switch to this directory and start the ISQL with without parameters. Then create a database using the CREATE DATABASE command, the code is as follows:

SQL> CREATE DATABASE '' 'number' 'sysdba' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' ''.

This command will create a file called firstdb.gdb in the current directory. This database is owned by SYSDBA. Let's create a basic sales table and enter the data, the code is as follows:

SQL> CREATE TABLE SALES_CATALOG (Con> Item_ID VARCHAR (10) Not Null Primary Key,

Con> item_name varchar (40) Not null,

Con> item_desc varchar (50)

Con>);

SQL> INSERT INTO SALES_CATALOG VALUES ('' 001 ',' 'Aluminium Wok' ",

'' CHINESE WOK USED for Stir Dishes '');

SQL> INSERT INTO SALES_CATALOG VALUES ('' 002 '",

'' CHOPSTICKS EXTRA-long '', ''60 -cm chopsticks';

SQL> INSERT INTO SALES_CATALOG VALUES ('' 003 '",

'' CLAYPOT '', '' Pot for Stews '');

SQL> INSERT INTO SALES_CATALOG VALUES ('' 004 '",

'' Charcoal Stove '', '' for ClayPot Dishes '';

SQL> SELECT * from sales_catalog;

Item_ID item_name item_desc

=================================================================================

001 Aluminium Wok Chinese Wok Used for Stir Fry Dishes

002 CHOPSTICKS EXTRA-long 60-cm chopsticks

003 Claypot Pot for Stews

004 Charcoal Stove for Claypot Dishes

Add user

Do not create all databases using the system administrator account SYSDBA. Sometimes, for example, when running multiple databases that belong to different users and groups, you may want each user and group to have their own databases and have the right to view. Another situation needs to create a proxy user, and all database operations can be performed, but their permissions are below SYSDBA. When doing this, you need to use the GSEC tool. For example, create an account name Testadmin, password is TestAdmin (note that the number of passwords can only be 8 bits) and gives it viewed, modified, and deleted the permissions of database firstdb.gdb. Use the following command to complete these features:

$ GSEC -USER SYSDBA -PASSWORD MASTERKEY

Gsec> add testadmin -pw testadmin -fname firstdb -lname administrator

Warning - Maximum 8 Significant bytes of Password USED

Open the database, create a system management role for the database, assign appropriate permissions, then run the following code: $ isql firstdb.gdb -user sysdba -password masterkey

Database: firstdb.gdb, user: sysdba

SQL> Grant SELECT, UPDATE, INSERT, DELETE ON SALES_CATALOG TO Administrator;

SQL> Grant Administrator to Testadmin;

SQL> quit;

Add TestAdmin to it. Next, test the database.

Test database

First quit GSEC and ISQL, log in to the database firstdb.gdb as TestAdmin, and run the following SQL statement:

SQL> Delete from sales_catalog;

SQL> INSERT INTO SALES_CATALOG VALUES ('' 001 ',' aluminum wok '', '' Chinese wok '');

SQL> INSERT INTO SALES_CATALOG VALUES ('' 002 ',' MicroWave Oven ", '' 300W MicroVe Oven ');

SQL> INSERT INTO SALES_CATALOG VALUES ('' 003 ',' 'CHOPSTICKS Extra-long', '' 60cm chopsticks';

SQL> SELECT * from sales_catalog;

Item_ID item_name item_desc

===================================================

001 Aluminum Wok Chinese WOK

002 Microwave Oven 300W MicroWave Oven

003 Chopsticks Extra-long 60cm Chopsticks

If there is no problem, the configuration has been completely successful. Now, the flamingo on this linux can be flying.

Full text

转载请注明原文地址:https://www.9cbs.com/read-47962.html

New Post(0)