Showing posts with label Database. Show all posts
Showing posts with label Database. Show all posts

May 29, 2008

MySQL Cluster

1.What is MySQL Cluster?
Using
MySQL Cluster is a high-availability, high-redundancy version of MySQL adapted for the distributed computing environment.
It uses the NDBCLUSTER storage engine to enable running several MySQL servers in a cluster.
http://dev.mysql.com/doc/refman/5.0/en/mysql-cluster.html
Tech
MySQL Cluster is a technology that enables clustering of in-memory databases in a shared-nothing system(1).

2. Supported
Linux, Solaris, Mac OSX, HT-UX, and other Unix-style operating systems on a variety of hardware.
Cluster Supported Platforms list
3. Architecture
A MySQL Cluster consist of a set of computers, each running a one or more processes which may include a MySQL server, a data node, a management server, and (possibly) a specialized data access programs.

All these programs work together to form a MySQL Cluster. When data is stored in the NDBCLUSTER storage engine, the tables are stored in the data nodes. Such tables are directly accessible from all other MySQL servers in the cluster.
The data stored in the data nodes for MySQL Cluster can be mirrored.
MySQL Cluster's NDB storage engine contains a complete set of data, dependent only on other data within the cluster itself.
Currently, MySQL does not support multiple data nodes in a single server.

4. Keywords
Shared-nothing system(SN): is a distributed computing architecture in which each node is independent and self-sufficient, and there is no single point of contention across the system

Mar 3, 2008

Sort the null or blank value in SQL

ORDER BY
CASE
WHEN #sort_column IS NULL THEN '2'
WHEN #sort_column = '' THEN '1'
ELSE '0'
END,
#sort_column [ASC or DESC]

Dec 6, 2007

Delete duplicate rows in Table - Oracle

delete from TABLE_NAME t1
where t1.rowid >
( select min(t2.rowid) from TABLE_NAME t2
where t1.COLUMN_1 = t2.COLUMN_1
and t1.COLUMN_2 = t2.COLUMN_2);

Jul 8, 2007

Install and config MySQL

Installation
yum install mysql
yum install mysql-server
yum install mysql-administrator
Configuration
chkconfig --levels 235 mysqld on
Starting
/etc/init.d/mysqld start
Changing the root password
mysqladmin -u root password your_root_sql_password
Backup
One database
mysqldump --single-transaction nhungnguoibantot_db > backup_nhungnguoibantot_db.sql -p
All databases
mysqldump --single-transaction --all-databases > backup_all_databases.sql -p
Restore
One databases
mysql > create database nhungnguoibantot_db;
mysql -u root -p < backup_nhungnguoibantot_db.sql
All databases
mysql -u root -p <
backup_all_databases.sql
Show all databases
mysql>show databases;
Connect to database
connect database_name;
Show all tables of a database
mysql>show tables;
Create a new user to manage database
GRANT SELECT,INSERT,UPDATE,DELETE,CREATE,DROP
ON database_name
TO 'username'@'localhost'
IDENTIFIED BY 'password';

Configure PostgreSQL

To connect from other host than locahost
- In file postgresql.conf (/var/lib/pgsql/data/postgresql.conf)
Change or add
listen_addresses = "*"
- In file pg_hba.conf
Allow connect from localhost
host all all 192.168.1.0/24 trust
Allow connect from internet
host all all 0.0.0.0/0 trust

note
0.0.0.0/a mean that IP in a range of 0.0.0.0 with a bits is fixed