Thursday, January 28, 2016

Percona XtraDB Cluster : [ERROR] WSREP: Could not open state file for writing: '/var/lib/mysql//grastate.dat'. Check permissions and/or disk space.: 13 (Permission denied)

After transfer snapshot of Percona XtraDB Cluster I received below error:
2016-01-29 06:57:18 20161 [Warning] WSREP: Could not open state file for reading: '/var/lib/mysql//grastate.dat'
2016-01-29 06:57:18 20161 [ERROR] WSREP: Could not open state file for writing: '/var/lib/mysql//grastate.dat'. Check permissions and/or disk space.: 13 (Permission denied)
         at galera/src/saved_state.cpp:SavedState():49
2016-01-29 06:57:18 20161 [ERROR] WSREP: wsrep::init() failed: 7, must shutdown
2016-01-29 06:57:18 20161 [ERROR] Aborting
turns out chxmod 660 or 666 or 777 didn't help and the reason was the mysql folder ownership was root instead of mysql, so to fix it:
chown -R mysql:mysql /var/lib/mysql/

Wednesday, January 27, 2016

Erase Replication and Slave Settings and Data on MySQL slave

To erase all replication data on MySQL you can do: MySQL 5.0 and 5.1:
STOP SLAVE;
CHANGE MASTER TO MASTER_HOST='';
MySQL 5.5 and 5.6:
STOP SLAVE;
RESET SLAVE ALL;
example:
mysql> show slave status\G
*************************** 1. row ***************************
               Slave_IO_State:
                  Master_Host: SOMEHOST
                  Master_User: MASTER_USER
                  Master_Port: 3306
                Connect_Retry: 60
              Master_Log_File:
          Read_Master_Log_Pos: 4
               Relay_Log_File: mysql-relay-bin.000004
                Relay_Log_Pos: 2949
        Relay_Master_Log_File:
             Slave_IO_Running: No
            Slave_SQL_Running: No
              Replicate_Do_DB: 
          Replicate_Ignore_DB:
           Replicate_Do_Table:
       Replicate_Ignore_Table:
      Replicate_Wild_Do_Table:
  Replicate_Wild_Ignore_Table:
                   Last_Errno: 0
                   Last_Error:
                 Skip_Counter: 0
          Exec_Master_Log_Pos: 0
              Relay_Log_Space: 0
              Until_Condition: None
               Until_Log_File:
                Until_Log_Pos: 0
           Master_SSL_Allowed: No
           Master_SSL_CA_File:
           Master_SSL_CA_Path:
              Master_SSL_Cert:
            Master_SSL_Cipher:
               Master_SSL_Key:
        Seconds_Behind_Master: NULL
Master_SSL_Verify_Server_Cert: No
                Last_IO_Errno: 0
                Last_IO_Error:
               Last_SQL_Errno: 0
               Last_SQL_Error:
  Replicate_Ignore_Server_Ids:
             Master_Server_Id: 0
                  Master_UUID: 0b505dc2-c3e3-11e5-8adf-000c292bd8a9
             Master_Info_File: mysql.slave_master_info
                    SQL_Delay: 0
          SQL_Remaining_Delay: NULL
      Slave_SQL_Running_State:
           Master_Retry_Count: 86400
                  Master_Bind:
      Last_IO_Error_Timestamp:
     Last_SQL_Error_Timestamp:
               Master_SSL_Crl:
           Master_SSL_Crlpath:
           Retrieved_Gtid_Set:
            Executed_Gtid_Set: c042d2a4-3ba4-ee1a-69aa-b4b5a00d8fe3:1-2027
                Auto_Position: 0
1 row in set (0.00 sec)

mysql> reset slave all;
Query OK, 0 rows affected (0.00 sec)

mysql> show slave status;
Empty set (0.00 sec)
Remember that "RESET SLAVE" only reset the replication "Exec_Master_Log_Pos", " Read_Master_Log_Pos" and "binlog".

Sunday, January 24, 2016

Disable Apache Folder Listing (for all website) or Enable listing for specified Download folder (as exception)

Default setting in Apache allows folder listing, which is not safe or secure and you may want to take below approach to change this setting.
A) "The best" approach is insert or change default tag within /etc/httpd/conf/httpd.conf as below:
<Directory />
    Options -Indexes
    AllowOverride All
</Directory>

B) It can be enabled or disabled by inserting below tag in .htaccess file at the website root or specified folder for example for Download and repository folder which user can select which file he/she wishes to download.
echo 'Options -Indexes' > /var/www/html/.htaccess

C) To do it website specific httpd.conf settings:
<VirtualHost *:80>
 Options -Indexes
 ServerName somewebsite.com
 ServerAlias www.somewebsite.com
 DocumentRoot /var/www/somewebsite.com
</VirtualHost>

Compress File or Folder using tar and xz tool (Multi threaded)

To compress a folder, first navigate to subfolder using "cd" and isue below command the new 5.X version support multi-threading thus multi cpu by "-T number_of_cpu" syntax
tar -cf - src_folder/ | xz -T 6 -9 -c - > /tmp/src_folder.tar.xz 

Saturday, January 23, 2016

Percona Server 5.6 to MYSQL 5.6 Replication Error: 1677 - Column 1 of table 'XXXXX.XXXXX' cannot be converted from type 'timestamp' to type 'timestamp'

You may get below error when replicating from Percona 5.6 to Mysql 5.6


mysql> show slave status\G
*************************** 1. row ***************************
               Slave_IO_State: Waiting for master to send event
                  Master_Host: 10.1.2.230
                  Master_User: ut_user
                  Master_Port: 3306
                Connect_Retry: 60
              Master_Log_File: mysql-bin.000001
          Read_Master_Log_Pos: 7640733
               Relay_Log_File: mysqld-relay-bin.000002
                Relay_Log_Pos: 279
        Relay_Master_Log_File: mysql-bin.000001
             Slave_IO_Running: Yes
            Slave_SQL_Running: No
              Replicate_Do_DB:
          Replicate_Ignore_DB:
           Replicate_Do_Table:
       Replicate_Ignore_Table:
      Replicate_Wild_Do_Table:
  Replicate_Wild_Ignore_Table:
                   Last_Errno: 1677
                   Last_Error: Column 1 of table 'XXXXX.XXXXX' cannot be converted from type 'timestamp' to type 'timestamp'
                 Skip_Counter: 0
          Exec_Master_Log_Pos: 120
              Relay_Log_Space: 1885
              Until_Condition: None
               Until_Log_File:
                Until_Log_Pos: 0
           Master_SSL_Allowed: No
           Master_SSL_CA_File:
           Master_SSL_CA_Path:
              Master_SSL_Cert:
            Master_SSL_Cipher:
               Master_SSL_Key:
        Seconds_Behind_Master: NULL
Master_SSL_Verify_Server_Cert: No
                Last_IO_Errno: 0
                Last_IO_Error:
               Last_SQL_Errno: 1677
               Last_SQL_Error: Column 1 of table 'XXXXX.XXXXX' cannot be converted from type 'timestamp' to type 'timestamp'
  Replicate_Ignore_Server_Ids:
             Master_Server_Id: 130
                  Master_UUID: e1d58117-750e-11e3-ae17-XXXXXXXXXXXXX
             Master_Info_File: /var/lib/mysql/master.info
                    SQL_Delay: 0
          SQL_Remaining_Delay: NULL
      Slave_SQL_Running_State:
           Master_Retry_Count: 86400
                  Master_Bind:
      Last_IO_Error_Timestamp:
     Last_SQL_Error_Timestamp: 140105 03:11:27
               Master_SSL_Crl:
           Master_SSL_Crlpath:
           Retrieved_Gtid_Set:
            Executed_Gtid_Set:
                Auto_Position: 0
1 row in set (0.00 sec)

My solution: Uninstall MySQL 5.6 and install XtraDB standalone or Percona Server using the same my.cnf and data directory

MySQL error on Grant: ERROR 1221 (HY000): Incorrect usage of DB GRANT and GLOBAL PRIVILEGES


When doing below grant:
mysql> GRANT SELECT, INSERT, UPDATE, DELETE, FILE ON ut_sipreg.* TO 'voip04my_sipreg'@'localhost' REQUIRE NONE WITH MAX_QUERIES_PER_HOUR 0 MAX_CONNECTIONS_PER_HOUR 0 MAX_UPDATES_PER_HOUR 0 MAX_USER_CONNECTIONS 0;

I received below error:
ERROR 1221 (HY000): Incorrect usage of DB GRANT and GLOBAL PRIVILEGES

To fix it, I had to take out "FILE" from permission list:
mysql> GRANT SELECT, INSERT, UPDATE, DELETE ON ut_sipreg.* TO 'voip04my_sipreg'@'localhost' REQUIRE NONE WITH MAX_QUERIES_PER_HOUR 0 MAX_CONNECTIONS_PER_HOUR 0 MAX_UPDATES_PER_HOUR 0 MAX_USER_CONNECTIONS 0;
Query OK, 0 rows affected (0.01 sec)