Cannot access MYSQL database on AWS lightsail - mysql

I am working on a simple application using the LAMP stack using AWS/Lightsail. It worked once, but I rebooted the instance and it stopped working. The data was not available. I suspected issue with MySQL. Below is what I tried. Can anyone suggest any solution for this?
bitnami#ip-123-45-67-89:~$ mysql -u root -p
Enter password:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/opt/bitnami/mysql
/tmp/mysql.sock' (2)
bitnami#ip-123-45-67-89:~$ sudo /opt/bitnami/ctlscript.sh status
Cannot find any running daemon to contact. If it is running, make sure you are pointing to
the right pid file (/var/run/gonit.pid)
bitnami#ip-123-45-67-89:~$ ps aux | grep mysql
mysql 607 0.0 6.0 1254660 29812 ? Ssl 04:11 0:11 /usr/sbin/mysqld
bitnami 3338 0.0 0.1 6076 824 pts/0 S+ 14:27 0:00 grep mysql
bitnami#ip-123-45-67-89:~$ sudo /opt/bitnami/ctlscript.sh status
Cannot find any running daemon to contact. If it is running, make sure you are pointing to
the right pid file (/var/run/gonit.pid)
bitnami#ip-123-45-67-89:~$ df -h
Filesystem Size Used Avail Use% Mounted on
udev 233M 0 233M 0% /dev
tmpfs 49M 2.8M 46M 6% /run
/dev/xvda1 20G 9.5G 9.2G 51% /
tmpfs 242M 0 242M 0% /dev/shm
tmpfs 5.0M 0 5.0M 0% /run/lock
tmpfs 242M 0 242M 0% /sys/fs/cgroup
/dev/xvda15 124M 262K 124M 1% /boot/efi
tmpfs 49M 0 49M 0% /run/user/1000
bitnami#ip-123-45-67-89:~$ sudo /opt/bitnami/ctlscript.sh stop mysql
Stopped mysql
bitnami#ip-123-45-67-89:~$ sudo /opt/bitnami/ctlscript.sh start mysql
Failed to start mysql: Failed to start mysql
bitnami#ip-123-45-67-89:~$ ps aux | grep mysql
mysql 607 0.0 3.8 1254660 18912 ? Ssl 04:11 0:11 /usr/sbin/mysqld
bitnami 3560 0.0 0.1 6076 884 pts/0 S+ 14:39 0:00 grep mysql

Related

Lightsail Bitnami - Error establishing a database connection

I have a WordPress website hosted by AWS Lightsail.
When I access my website, I got this error - Error establishing a database connection
I didn't change anything for the last few days, and it was working okay.
Also, I have two snapshots and tried to restore the instance, but I got same error messages.
I tried to fix it by adding define('WP_ALLOW_REPAIR', true); line in my wp-config.php file, but it's not working.
I tried to access mysql on the terminal by following the command mysql -u root -p and typed password that I got from cat bitnami_application_password, but I got this error message - ERROR 2002 (HY000): Can't connect to local server through socket '/opt/bitnami/mariadb/tmp /mysql.sock' (111)
$ ps -ef | grep mysql
bitnami 3483 802 0 15:17 pts/0 00:00:00 grep mysql
If I run df -h, I got this:
Filesystem Size Used Avail Use% Mounted on
udev 989M 0 989M 0% /dev
tmpfs 200M 2.9M 197M 2% /run
/dev/xvda1 59G 8.6G 48G 16% /
tmpfs 998M 0 998M 0% /dev/shm
tmpfs 5.0M 0 5.0M 0% /run/lock
tmpfs 998M 0 998M 0% /sys/fs/cgroup
/dev/xvda15 124M 278K 124M 1% /boot/efi
tmpfs 200M 0 200M 0% /run/user/1000
If I run sudo service mysql stop, I got this error message:
Failed to stop mysql.service: Unit mysql.service not loaded.
If I run sudo /opt/bitnami/ctlscript.sh status, I got this message:
Cannot find any running daemon to contact. If it is running, make sure you are pointing to the right pid file (/var/run/gonit.pid)

mysql service reappears after kill -9 <pid for mysql>

I have mysql installed on Ubuntu18.04. I tried to kill the mysql process with kill -9 but it comes back immediately. Here's example from my terminal output:
root#mysql-image:~# ps aux | grep mysql
mysql 779 0.8 19.2 1166336 188064 ? Sl 20:06 0:02 /usr/sbin/mysqld --daemonize --pid-file=/run/mysqld/mysqld.pid
root 1046 0.0 0.1 13144 1060 pts/0 S+ 20:11 0:00 grep --color=auto mysql
root#mysql-image:~# kill -9 779
root#mysql-image:~# ps aux | grep mysql
mysql 1063 21.5 18.1 1165936 177556 ? Sl 20:11 0:00 /usr/sbin/mysqld --daemonize --pid-file=/run/mysqld/mysqld.pid
root 1094 0.0 0.1 13144 1032 pts/0 S+ 20:11 0:00 grep --color=auto mysql
root#mysql-image:~# kill -9 1063
root#mysql-image:~# ps aux | grep mysql
mysql 1142 21.5 18.1 1165936 177628 ? Sl 20:12 0:00 /usr/sbin/mysqld --daemonize --pid-file=/run/mysqld/mysqld.pid
root 1173 0.0 0.1 13144 1084 pts/0 S+ 20:12 0:00 grep --color=auto mysql
I'm trying to destroy the mysql process in an abrupt way and "unsafe way" as part of an experiment I'm doing. But the kill -9 doesn't seem to permanently shut down the mysql database.
What am I doing wrong?
Normally, systemd will be configured to restart mysql if it unexpectedly terminates, with Restart=on-abort in /usr/lib/systemd/system/mysql.service.
on-abort is explained in: https://unix.stackexchange.com/questions/564443/what-does-restart-on-abort-mean-in-a-systemd-service
You could try making a change to the mysql conf files that keep it from restarting (setting a non-existent user, maybe?). Or you can just do a
kill -15 instead, which is treated as an expected termination so won't cause a restart.

Unable to start mysql on ubuntu

I'm trying to mysql, but I'm receiving this error:
sudo /etc/init.d/apache2 start
* Starting web server apache2 *
ubuntu#ip-172-31-19-47:/var/www/html/anunciolocal$ sudo /etc/init.d/mysql start
* /etc/init.d/mysql: ERROR: The partition with /var/lib/mysql is too full!
When I checked my memory:
ubuntu#ip-172-31-19-47:~$ df -h
Filesystem Size Used Avail Use% Mounted on
udev 996M 12K 996M 1% /dev
tmpfs 201M 344K 200M 1% /run
/dev/xvda1 16G 15G 307M 98% /
none 4.0K 0 4.0K 0% /sys/fs/cgroup
none 5.0M 0 5.0M 0% /run/lock
none 1001M 0 1001M 0% /run/shm
none 100M 0 100M 0% /run/user
overflow 1.0M 992K 32K 97% /tmp
How do I solve it?
Try running it this way
sudo service mysql stop
sudo service mysql start
/etc/init.d/mysql: ERROR: The partition with /var/lib/mysql is too full!
this is why you cant start mysql
please clear /dev/xvda1 the disk has no enough space

mysql select query "No Space Left On Device"

My system is using Ubuntu with mysql database:
I have a complex mysql select query to run.
mysql -u root -p myDB < query.sql
But when I try to run it it always gives me:
ERROR 3 (HY000) at line 1: Error writing file
'/mnt/disk/tmp/MY0Wy7vA' (Errcode: 28 - No space left on device)
I have 11 GB free on disk and while the query is running, I keep track of it using
df -h
and
df -hi
to keep track of inodes
and I don't see any decrease in disk space while the query is running. All the time there is always 11 GB free on disk where the tmp folder is located.
This is the output of df -h:
ubuntu#ip-10-0-0-177:~$ df -h
Filesystem Size Used Avail Use% Mounted on
udev 3.9G 0 3.9G 0% /dev
tmpfs 799M 57M 742M 8% /run
/dev/xvda1 30G 24G 5.4G 82% /
tmpfs 3.9G 0 3.9G 0% /dev/shm
tmpfs 5.0M 0 5.0M 0% /run/lock
tmpfs 3.9G 0 3.9G 0% /sys/fs/cgroup
/dev/xvdf1 50G 39G 11G 80% /mnt/disk
tmpfs 799M 0 799M 0% /run/user/1000
This is the output of df -aTh:
Filesystem Type Size Used Avail Use% Mounted on
/dev/xvdf1 ext4 50G 39G 11G 80% /mnt/disk
Take a look at the part of the error that indicate it’s actually writing to /tmp (see below)
: Error writing file '/mnt/disk/tmp/MY0Wy7vA
In some Linux distributions, /tmp is mounted as a tmpfs (ramdisk), so even if your disk has plenty of space you can get a "no space" error if you try to write too much there.
To investigate about the mount, try
$ cat /proc/mounts
OR
$ cat /proc/self/mounts
Or better yet
df - aTh
df -h /tmp
To see hidden ones, try
du -sc * .[^.]* | sort -n
Among other things you can try making MySQL use a different temp directory, or to not use tmpfs for /tmp
If TMPDIR is not set in my.cnf, MySQL uses the system default which is usually /tmp
You can change the MySQL tmp dir as the following suggests:
Changing the tmp folder of mysql
Credits ::
https://github.com/LogBlock/LogBlock/issues/540

start using pre-compiled mysql, but get: Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)

I knew the question I am asking is somewhat alike with other guys, but my case is a little different:
I did not install mysql-server using yum, nor did I install it with rpm or compile-makeinstall.
I simply downloaded the compressed precompiled binary from the official website:
http://dev.mysql.com/get/Downloads/MySQL-5.1/mysql-5.1.73-linux-x86_64-glibc23.tar.gz
So, there is no /etc/init.d/mysqld, the "service mysqld start/stop/restart" could not work.
I unarchived it and initialized the DB with:
./scripts/mysql_install_db
then start it with:
./bin/mysqld_safe &
everything work fine till now, but when I tried to connect it using mysql, it prompted:
# mysql
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
The data directory was changed to:
drw-rw-rw- 4 mysql mysql 4096 Jan 3 14:03 mysql
The following stop command also could not work:
# mysqladmin shutdown
mysqladmin: connect to server at 'localhost' failed
error: 'Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)'
Check that mysqld is running and that the socket: '/tmp/mysql.sock' exists!
The mysqld_safe process and mysqld process are all working fine:
# ps -ef | grep mysqld
root 10977 5685 0 14:03 pts/2 00:00:00 /bin/sh ./bin/mysqld_safe
mysql 11154 10977 0 14:03 pts/2 00:00:00 /root/mysql-5.1.73-linux-x86_64-glibc23/bin/mysqld
--basedir=/root/mysql-5.1.73-linux-x86_64-glibc23
--datadir=/var/lib/mysql --user=mysql
--log-error=/var/log/mysqld.log
--pid-file=/var/run/mysqld/mysqld.pid
--socket=/var/lib/mysql/mysql.sock
root 11650 5685 0 14:26 pts/2 00:00:00 grep mysqld
some config information in the /etc/my.cnf is :
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
user=mysql
old_passwords=1
# ps -ef | grep mysqld
root 10977 5685 0 14:03 pts/2 00:00:00 /bin/sh ./bin/mysqld_safe
mysql 11154 10977 0 14:03 pts/2 00:00:00 /root/mysql-5.1.73-linux-x86_64-glibc23/bin/mysqld
--basedir=/root/mysql-5.1.73-linux-x86_64-glibc23
--datadir=/var/lib/mysql --user=mysql
--log-error=/var/log/mysqld.log
--pid-file=/var/run/mysqld/mysqld.pid
--socket=/var/lib/mysql/mysql.sock
your socket is at /var/lib/mysql/mysql.sock
guess you are using /usr/bin/mysql
to connect to mysql, you can update /etc/my.cnf, set socket=/var/lib/mysql/mysql.sock for [mysql] section
[mysql]
socket=/var/lib/mysql/mysql.sock
To fix mysqladmin you need to add the section [mysqladmin] also
[mysqladmin]
socket=/var/lib/mysql/mysql.sock
Alternatively you can add [client], it should work for both mysql and mysqladmin
[client]
socket=/var/lib/mysql/mysql.sock
Don't you need to do a
mysql.server start