Showing posts with label MySql. Show all posts
Showing posts with label MySql. Show all posts

July 3, 2007

Delete Duplicate records

The scenario is:

The table has 3 columns, A, B, and C. Column A is unique for all rows
but the columns B and C can be duplicate across rows.
And it needs to remove the rows where B and C are duplicated.

DELETE
FROM tbl_name
WHERE
a NOT IN
(
SELECT
MIN(a)
FROM daTable
GROUP BY b,c
)

March 15, 2007

Website Shifting (All files & DataBase)

Here is the method for Shifting your website & database from one server to another with simple steps. This works only on Linux server.

Steps to follow on Existing(Source) Server:
1. Move in the root folder of project i.e. change the directory
cd /path/to/dir

2. Compress the website(project) folder
tar -cvf xxxx.tar * (Supposing 'xxxx' is the name of project)

3. Export the Database in a tar file
mysqldump dbName -u dbUserName -p > dbFileName.tar
Password: myPassword

example:
mysqldump xxxx -u root -p > xxxx_DB_Backup.tar
Password: password

4. Copy the tar files to New server, where you want to shift (move) the website
scp xxxx.tar RemoteUserName@RemoteIP:/path/to/dir/xxxx.tar
Password: (password for that user of Remote IP)

example:
scp xxxx.tar root@127.0.0.1:/home/xyz/public_html/xxxx.tar
Password: myRootPassword

scp xxxx_DB_Backup.tar root@127.0.0.1:/home/xyz/public_html/xxxx_DB_Backup.tar
Password: myRootPassword

Steps to follow onNew(Target) Server:
1. Move in the root folder of project, where you have copied the compressed file
cd /path/to/dir

2. UnTar the tar file
tar -xvf xxxx.tar

3. Import the Database
mysql myDbName -u
dbUserName -p < dbFileName.tar
Password: myPassword

March 14, 2007

Full Backup of MySQL DataBase

Here are some methods for FULL backup of MySQL Databases. This way all the constraints, stored procedures, triggers etc will be copied for backup and/or replicating the database.

Depending on your access to server, you can choose the different options.
e.g. you will not be able to copy the files from a shared hosting server (Method 3)

METHOD 1:
shell> mysqldump --tab=/path/to/some/dir --opt --full

METHOD 2:
shell> mysqlhotcopy database /path/to/some/dir

METHOD 3:
simply copy all table files (`*.frm', `*.MYD', and `*.MYI' files)

METHOD 4:
You can write your own script which you can use to backup your database with various options. An example script can be downloaded from here

Please comment to this post to suggest more methods which can be added here.
Thanks

February 21, 2007

SQL Server 2000 Vs MYSQL v4.1 ( Limits)

Here you can find comparison of Limits.. between 'SQL Server 2000' & 'MySQL 4.1'


Feature SQL Server 2000 MySQL 4.1
column name length 128 64
index name length 128 64
table name length 128 64
max indexes per table 250 32
index length 900 1024
max index column length 900 255
columns per index 16 16
max char() size 8000 1048543
max varchar() size 8000 1048543
max blob size 2147483647 1048543
max number of columns in GROUP BY Limited only by number of bytes (8060) 64
max number of columns in ORDER BY Limited only by number of bytes (8060) 64
tables per SELECT statement 256 31
max columns per table 1024 2599
max table row length 8036 65534
longest SQL statement 16777216 1048574
constant string size in SELECT 16777207 1048565