Installing MySQL Server to Ubuntu

Here are the steps that you need to follow:

1- Install the files that need to create a mysql database.

sudo apt-get install mysql-server  2-  Open the config file and comment out the line "bind-address =  127.0.0.1" as "#bind-address = 127.0.0.1". It makes your server  available from internet.gksudo gedit /etc/mysql/my.cnf

3- Set the root password of the server and restart it.

mysqladmin -u root password your-new-passwordsudo /etc/init.d/mysql restart

4- Install the “MYSql query browser” program

$sudo apt-get install mysql-query-browser

5- Program is installed in Applications > Programming, open it. Then type the necessary infos.

Server Hostname: 127.0.0.1
Username: root
Password: ******
Default Schema: (Empty)
Port : 3306

Share


Normalize Your Database with NF rules.

The Normal Form rules are the basic rules that are created by the Relational Database concept creater Edgar F. Codd. The main purpose of these is to create database tables that do not have redundancy for the data inside. There are basically three NF variations 1NF, 2NF, 3NF (Actually now on it goes up to 6NF by other theoreticians but basic structure is based on 1NF 2NF 3NF) .

1NF points out:
– Table should not have columns that are based on same data
– Create separate tables for each group of related data and identify each row with a unique column (the primary key).

Example:
(Manager, Employee1, Employee2 ) are the columns but there are two Employee column that violate rule one.

(Manager, Employee) is good solution but it violates still second rule.

(Manager, EmployeeID) is intuitive solution since each Employee has only one Manager. Now our table is proper for 1NF.

2NF points out:
– Remove subset of data that causes multiple rows includes same information and create seperate table for them
-Use foreign keys to relate the tables that are newly created and previous one

EXAMPLE:
(EmpID,FirstName, LastName, City, Zipcode, ) is our table but if there are two employee with same city so zipcodem it makes two row with redundant data. So it is more appropriate to use another table that includes cities and correspondence zipcodes. In addition new new structure makes easier to add, remove or update address information. Instead of updating all the rows that have same city and zipcode, we just need to update one row in the new table.
(EmpID, FirstName, LastName, AddID) (AddID, City, ZipCode)

3NF points out:
-Each attribute in the table must be fully determined by a key, separate other columns to other table.

EXAMPLE:
(CustomerID, OrderNum, UnitPrice, Quantity, Total) in this table all the attributes are fully depended to CustomerID but the Total. Total is determined by the UnitPrice*Quantity so it is not fully depended to key. It can be deleted.
(CustomerID, OrderNum, UnitPrice, Quantity) is new table

Share



Using Pipes for IPC in C

I am developing a program that utilises the pipe system of POSIX for my Operating system course. I want to share my experience with you. There might be some flaws in my explanations and in that case please WARN ME?

Then, lets start some explanation for beginning. Pipes system is used for (Inter-process Communication) IPC between related processes. Related means that the processes having parent-child relation or sibling relation. It is not possible to use pipes for unrelated process communication. In addition the another limitation of the pipes is that one pipe just gives uni-directional communication between processes so if you want to have both direction communication, you might use two distinct pipes that have different directions in the way of sharing data (one pipe to send data form parent to child, one pipe to send data from child to parent). Another restriction of the pipe system, it is not the best way to share big data between processes (Using shared memory structure may be suitable) but it is the most common way.

Now here the basic process of coding in C:

First #include stdio.h(standard input output library) stdlib.h (standard library) unistd.h(POSIX depended functions library)

Create the pipe with “pipe(fd)”. fd is the array to keep the file descriptors that are returned by the function. These descriptors points the “files” that are created after the function to provide read and write. (By the way, pipes are respected as files in the system. Thus each read and write action manipulated like file objects). Here is the code:

int fd[2];
pipe(fd);

After you create the pipe, if you “fork()” the process, it creates a child process that inherits all the information about the pipe so it is okay to communicate with the pipes.

I give an example code taken and little manipulated by myself form a pdf. In this implementation, by using the file descriptors we create file objects. In that way, this is possible to use standard C functions to read and write pipes. (Also you can get the PDF file from here).

Here
the link for below code:

#include
#include
#include
#include

/* Read characters from the pipe and echo them to stdout. */

void
read_from_pipe (int file)
{
FILE *stream;
int c;
stream = fdopen (file, “r”);
while ((c = fgetc (stream)) != EOF)
putchar (c);
fclose (stream);
}

/* Write some random text to the pipe. */

void
write_to_pipe (int file)
{
FILE *stream;
stream = fdopen (file, “w”);
fprintf (stream, “hello, world!n”);
fprintf (stream, “goodbye, world!n”);
fclose (stream);
}

int
main (void)
{
pid_t pid;
int mypipe[2];

/* Create the pipe. */
if (pipe (mypipe))
{
fprintf (stderr, “Pipe failed.n”);
return EXIT_FAILURE;
}

/* Create the child process. */
pid = fork ();
if (pid == (pid_t) 0)
{
/* This is the child process.
Close other end first. */
close (mypipe[1]);
read_from_pipe (mypipe[0]);
return EXIT_SUCCESS;
}
else if (pid < (pid_t) 0) {
/* The fork failed. */
fprintf (stderr, “Fork failed.n”);
return EXIT_FAILURE; }
else { /* This is the parent process. Close other end first. */
close (mypipe[0]);
write_to_pipe (mypipe[1]);
return EXIT_SUCCESS;
}
}

Also there is another way of using pipes by using “popen” as named pipe implementation. It is more generalised way of doing and avoids all the file object creation. You can get more info from the pdf.

Share


IPC (Interprocess Communication) implementation example.

This example code illustrates the basic implementation of IPC mechanism that is provided by POSIX API.


#include
#include shm.h>
>#include stat.h>
>
int main(int argc, char **argv)
{
int segment_id;
char *shared_mem;
const int size = 5096; // in bytes

//create shared mem.
segment_id = shmget(IPC_PRIVATE, size, S_IRUSR|S_IWUSR);

//attach the shared mem. to the process in Write Read mode.(0 argument)
shared_mem = (char * )shmat(segment_id, NULL, 0);

//write the data to the shared memory.
sprintf(shared_mem, "This is the shared memory example coded by Eren Golge. Regards!!");

//read the data from
printf("*%s n", shared_mem );

//detach the segment from process
shmdt(shared_mem);

//delete the shared mem. segment form memory
shmctl(segment_id, IPC_RMID, NULL);

printf("End of code");
return 0;
}

Share

Installing MySql to Ubuntu

Here are the steps that you need to follow:

1- Install the files that need to create a mysql database.

sudo apt-get install mysql-server2- Open the config file and comment out the line "bind-address = 127.0.0.1" as "#bind-address = 127.0.0.1". It makes your server available from internet.gksudo gedit /etc/mysql/my.cnf

3- Set the root password of the server and restart it.

mysqladmin -u root password your-new-passwordsudo /etc/init.d/mysql restart

4- Install the “MYSql query browser” program

$sudo apt-get install mysql-query-browser

5- Program is installed in Applications > Programming, open it. Then type the necessary infos.

Server Hostname: 127.0.0.1
Username: root
Password: ******
Default Schema: (Empty)
Port : 3306

Share

Compiling Kernel Method 2 (As Debian Package)

Here another compilation method for Kernel installing.

First download wanted kernel source code from kerel.org

then extract the .tar file that comes from the website.

Here the terminal process.

Copy the old config file to the new Kernel to do not try for setting new kernel.
­cp -vi /boot/config-`uname -r` .config

Or if you want to set your kernel type:
sudo make menuconfig

Then compile and create the debian packages of the kernel. You can type anything instead of **** to define your kernel. “fakeroot” commands gives error, maybe you need to download and install from “software center”.
fakeroot make-kpkg --initrd --append-to-version=**** kernel-image kernel-headers

There should be created two “debian packages” (most probably in desktop). Go that directory in terminal then type:
sudo dpkg -i linux-ubuntu-modules-2.6.24-16-generic_2.6.24-16.23_i386.deb
sudo dpkg -i linux-headers-lum-2.6.24-16-generic_2.6.24-16.23_i386.deb

Finally go to the boot directory to set the “grub” with your new kernel:

cd /boot
sudo update-initramfs -c -k 2.6.37+QD

sudo update-grub2
reboot

Share