Pejman Moghadam / General

MySQL cheat sheet

Public domain


Table Repair

CHECK TABLE radacct EXTENDED;
REPAIR TABLE radacct;

Add a column to an existing table

ALTER TABLE table_name ADD new_column INT NOT NULL;
ALTER TABLE table_name ADD new_column VARCHAR(50) AFTER existing_column;
ALTER TABLE table_name ADD new_column VARCHAR(50) FIRST;

Change a column name

ALTER TABLE table_name CHANGE old_name new_name VARCHAR(50);

Add unique to an existing column

ALTER TABLE table_name ADD UNIQUE (existing_column);

Remove a column

ALTER TABLE table_name DROP COLUMN column_name;

Export database schema

mysqldump -uroot -p database -d > databse-schema.sql

Export entire database

mysqldump -uroot -p database > databse-backup.sql

Sotring IP

mysql> SELECT INET_ATON('192.168.10.50');
+----------------------------+
| INET_ATON('192.168.10.50') |
+----------------------------+
|                 3232238130 | 
+----------------------------+
1 row in set (0.00 sec)

mysql> SELECT INET_NTOA('3232238130');
+-------------------------+
| INET_NTOA('3232238130') |
+-------------------------+
| 192.168.10.50           | 
+-------------------------+
1 row in set (0.00 sec)

BY: Pejman Moghadam
TAG: mysql
DATE: 2011-06-08 10:36:58


Pejman Moghadam / General [ TXT ]