Error establishing a database connection EC2 Amazon

I hope you can help me. I can not stand having to keep restarting my ec2 instance on Amazon.

I have two wordpress sites hosted there. My sites have always worked well until two months ago, one of them started having this problem. I tried all ways pack up, and the only solution was to reconfigure.

Read More

Now that all was right with the two. The second site started the same problem. I think Amazon is clowning me.

I am using a free micro instance. If anyone knows what the problem is, please help me!

Related posts

Leave a Reply

1 comment

  1. Your issue will be the limited memory that is allocated to the T1 Micro instances in EC2. I’m assuming you are using ANI Linux in this case and if an alternate version of Linux is used then you may have different locations for your log and config files.

    Make sure you are the root user.

    Have a look at your MySQL logs in the following location:

    /var/log/mysqld.log
    

    If you see repeated instances of the following it’s pretty certain that the 0.6GB of memory allocated to the micro instance is not cutting it.

    150714 22:13:33 InnoDB: Initializing buffer pool, size = 12.0M
    InnoDB: mmap(12877824 bytes) failed; errno 12
    150714 22:13:33 InnoDB: Completed initialization of buffer pool
    150714 22:13:33 InnoDB: Fatal error: cannot allocate memory for the buffer pool
    150714 22:13:33 [ERROR] Plugin 'InnoDB' init function returned error.
    150714 22:13:33 [ERROR] Plugin 'InnoDB' registration as a STORAGE ENGINE failed.
    150714 22:13:33 [ERROR] Unknown/unsupported storage engine: InnoDB
    150714 22:13:33 [ERROR] Aborting
    

    You will notice in the log excerpt above that my buffer pool size is set to 12MB. This can be configured by adding the line innodb_buffer_pool_size = 12M to your MySQL config file /etc/my.cnf.

    A pretty good way to deal with InnoDB chewing up your memory is to create a swap file.
    Start by checking the status of your memory:

    free -m
    

    You will most probably see that your swap is not doing much:

                 total       used       free     shared    buffers     cached
    Mem:           592        574         17          0         15        235
    -/+ buffers/cache:        323        268
    Swap:            0          0          0
    

    To start ensure you are logged in as the root user and run the following command:

    dd if=/dev/zero of=/swapfile bs=1M count=1024
    

    Wait for a bit as the command is not verbose but you should see the following response after about 15 seconds when the process is complete:

    1024+0 records in
    1024+0 records out
    1073741824 bytes (1.1 GB) copied, 31.505 s, 34.1 MB/s
    

    Next set up the swapspace with:

    mkswap /swapfile
    

    Now set up the swap event:

    swapon /swapfile
    

    If you get a permissions response you can ignore it or address the swap file by changing the permissions to 600 with the chmod command.

    chmod 600 /swapfile
    

    Now add the following line to /etc/fstab to create the swap spaces on server start:

    /swapfile swap swap defaults 0 0
    

    Restart your MySQL instance:

    service mysqld restart
    

    Finally check to see if your swap file is working correctly with the free -m command.
    You should see something like:

                 total       used       free     shared    buffers     cached
    Mem:           592        575         16          0         16        235
    -/+ buffers/cache:        323        269
    Swap:         1023          0       1023
    

    Hope this helps.