Thursday, March 17, 2016

Converting Timezone-Specific Times in MySQL

Use below MySQL function to convert one timezone to another timezone.

Ex:

SELECT CONVERT_TZ(now(),'UTC','Europe/paris') as d;

SELECT CONVERT_TZ(now(),''US/Eastern','US/Central') as d;

Wednesday, March 9, 2016

LOAD DATA INFILE Error Code : 13 - When using mysqlimport command in ubuntu

mysqlimport: Error: 29, File '/CSVFile' not found (Errcode: 13 - Permission denied), when using table: TableName


  • This error occurs due to the permission issue. 
  • I used following steps to resolve this issue. 

1. Execute sudo aa-status command to check MySQL's profile is in enforcing mode.Because in recent Ubuntu server editions ship with AppArmor and MySQL's profile might be in enforcing mode by default.
What is AppArmor?
("Application Armor") is a Linux kernel security module that allows the system administrator to restrict programs's capabilities with per-program profiles. Profiles can allow capabilities like network access, raw socket access, and the permission to read, write, or execute files on matching paths.
# sudo aa-status
5 profiles are loaded.
5 profiles are in enforce mode.
   /usr/lib/connman/scripts/dhclient-script
   /sbin/dhclient3
   /usr/sbin/tcpdump
   /usr/lib/NetworkManager/nm-dhcp-client.action
   /usr/sbin/mysqld
0 profiles are in complain mode.
1 processes have profiles defined.
1 processes are in enforce mode :
   /usr/sbin/mysqld (1089)
0 processes are in complain mode.
If mysqld is included in enforce mode, then it is the one probably denying the write. Entries would also be written in /var/log/messages when AppArmor blocks the writes/accesses. What you can do is edit /etc/apparmor.d/usr.sbin.mysqld and add /data/ and /data/* near the bottom like so:
I have added  /home/charith/* r,   entry in to the file. Upload the csv file to the /home/charith/ directory and 
...
/usr/sbin/mysqld {
    ...
    /var/log/mysql/ r,
    /var/log/mysql/* rw,
    /var/run/mysqld/mysqld.pid w,
    /var/run/mysqld/mysqld.sock w,
    /data/ r,
    /data/* rw,
 /home/charith/* r,  
}
And then make AppArmor reload the profiles.
# sudo /etc/init.d/apparmor reload
WARNING: the change above will allow MySQL to read and write to the /data directory. We hope you've already considered the security implications of this.

Import CSV File Into MySQL Table in Ubuntu server

These are the steps that i followed to import a CSV data file to MySQL database


  • Create a table in MySQL database. CSV file name should be equivalent to the table name that you are going to import.  
EX: Table name is : PS_EMPLIDS
  • Execute following command  

Command to import csv file to MySQL :
mysqlimport --user=mysqlUsername --password=mysqlPassword --ignore-lines=1 databaseName ~/PS_EMPLIDS.csv


References:
http://dev.mysql.com/doc/refman/5.6/en/mysqlimport.html

Wednesday, January 27, 2016

Solution for [RuntimeException] The HOME or COMPOSER_HOME environment variable must be set for composer to run correctly - AWS Elastic beanstalk

Recently we got this error while we deploying our PHP Symfony2 application to AWS via elastic beanstalk environment.

Root cause for this issue

  • Composer have made a change in which they have deprecated COMPOSER_HOME
Solution 1:

The quick fix is to COMPOSER_HOME to HOME.

commands:
  01_update_composer:
    command: export HOME=/root && /usr/bin/composer.phar self-update

option_settings:
  - namespace: aws:elasticbeanstalk:application:environment
    option_name: HOME
    value: /root


Solution 2: 

Another option on a new instance is to lock the composer version.

Here is an example ebextension:

commands:
  01_update_composer:
    command: export HOME=/root && export COMPOSER_HOME=/root && /usr/bin/composer.phar self-update 1.0.0-alpha11

option_settings:
  - namespace: aws:elasticbeanstalk:application:environment
    option_name: COMPOSER_HOME
    value: /root
  - namespace: aws:elasticbeanstalk:application:environment
    option_name: HOME
    value: /root
 

 





Sunday, February 2, 2014

How to enable GD Library support for PHP in Windows server

To enable GD Library support for PHP on Windows server, follow the below mentioned steps:
  1. First of all, make sure that php_gd2.dll file is present into the directory identified as extension directory in PHP folder.
  2. If the above file is not present then you need to download it from http://php.net/ and copy in the extension directory of PHP folder.
  3. If the file is already present then you need to enable php_gd2.dll extension from php.ini configuration file.
  4. You can verify extension-dir through PHPINFO page. Following is the code for PHPINFO Page:
    phpinfo();
    ?>
After performing all these steps, restart the IIS web server.

Tuesday, September 17, 2013

To Reload Code or Deployment Descriptor Changes in Sun GlassFish Enterprise Server 2.1

  • Create an empty file named .reload at the root of the deployed application or module.

    For an application:
    domain-dir/applications/j2ee-apps/app-name/.reload

    For an individually deployed module:
    domain-dir/applications/j2ee-modules/module-name/.reload
    
    

  • Explicitly update the .reload file’s timestamp (touch .reload in UNIX) each time you make changes.
  • Sunday, August 25, 2013

    Solution for BeanCreationException with Spring and Jackson API

    Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.springframework.http.converter.json.MappingJacksonHttpMessageConverter]: Constructor threw exception; nested exception is java.lang.VerifyError: Cannot inherit from final class


    2013-08-25T15:57:49.981+0800|SEVERE|sun-appserver2.1|javax.enterprise.system.container.web|_ThreadID=22;_ThreadName=RMI TCP Connection(52)-137.132.6.49;_RequestID=4fdf798f-47c0-42bd-9c9c-e4e6f9b8478b;|WebModule[/myapp]PWC1275: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener
    org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter#0': Cannot create inner bean '(inner bean)' of type [org.springframework.http.converter.json.MappingJacksonHttpMessageConverter] while setting bean property 'messageConverters' with key [6]; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)#8': Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.springframework.http.converter.json.MappingJacksonHttpMessageConverter]: Constructor threw exception; nested exception is java.lang.VerifyError: Cannot inherit from final class
        at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveInnerBean(BeanDefinitionValueResolver.java:281)
        at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:125)
        at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveManagedList(BeanDefinitionValueResolver.java:353)
        at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:153)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1327)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1085)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:516)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:455)
        at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:293)
        at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
        at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:290)
        at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:192)
        at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:585)
        at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:895)
        at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:425)
        at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:282)
        at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:204)
        at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:47)
        at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4655)
        at org.apache.catalina.core.StandardContext.start(StandardContext.java:5364)
        at com.sun.enterprise.web.WebModule.start(WebModule.java:345)
        at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:986)
        at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:970)
        at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:704)
        at com.sun.enterprise.web.WebContainer.loadWebModule(WebContainer.java:1649)
        at com.sun.enterprise.web.WebContainer.loadWebModule(WebContainer.java:1254)
        at com.sun.enterprise.server.WebModuleDeployEventListener.moduleDeployed(WebModuleDeployEventListener.java:182)
        at com.sun.enterprise.server.WebModuleDeployEventListener.moduleDeployed(WebModuleDeployEventListener.java:278)
        at com.sun.enterprise.admin.event.AdminEventMulticaster.invokeModuleDeployEventListener(AdminEventMulticaster.java:1005)
        at com.sun.enterprise.admin.event.AdminEventMulticaster.handleModuleDeployEvent(AdminEventMulticaster.java:992)
        at com.sun.enterprise.admin.event.AdminEventMulticaster.processEvent(AdminEventMulticaster.java:470)
        at com.sun.enterprise.admin.event.AdminEventMulticaster.multicastEvent(AdminEventMulticaster.java:182)
        at com.sun.enterprise.ee.admin.mbeans.ServerRuntimeMBean.forwardEvent(ServerRuntimeMBean.java:95)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at com.sun.enterprise.admin.MBeanHelper.invokeOperationInBean(MBeanHelper.java:390)
        at com.sun.enterprise.admin.MBeanHelper.invokeOperationInBean(MBeanHelper.java:373)
        at com.sun.enterprise.admin.runtime.BaseRuntimeMBean.invoke(BaseRuntimeMBean.java:468)
        at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(DefaultMBeanServerInterceptor.java:836)
        at com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(JmxMBeanServer.java:761)
        at sun.reflect.GeneratedMethodAccessor6.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at com.sun.enterprise.admin.util.proxy.ProxyClass.invoke(ProxyClass.java:90)
        at $Proxy1.invoke(Unknown Source)
        at com.sun.enterprise.admin.server.core.jmx.SunoneInterceptor.invoke(SunoneInterceptor.java:304)
        at com.sun.enterprise.interceptor.DynamicInterceptor.invoke(DynamicInterceptor.java:170)
        at javax.management.remote.rmi.RMIConnectionImpl.doOperation(RMIConnectionImpl.java:1427)
        at javax.management.remote.rmi.RMIConnectionImpl.access$200(RMIConnectionImpl.java:72)
        at javax.management.remote.rmi.RMIConnectionImpl$PrivilegedOperation.run(RMIConnectionImpl.java:1265)
        at javax.management.remote.rmi.RMIConnectionImpl.doPrivilegedOperation(RMIConnectionImpl.java:1360)
        at javax.management.remote.rmi.RMIConnectionImpl.invoke(RMIConnectionImpl.java:788)
        at sun.reflect.GeneratedMethodAccessor139.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:305)
        at sun.rmi.transport.Transport$1.run(Transport.java:159)
        at java.security.AccessController.doPrivileged(Native Method)
        at sun.rmi.transport.Transport.serviceCall(Transport.java:155)
        at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:535)
        at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:790)
        at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:649)
        at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
        at java.lang.Thread.run(Thread.java:619)
    Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)#8': Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.springframework.http.converter.json.MappingJacksonHttpMessageConverter]: Constructor threw exception; nested exception is java.lang.VerifyError: Cannot inherit from final class
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:964)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:910)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:484)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:455)
        at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveInnerBean(BeanDefinitionValueResolver.java:270)
        ... 66 more
    Caused by: org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.springframework.http.converter.json.MappingJacksonHttpMessageConverter]: Constructor threw exception; nested exception is java.lang.VerifyError: Cannot inherit from final class
        at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:141)
        at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:74)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:957)
        ... 70 more
    Caused by: java.lang.VerifyError: Cannot inherit from final class
        at java.lang.ClassLoader.defineClass1(Native Method)
        at java.lang.ClassLoader.defineClassCond(ClassLoader.java:632)
        at java.lang.ClassLoader.defineClass(ClassLoader.java:616)
        at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)
        at org.apache.catalina.loader.WebappClassLoader.findClass(WebappClassLoader.java:983)
        at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1503)
        at org.springframework.http.converter.json.MappingJacksonHttpMessageConverter.(MappingJacksonHttpMessageConverter.java:56)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
        at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
        at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:126)
        ... 72 more


    Solution

    * The correct version dependency of Jackson for Spring 3.0.6 is 1.4.2(per Spring's pom), try replacing 1.8.9 with this version, it should work correctly.

    Download jackson-mapper-asl-1.4.2.jar from http://www.java2s.com/Code/Jar/j/Downloadjacksonmapperasl142jar.htm