MySQL can't grab more memory than you allow it to. It needs to be tuned to properly use the available memory.
So does Apache.
The chances are that in 1GB both applications are trying to use more memory than is available. It's possible to configure Moodle to run on very small servers but it is tricky. And, time being money, it makes no sense most of the time.
I'm not at all surprised that MySQL is attempting to use all your memory. Because there really isn't very much of it.