FIX: WordPress error establishing a database connection problem

Source: Internet
Author: User
Tags call back vps virtual private server

I am a website rookie, just started to build lamp environment, it will be half my dead.

No way, understand things too little, lamp is what I do not understand, domain name is what, I also was not understand, why want to have a website will have server I still do not understand. Step by step to drill yourself, to see Digitalocean to the Instruction tutorial. I understand it slowly.

The configuration of my VPS (Virtual Private server) is LOW,CPU only 512m--

The first solution to this problem is to restart my server

-K  Restart

The above two code with the fly, in fact, if the database crash, the following two commands should be OK

Systemctl Start Mariadbsystemctl Status mariadb

Okay, here's the problem. At first, I found the error establishing the question, and I didn't know what was going on. Later these days learned a bit about MySQL configuration. First, I want to describe the steps to solve the problem.

1, found the error establishing a database connection problem--a little Google will know that it is the problem of databases

2, to check the database of the Err log MySQL. The exact location should be under/var/log.

3, after checking I found out is out of Memory,cannot allocate InnoDB buffer pool=128m (memory only 512M you let me do) the question of

4, Google a bit, there are two ways to solve this problem:

One way to do this is to add swap files (more on swap space and how to add them below): Digitalocean's Add swapfile tutorial

There is also the need to modify your Innodb_buffer_pool_size (detailed below)

Swap space:

The swap partition frees up some of the space in the hard disk space when the system's physical memory is not available for use by the currently running program. The freed space may come from programs that have not been manipulated for a long time, and the freed space is temporarily saved to the swap partition until those programs are run and the saved data is restored to memory from the swap partition.

First of all, how the swap works: Swap work can be seen as a static relay device. If our memory is 512M. When there is a task coming but because the previous tasks and concurrent tasks occupy a lot of work space, so that the work is more than 512M of space, it will lead to startup failure. Because there is no place for it. This time, many engineers and technical cows invented the swap space, the technology of virtual memory. The swap space is actually on the hard drive. The principle of work is: when we have a task to come, found that the physical memory space is not enough, then we have the user opened but often unused space to release, and some of their information into the swap space. Then give this later program to use the physical memory space first, when I want to use the previous program, we then from the swap space to the previous saved content call back. Two ways to increase the swap space: the first is to create a swap partition, the second is to create a swap file, here we introduce the second relatively simple method 1, to see if there is no already configured swap space, use the following command to see the swap space usage
Swapon-s

If you have not configured swap space, found to knock over the above command, nothing, if you configured, will appear below, I configured on my VPS is 4G:

Another way is to use free, which shows the overall memory usage of the system:

Free-m

2, check the available hard disk space, because the swap space is actually to use the hard disk space, so, of course, you want to see how many hard drives are available

Df-h

3. Create a swap file and change its permissions

sudo fallocate-l 4g/swapfile

We check permissions for this file

-rw-r--r--1 root root 4.0G Oct 11:00/swapfile

Will find that the readable permission of this file is developed for anyone, so it is very insecure, so we have to change the permissions of this file

sudo chmod 600/swapfile
-RW-------1 root root 4.0G Oct 11:00/swapfile

Well, that's a lot safer.

4. Use this swap file

Use this command to tell the system that we're going to take this file as a swap file.

sudo mkswap/swapfile
Setting up Swapspace version 1, size = 4194300 kibno label, UUID=B99230BB-21AF-47BC-8C37-DE41129C39BF

Then it's going to use this swap file:

Swapon-s

Filename                Type        Size    used    priority/swapfile               file        4194300 0     -1

We then use the FREE-M command to view the memory usage:

Found this swap file is OK!

5. Make this new swap file permanent and effective when the system starts, so we'll add the following line to the/ect/fstab file

Open the file with VI first, then add the following line, and then save it.

sudo vi/etc/fstab

/swapfile   swap    swap    SW  0   0

Modify Innodb_buffer_pool_size:

My VPS is loaded with MARIADB (15 mariadb performance tuning methods). It has four configuration files--each of which is under/etc:

MY.CNF.D is a folder: (There are three files, ignoring the bakup file, I modified the sever backup)

Then go to/usr/share/mysql inside, there will be some example configuration files, copy a copy over, my VPS configuration, I chose medium that file

Then restart MARIADB

Systemctl Restart MARIADB

Let's see if Innodb_buffer_pool_size has been modified.

View method: Go inside MySQL, then select the variable below.

- -P

MySQL > SELECT @ @innodb_buffer_pool_size / 1024x768 / 1024x768 / 1024x768 ;

Well, we've been changed to 50M!

FIX: WordPress error establishing a database connection problem

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.