In this tutorial you will learn how to quickly create a database in CUBRID. If you use a Desktop version of the OS and prefer using GUI tools instead of a terminal, you may perform all of the commands below in CUBRID Manager.
To start with let's create a sample database. Type the following command in the terminal. This assumes that CUBRID is installed in your system (or see installation instructions). If necessary, replace sample_db with your own database name.
cubrid createdb sample_db
If you want to keep your databases in a certain directory, first navigate to that directory and then execute the above createdb command in that directory.
Once you have created a database, you need to start it before you try to connect to it.
cubrid server start sample_db
If you decided to use a command line terminal, you need to connect to a database to execute SQL queries. CUBRID provides CSQL command line SQL interpreter for this. Let's connect to a database.
csql sample_db -u dba CSQL Interpreter Type `;help' for help messages. csql>
Now create a table to hold users' data. SQL in CUBRID is very much same to that of MySQL.
CREATE TABLE "tbl_users"( "id" integer AUTO_INCREMENT, "email" varchar(100) NOT NULL UNIQUE, "join_date" integer NOT NULL, CONSTRAINT pk_tbl_users_id PRIMARY KEY("id") );
Copy and paste the above schema declaration in the CSQL and press Enter.
Now let's insert some data into the table using CSQL.
INSERT INTO tbl_users (email, join_date) VALUES ('email@example.com', 1328523265), ('firstname.lastname@example.org', 1328534265), ('email@example.com', 1328528265), ('firstname.lastname@example.org', 1323423265), ('email@example.com', 1328523665);
At this point you have learnt how to create a database and a table as well as insert sample data.
There can be several reasons why your database may fail to start.
hostnameresolves (by editing hosts file) to the IP of your server (eg. localhost or 127.0.0.1). It is common that users forget to ensure this. Note that CUBRID doesn't support IPv6, which means your hostname should resolve to an IPv4 address.