Saari Development

MySQL: Restarting MySQL on Ubuntu

Posted in mysql by imsaar on April 7th, 2008
/etc/init.d/mysql start

OR

/etc/init.d/mysql restart

Source:
Mysql Database Server Installation and Configuration in Ubuntu

Tagged with: , ,

MySQL : Saving a ton of space on old tables

Posted in mysql by imsaar on January 10th, 2008

Here is a nice article about using MySQL (> 5) archive engine.
The MySQL 5.0 Archive Storage Engine

If you have some tables that has mostly read-only for data retention purposes then you can do something like this to drastically reduce the disk spaced used by that table:


alter table MY_OLD_TABLE drop primary key, engine=archive;

note the archive table does not have primary key and dropping the primary key in this way prevents from rebuilding the table twice (compared to the case where you issue two alter table, one to drop key and second to switch engine.

Tagged with: , , , ,

MySQL : Information about tables

Posted in mysql by imsaar on January 10th, 2008

desc information_schema.tables;
+-----------------+--------------+------+-----+---------+-------+
| Field           | Type         | Null | Key | Default | Extra |
+-----------------+--------------+------+-----+---------+-------+
| TABLE_CATALOG   | varchar(512) | YES  |     | NULL    |       |
| TABLE_SCHEMA    | varchar(64)  | NO   |     |         |       |
| TABLE_NAME      | varchar(64)  | NO   |     |         |       |
| TABLE_TYPE      | varchar(64)  | NO   |     |         |       |
| ENGINE          | varchar(64)  | YES  |     | NULL    |       |
| VERSION         | bigint(21)   | YES  |     | NULL    |       |
| ROW_FORMAT      | varchar(10)  | YES  |     | NULL    |       |
| TABLE_ROWS      | bigint(21)   | YES  |     | NULL    |       |
| AVG_ROW_LENGTH  | bigint(21)   | YES  |     | NULL    |       |
| DATA_LENGTH     | bigint(21)   | YES  |     | NULL    |       |
| MAX_DATA_LENGTH | bigint(21)   | YES  |     | NULL    |       |
| INDEX_LENGTH    | bigint(21)   | YES  |     | NULL    |       |
| DATA_FREE       | bigint(21)   | YES  |     | NULL    |       |
| AUTO_INCREMENT  | bigint(21)   | YES  |     | NULL    |       |
| CREATE_TIME     | datetime     | YES  |     | NULL    |       |
| UPDATE_TIME     | datetime     | YES  |     | NULL    |       |
| CHECK_TIME      | datetime     | YES  |     | NULL    |       |
| TABLE_COLLATION | varchar(64)  | YES  |     | NULL    |       |
| CHECKSUM        | bigint(21)   | YES  |     | NULL    |       |
| CREATE_OPTIONS  | varchar(255) | YES  |     | NULL    |       |
| TABLE_COMMENT   | varchar(80)  | NO   |     |         |       |
+-----------------+--------------+------+-----+---------+-------+

-- now you can do this or some such
select table_name, engine from information_schema.tables where table_name like "MY_TABLE%";

MySQL : Find out and change charset of a table

Posted in mysql by imsaar on January 10th, 2008

show create table TABLE_IN_QUESTION;
-- show create table can tell you more than
-- describe TABLE_IN_QUESTION including database engine
-- look towards the end for CHARSET=XXX
alter table TABLE_IN_QUESTION CONVERT TO CHARACTER SET latin1;

MySQL and Rails: mysql.sock not found

Posted in mysql, rails by imsaar on August 6th, 2007

I started doing my webapp on my brand new server (ubuntu linux 7.04) and when trying to run my first migration I got the following error message:

rake db:migrate(in /home/rizvi/projects/somewebapp)rake aborted!No such file or directory - /tmp/mysql.sock

Here is a useful mysql command to find out mysql defaults:

mysqladmin --print-defaultsmysqladmin would have been started with the following arguments:--port=3306 --socket=/var/run/mysqld/mysqld.sock

Here is what solved the problem:

sudo apt-get install libmysql-ruby

Note: The above is an alternative to :

sudo gem install mysql

Now I get:

rake db:migrate(in /home/rizvi/projects/somewebapp)rake aborted!Unknown database 'somewebapp_development'(See full trace by running task with --trace)

So I need to do the following:

mysqladmin -u root create somewebapp_development -pmysqladmin -u root create somewebapp_test -pmysqladmin -u root create somewebapp_production -p

Reference: RailsOnUbuntu