Search This Blog

Wednesday, February 23, 2011

mysql insert ignore on duplicate key

INSERT IGNORE INTO all_cas (CAS, sid, source)
( SELECT DISTINCT(cas), mid, 4 FROM chemmolpharm.compounds WHERE cas REGEXP '[0-9]{2,7}-[0-9]{1,2}-[0-9]{1}' );

mysql update comments to table

ALTER TABLE all_cas COMMENT='source 1 aaa 2 ChemMol.com' ;

mysql "ERROR 1018 (HY000): Can't read dir of '.' (errno: 13)"

issue:

mysql "ERROR 1018 (HY000): Can't read dir of '.' (errno: 13)"

Solution
Restart mysql server
root@cm-test:~# service mysql stop
root@cm-test:~# service mysql start

ls ll with regular express

#!/bin/bash

for f in $(ls | egrep 'mysql-bin.0[0-9]{5}$')
do
echo "process file: $f"
done



[root@localhost recovery]# ll mysql-bin.0[0-9][0-9][0-9][0-9][0-9]
-rw-r----- 1 root root 23022429 Feb 23 06:13 mysql-bin.000001
-rw-r----- 1 root root 456769 Feb 23 06:13 mysql-bin.000002
-rw-r----- 1 root root 47295 Feb 23 06:13 mysql-bin.000003
-rw-r----- 1 root root 679680 Feb 23 06:13 mysql-bin.000004
-rw-r----- 1 root root 1742441 Feb 23 06:13 mysql-bin.000005
-rw-r----- 1 root root 5671825 Feb 23 06:13 mysql-bin.000006
-rw-r----- 1 root root 5588178 Feb 23 06:13 mysql-bin.000007
-rw-r----- 1 root root 5312684 Feb 23 06:13 mysql-bin.000008
-rw-r----- 1 root root 5569825 Feb 23 06:13 mysql-bin.000009
-rw-r----- 1 root root 5653535 Feb 23 06:13 mysql-bin.000010
-rw-r----- 1 root root 5361382 Feb 23 06:13 mysql-bin.000011
-rw-r----- 1 root root 5722384 Feb 23 06:13 mysql-bin.000012
-rw-r----- 1 root root 5759352 Feb 23 06:13 mysql-bin.000013
-rw-r----- 1 root root 6006372 Feb 23 06:13 mysql-bin.000014
-rw-r----- 1 root root 5645165 Feb 23 06:13 mysql-bin.000015
-rw-r----- 1 root root 5508167 Feb 23 06:13 mysql-bin.000016
-rw-r----- 1 root root 6258305 Feb 23 06:13 mysql-bin.000017
-rw-r----- 1 root root 5959473 Feb 23 06:13 mysql-bin.000018
-rw-r----- 1 root root 5743501 Feb 23 06:13 mysql-bin.000019
-rw-r----- 1 root root 5618976 Feb 23 06:13 mysql-bin.000020
-rw-r----- 1 root root 4157667 Feb 23 06:13 mysql-bin.000021
[root@localhost recovery]# ll | egrep "mysql-bin.0[0-9]{5}$"
-rw-r----- 1 root root 23022429 Feb 23 06:13 mysql-bin.000001
-rw-r----- 1 root root 456769 Feb 23 06:13 mysql-bin.000002
-rw-r----- 1 root root 47295 Feb 23 06:13 mysql-bin.000003
-rw-r----- 1 root root 679680 Feb 23 06:13 mysql-bin.000004
-rw-r----- 1 root root 1742441 Feb 23 06:13 mysql-bin.000005
-rw-r----- 1 root root 5671825 Feb 23 06:13 mysql-bin.000006
-rw-r----- 1 root root 5588178 Feb 23 06:13 mysql-bin.000007
-rw-r----- 1 root root 5312684 Feb 23 06:13 mysql-bin.000008
-rw-r----- 1 root root 5569825 Feb 23 06:13 mysql-bin.000009
-rw-r----- 1 root root 5653535 Feb 23 06:13 mysql-bin.000010
-rw-r----- 1 root root 5361382 Feb 23 06:13 mysql-bin.000011
-rw-r----- 1 root root 5722384 Feb 23 06:13 mysql-bin.000012
-rw-r----- 1 root root 5759352 Feb 23 06:13 mysql-bin.000013
-rw-r----- 1 root root 6006372 Feb 23 06:13 mysql-bin.000014
-rw-r----- 1 root root 5645165 Feb 23 06:13 mysql-bin.000015
-rw-r----- 1 root root 5508167 Feb 23 06:13 mysql-bin.000016
-rw-r----- 1 root root 6258305 Feb 23 06:13 mysql-bin.000017
-rw-r----- 1 root root 5959473 Feb 23 06:13 mysql-bin.000018
-rw-r----- 1 root root 5743501 Feb 23 06:13 mysql-bin.000019
-rw-r----- 1 root root 5618976 Feb 23 06:13 mysql-bin.000020
-rw-r----- 1 root root 4157667 Feb 23 06:13 mysql-bin.000021

mysql show variables

mysql> show variables like '%bin%';
+-----------------------------------------+------------+
| Variable_name | Value |
+-----------------------------------------+------------+
| binlog_cache_size | 32768 |
| binlog_direct_non_transactional_updates | OFF |
| binlog_format | MIXED |
| innodb_locks_unsafe_for_binlog | OFF |
| log_bin | ON |
| log_bin_trust_function_creators | OFF |
| log_bin_trust_routine_creators | OFF |
| max_binlog_cache_size | 4294963200 |
| max_binlog_size | 1073741824 |
| sql_log_bin | ON |
| sync_binlog | 0 |
+-----------------------------------------+------------+
11 rows in set (0.00 sec)

mysql truncate multiple tables

mysql> select concat('TRUNCATE TABLE ', TABLE_NAME, ';') from INFORMATION_SCHEMA.TABLES where TABLE_SCHEMA='amp';

centos update path

echo 'export PATH=$PATH:/sbin' >> $HOME/.bash_profile

How to create a Directory with permission of drwxrwxrwt

t mean Sticky bit. It was used to trigger process to "stick" in memory after it is finished, now this usage is obsolete. Currently its use is system dependant and it is mostly used to suppress deletion of the files that belong to other users in the folder where you have "write" access to.

chmod +t mydir