Thursday, January 20, 2011

dump mysql table to csv file

1, Login to mysql terminal:
c@cm-test:~$ mysql -u xxxxxx -pxxxxxxx mydatabase

2, run:
mysql> select * into OUTFILE 'abc.CSV' FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"' LINES TERMINATED BY '\n' FROM excel_unique;

3, the file should be in
/mydisk/lib/mysql/mydatabase/abc.CSV

Friday, January 14, 2011

Thursday, January 13, 2011

get table info

method 1:
mysql> show create table xxxxxxxxx;
+-----------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Table | Create Table |
+-----------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| compounds | CREATE TABLE `xxxxx` (
`mol_id` int(10) NOT NULL AUTO_INCREMENT,
`uid` int(10) DEFAULT NULL,
`ucid` varchar(255) DEFAULT NULL,
`CASNumber` varchar(255) DEFAULT NULL,
`CName` varchar(255) DEFAULT NULL,
`SubstanceID` varchar(255) DEFAULT NULL,
`MF` varchar(255) DEFAULT NULL,
PRIMARY KEY (`mol_id`),
UNIQUE KEY `CAS` (`CASNumber`)
) ENGINE=MyISAM AUTO_INCREMENT=49400000 DEFAULT CHARSET=latin1 CHECKSUM=1 DELAY_KEY_WRITE=1 ROW_FORMAT=DYNAMIC |
+-----------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)

mysql>

method 2:
mysql> select * from information_schema.tables WHERE table_name='table_name' and TABLE_SCHEMA='db_name';

+---------------+--------------------+------------+------------+--------+---------+------------+------------+----------------+-------------+-----------------+--------------+-----------+----------------+---------------------+---------------------+------------+-------------------+----------+-------------------------------------------------+---------------+
| TABLE_CATALOG | TABLE_SCHEMA | TABLE_NAME | TABLE_TYPE | ENGINE | VERSION | ROW_FORMAT | TABLE_ROWS | AVG_ROW_LENGTH | DATA_LENGTH | MAX_DATA_LENGTH | INDEX_LENGTH | DATA_FREE | AUTO_INCREMENT | CREATE_TIME | UPDATE_TIME | CHECK_TIME | TABLE_COLLATION | CHECKSUM | CREATE_OPTIONS | TABLE_COMMENT |
+---------------+--------------------+------------+------------+--------+---------+------------+------------+----------------+-------------+-----------------+--------------+-----------+----------------+---------------------+---------------------+------------+-------------------+----------+-------------------------------------------------+---------------+
| NULL | xxxxx | compounds | BASE TABLE | MyISAM | 10 | Dynamic | 0 | 0 | 0 | 281474976710655 | 2048 | 0 | 49400000 | 2011-01-13 16:10:20 | 2011-01-13 16:10:20 | NULL | latin1_swedish_ci | 0 | checksum=1 delay_key_write=1 row_format=DYNAMIC | |
+---------------+--------------------+------------+------------+--------+---------+------------+------------+----------------+-------------+-----------------+--------------+-----------+----------------+---------------------+---------------------+------------+-------------------+----------+-------------------------------------------------+---------------+
1 row in set (0.00 sec)

mysql reset auto_increment

alter table compounds auto_increment=49400000;

Tuesday, January 11, 2011

import openssl key to tomcat

1. Generate a self-signed certificate (or CA trusted certificate if needed)
1) Generate a private key
openssl genrsa -des3 -out es.key 2048
2) Generate a CSR
openssl req -new -key es.key -out es.csr
 3) Generate a self-signed certificate
openssl x509 -req -days 3650 -in es.csr -signkey es.key -out es.crt

2, Import the SSL Ceritificate into PKCS#12 keystore:
openssl pkcs12 -export -in es.crt -inkey es.key -out es.p12 -name es_tomcat

3, list privatekeyentry
keytool -list -v -keystore es.p12 -storetype pkcs12

4,Import CA/cacert.crt into the Java cacerts, so that the tomcat install can talk to itself if needed.
keytool -import -keystore es.keystore -file es.crt

5, Covert the PKCS#12 keystore to JKS keystore
keytool -importkeystore -srckeystore es.p12 -destkeystore es.jks -srcstoretype pkcs12

keytool -list -v -keystore es.jks

6 update server.xml
vim /opt/tomcat/conf/server.xml




cat /dev/null > /opt/tomcat/logs/catalina.out
/etc/init.d/tomcat stop
cat /dev/null > /opt/tomcat/logs/catalina.out
/etc/init.d/tomcat start
less /opt/tomcat/logs/catalina.out

Friday, January 7, 2011

Thursday, January 6, 2011

clear mysql-bin log file or disable mysql bin log

Step 1,
Go to folder
/var/lib/mysql

Step 2:
Run:
[root@localhost mysql]# mysqladmin -u xxxx -pxxxx flush-logs

Mysql will create a new bin-log file - for my server it is mysql-bin.000014
-rw-rw---- 1 mysql mysql 22770974 Jan 6 04:02 mysql-bin.000011
-rw-rw---- 1 mysql mysql 79427070 Jan 6 04:04 mysql-bin.000012
-rw-rw---- 1 mysql mysql 109593 Jan 6 04:07 mysql-bin.000013
-rw-rw---- 1 mysql mysql 1318 Jan 6 04:07 mysql-bin.000014
-rw-rw---- 1 mysql mysql 266 Jan 6 04:07 mysql-bin.index

Step 3:
You can delete all mysql-bin log file except the latest one.
Here is the sample:
rm mysql-bin.000004 -f
rm mysql-bin.000005 -f
rm mysql-bin.000006 -f
rm mysql-bin.000007 -f
rm mysql-bin.00000* -f


Delete mysql bin log file older than 2 days
find /var/lib/mysql/mysql-bin.* -mtime +2 -exec rm {} \;