Monday, September 29, 2014

MySQL database maintenance

To rebuild a table by dumping and reloading it, use mysqldump to create a dump file and mysql to reload the file:
shell> mysqldump db_name t1 > dump.sql
shell> mysql db_name < dump.sql
To rebuild all the tables in a single database, specify the database name without any following table name:
shell> mysqldump db_name > dump.sql
shell> mysql db_name < dump.sql
To rebuild all tables in all databases, use the --all-databases option:
shell> mysqldump --all-databases > dump.sql
shell> mysql < dump.sql
To rebuild a table with ALTER TABLE, use a null alteration; that is, an ALTER TABLE statement that changes the table to use the storage engine that it already has. For example, if t1 is a MyISAM table, use this statement:
mysql> ALTER TABLE t1 ENGINE = MyISAM;
If you are not sure which storage engine to specify in the ALTER TABLE statement, use SHOW CREATE TABLE to display the table definition.
If you must rebuild a table because a table checking operation indicates that the table is corrupt or needs an upgrade, you can use REPAIR TABLE if that statement supports the table's storage engine. For example, to repair aMyISAM table, use this statement:
mysql> REPAIR TABLE t1;
For storage engines such as InnoDB that REPAIR TABLE does not support, use mysqldump to create a dump file and mysql to reload the file, as described earlier.
For specifics about which storage engines REPAIR TABLE supports, see Section 13.7.2.6, “REPAIR TABLE Syntax”.
mysqlcheck --repair provides command-line access to the REPAIR TABLE statement. This can be a more convenient means of repairing tables because you can use the --databases or --all-databases option to repair all tables in specific databases or all databases, respectively:
shell> mysqlcheck --repair --databases db_name ...
shell> mysqlcheck --repair --all-databases
For incompatibilities introduced in MySQL 5.1.24 by the fix for Bug #27877 that corrected the utf8_general_ciand ucs2_general_ci collations, a workaround is implemented as of MySQL 5.1.62, 5.5.21, and 5.6.5. Upgrade to one of those versions, then convert each affected table using one of the following methods. In each case, the workaround altering affected columns to use the utf8_general_mysql500_ci and ucs2_general_mysql500_cicollations, which preserve the original pre-5.1.24 ordering of utf8_general_ci and ucs2_general_ci.
  • To convert an affected table after a binary upgrade that leaves the table files in place, alter the table to use the new collation. Suppose that the table t1 contains one or more problematic utf8 columns. To convert the table at the table level, use a statement like this:
    ALTER TABLE t1
    CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_mysql500_ci;
    
    To apply the change on a column-specific basis, use a statement like this (be sure to repeat the column definition as originally specified except for the COLLATE clause):
    ALTER TABLE t1
    MODIFY c1 CHAR(N) CHARACTER SET utf8 COLLATE utf8_general_mysql500_ci;
    
  • To upgrade the table using a dump and reload procedure, dump the table using mysqldump, modify the CREATE TABLE statement in the dump file to use the new collation, and reload the table.
After making the appropriate changes, CHECK TABLE should report no error.

Sunday, September 14, 2014

DOS cmd show history

In CMD window, press F7 to view the history of commands in the current cmd session

Friday, July 11, 2014

Cassandra ( C* ) vs RDBMS

To manage c* data, use cassandra-cli or cqlsh

keyspaces@c* = schema@c* = database@RDBMS
columnfamily@c* = table@RDBMS

Cli:

Start cli

> cassandra-cli
cli> connect localhost /9160;

Set active keyspace

cli> use demo;

Update a row in table "users":

cli> set users['user123'][email]='user123@gmail.com';

Select user row

cli> get users['user123']

cql:

> cqlsh

List available keyspaces

cqlsh> describe keyspaces
cql> SELECT * FROM system.schema_keyspaces;

Create keyspace

CREATE KEYSPACE Demo
WITH REPLICATION={ 'class':'SimpleStrategy', 'replication_factor':3 };

Set active keyspace

cql> use Demo;

Show all tables ( columnfamilies )

cqlsh> describe tables | columnfamilies;
cql> select columnfamily_name from system.schema_columnfamilies where keyspace_name=?;

Create table

 CREATE TABLE
        keyspace_name.
        table_name
( column_definition
        , column_definition, ...
        )
        WITH property AND property ...
      

Insert row into a table or columnfamily

INSERT INTO users(id, name, firstname, lastname, email, class)
  VALUES (62c36092-82a1-3a00-93d1-46196ee77204, 'user123',
  'Joe', 'Trader', 'user123@gmail.com', 'admin');

Sunday, June 8, 2014

Creating symbolic links in Windows NT file system


using DOS command "mklink"

mklink /d {{link name}} {{target folder}} 

Sunday, June 1, 2014

using postgres for ruby development


It is required to install the development components of postgres

Ubuntu:
apt-get install postgresql libpq-dev

Sunday, May 11, 2014

Install gem from github




Not verified solution
gem specific_install -l https://github.com/{{username}}/{{gemname}}.git -b {{branchname}}

Monday, April 14, 2014

Ruby: Print first 10 lines from a URI page


require "open-uri"
open("http://www.google.com") { |f| f.each_line{ |line| puts line if f.lineno.between? 1, 10 } }

To print line numbers:
open("http://www.google.com") { |f| f.each_line{ |line| puts "#{f.lineno.to_s.rjust(3,'0')}:#{line}" if f.lineno.between?  1,5 } }