Error establishing a database connection - mysql

I have a wordpress site on a VPS running Debian 7 that was working fine when I last visited it and I've made no changes since, but now when I visit the site it says: Error establishing a database connection. It also gives the same error in the admin portal.
I had not changed the password, domain, IP, or anything and checked the wp-config.php and everything in it is accurate.
I logged into my VPS as root and tried to log into mysql to check to see if wordpress was still a user, but it couldn't locate the socket:
root#debian7:~# mysql -u root -p
Enter password:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
So I tried restarting the mysqld and got:
root#debian7:~# /etc/init.d/mysql restart
[ ok ] Stopping MySQL database server: mysqld.
[FAIL] Starting MySQL database server: mysqld . . . . . . . . . . . . . . failed!
When I try to run mysqld:
root#debian7:~# mysqld
131226 15:36:15 [Warning] Can't create test file /var/lib/mysql/debian7.lower-test
131226 15:36:15 [Warning] Can't create test file /var/lib/mysql/debian7.lower-test
131226 15:36:15 [Note] Plugin 'FEDERATED' is disabled.
131226 15:36:15 InnoDB: The InnoDB memory heap is disabled
131226 15:36:15 InnoDB: Mutexes and rw_locks use GCC atomic builtins
131226 15:36:15 InnoDB: Compressed tables use zlib 1.2.7
131226 15:36:15 InnoDB: Using Linux native AIO
mysqld: Can't create/write to file '/tmp/ibRx51To' (Errcode: 30)
131226 15:36:15 InnoDB: Error: unable to create temporary file; errno: 30
131226 15:36:15 [ERROR] Plugin 'InnoDB' init function returned error.
131226 15:36:15 [ERROR] Plugin 'InnoDB' registration as a STORAGE ENGINE failed.
131226 15:36:15 [ERROR] Unknown/unsupported storage engine: InnoDB
131226 15:36:15 [ERROR] Aborting
131226 15:36:15 [Note] mysqld: Shutdown complete
So it seemed to be an access problem, so I checked the /var/lib/mysql directory
root#debian7:~# stat /var/lib/mysql
File: `/var/lib/mysql'
Size: 4096 Blocks: 8 IO Block: 4096 directory
Device: fe00h/65024d Inode: 391599 Links: 6
Access: (0700/drwx------) Uid: ( 104/ mysql) Gid: ( 106/ mysql)
Access: 2013-12-10 15:58:56.401341180 -0500
Modify: 2013-12-10 15:58:56.241341172 -0500
Change: 2013-12-10 15:58:56.241341172 -0500
Birth: -
As you can see, mysql is the owner and has rwx access..
The logs are somehow empty so I can't figure out what happened. I'm not familiar with troubleshooting these kinds of things though. So I could be making novice mistakes.
I'm just trying to get my wordpress site back and it seems the database dsiconnected on its own and the server wont restart. Any ideas?
More:
My /etc/mysql/my.cnf file contains these relevant lines:
pid-file = /var/run/mysqld/mysqld.pid
socket = /var/run/mysqld/mysqld.sock
bind-address = 127.0.0.1

Okay, after troubleshooting a while, it turned out that the entire file system is read-only. I tried making new files and in each case it says it can't cause "Read-only filesystem"
It seems to be a bad image or some sort of change my VPS provider made. So I'll be contacting them.

Related

Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2) . mysql.sock not exist in /var/lib/mysql/

Magento Showing "There Has Been Error Processing Your Request "
When trying to command " sudo service mysqld restart" but failed to Start
Then See the Log Showing me " SQLSTATE[HY000] [2002] No such file or directory "
I do Little search on Google, stackoverflow, magento stackoverflow sites and at last got something may be
after the Command " mysqld -u root -p status"
showing 'mysqladmin: connect to server at 'localhost' failed
error: 'Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)'
Check that mysqld is running and that the socket: '/var/lib/mysql/mysql.sock' exists!
I located that I don't have mysql.sock in /var/lib/mysql/ So now what I should do . I am not in expert just newbie . Unfortunately I gave 777 permission to all directory in ec2 instance, after some time of this Issue I see My site " There has been an error processing your request . for ec2 security reason I was not able to access instance using ftp or ssh . so I had to do create new instance gave this EBS to new instance , after changing permission I able to access my instance
Please take a look at my my.cnf file. I am seeing something can help
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
# Settings user and group are ignored when systemd is used.
# If you need to run mysqld under a different user or group,
# customize your systemd unit file for mysqld according to the
# instructions in http://fedoraproject.org/wiki/Systemd
[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
Here is The mysqld.log
/usr/libexec/mysql55/mysqld: Can't create/write to file '/tmp/ibmCz4dv' (Errcode: 13)
160212 18:29:37 InnoDB: Error: unable to create temporary file; errno: 13
160212 18:29:37 [ERROR] Plugin 'InnoDB' init function returned error.
160212 18:29:37 [ERROR] Plugin 'InnoDB' registration as a STORAGE ENGINE failed.
160212 18:29:37 [ERROR] Unknown/unsupported storage engine: InnoDB
160212 18:29:37 [ERROR] Aborting
160212 18:29:37 [Note] /usr/libexec/mysql55/mysqld: Shutdown complete
160212 18:29:37 mysqld_safe mysqld from pid file /var/run/mysqld/mysqld.pid ended
775 to /tmp and Now The mysqld.log
775 to /tmp and mysqld.log
/usr/libexec/mysql55/mysqld: Can't create/write to file '/tmp/ibLzshr1' (Errcode: 13)
160213 9:08:59 InnoDB: Error: unable to create temporary file; errno: 13
160213 9:08:59 [ERROR] Plugin 'InnoDB' init function returned error.
160213 9:08:59 [ERROR] Plugin 'InnoDB' registration as a STORAGE ENGINE failed.
160213 9:08:59 [ERROR] Unknown/unsupported storage engine: InnoDB
160213 9:08:59 [ERROR] Aborting
160213 9:08:59 [Note] /usr/libexec/mysql55/mysqld: Shutdown complete
160213 09:08:59 mysqld_safe mysqld from pid file /var/run/mysqld/mysqld.pid ended
Please help me to Sort it out
The mysql user obviously doesn't have the rights to create a file in /tmp according to
/usr/libexec/mysql55/mysqld: Can't create/write to file '/tmp/ibmCz4dv' (Errcode: 13)
check the access rights on /tmp, should be 777. BTW sys "errno 13" is "Permission denied"
According to this, the server stops and doesn't create any socket which then causes the connect error.
I want to say thanks # Axel Amthor . Finally I gave /tmp file 777 and Restarted mysqld .. and Boom
Site back in Action . Sorry i can't give Upvote because i didn't have reputation 15 :(

After changing mysql directory, Mysql will no longer start up

I am running a debian machine and I am trying to move my mysql data directory. After looking at a few online tutorials, it looks like the way to do this is changing the datadir in the my.cnf. Some of the tutorials also talk about changing some apparmor files, but it does not look like I have apparmor installed.
After I changed the my.cnf I would keep on getting the following error in the syslog:
Jul 16 16:21:04 sparta /etc/init.d/mysql[29315]: #007/usr/bin/mysqladmin: connect to server at 'localhost' failed
Jul 16 16:21:04 sparta /etc/init.d/mysql[29315]: error: 'Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)'
Jul 16 16:21:04 sparta /etc/init.d/mysql[29315]: Check that mysqld is running and that the socket: '/var/run/mysqld/mysqld.sock' exists!
After looking around a little more I came upon a website that said I should also change the directory for the socket. So I did that, but I still get the same issue.
When I run sudo mysqld start I get the following error:
150716 16:25:54 [Warning] Using unique option prefix key_buffer instead of key_buffer_size is deprecated and will be removed in a future release. Please use the full name instead.
150716 16:25:54 [Note] mysqld (mysqld 5.5.43-0+deb7u1) starting as process 29416 ...
150716 16:25:54 [Warning] Using unique option prefix myisam-recover instead of myisam-recover-options is deprecated and will be removed in a future release. Please use the full name instead.
150716 16:25:54 [Note] Plugin 'FEDERATED' is disabled.
mysqld: Table 'mysql.plugin' doesn't exist
150716 16:25:54 [ERROR] Can't open the mysql.plugin table. Please run mysql_upgrade to create it.
150716 16:25:54 InnoDB: The InnoDB memory heap is disabled
150716 16:25:54 InnoDB: Mutexes and rw_locks use GCC atomic builtins
150716 16:25:54 InnoDB: Compressed tables use zlib 1.2.7
150716 16:25:54 InnoDB: Using Linux native AIO
150716 16:25:54 InnoDB: Initializing buffer pool, size = 128.0M
150716 16:25:54 InnoDB: Completed initialization of buffer pool
150716 16:25:54 InnoDB: Operating system error number 13 in a file operation.
InnoDB: The error means mysqld does not have the access rights to
InnoDB: the directory.
InnoDB: File name ./ibdata1
InnoDB: File operation call: 'create'.
InnoDB: Cannot continue operation.
Here is a copy of the part of my.cnf file that I edited:
[mysqld]
#
# * Basic Settings
#
user = mysql
pid-file = /var/run/mysqld/mysqld.pid
socket = /mysql_persistant/
port = 3306
basedir = /usr
datadir = /mysql_persistant/
tmpdir = /tmp
lc-messages-dir = /usr/share/mysql
skip-external-locking
I have also chmod 755 the new file directory.
So it seems like the issue was running a chown -R on the directory that I was changing the data too.
It is not necessary to change the location of the socket.

MAMP mysql not starting

Got error: 2002: Can't connect to local MySQL server through socket '/Applications/MAMP/tmp/mysql/mysql.sock' (2) when trying to connect
150629 15:44:35 mysqld_safe Starting mysqld daemon with databases from /Applications/MAMP/db/mysql
150629 15:44:35 [Warning] You have forced lower_case_table_names to 0 through a command-line option, even though your file system '/Applications/MAMP/db/mysql/' is case insensitive. This means that you can corrupt a MyISAM table by accessing it with different cases. You should consider changing lower_case_table_names to 1 or 2
150629 15:44:35 [Note] Plugin 'FEDERATED' is disabled.
150629 15:44:35 [Note] Plugin 'ndbcluster' is disabled.
/Applications/MAMP/Library/libexec/mysqld: Can't find file: './mysql/plugin.frm' (errno: 13)
150629 15:44:35 [ERROR] Can't open the mysql.plugin table. Please run mysql_upgrade to create it.
150629 15:44:35 InnoDB: Started; log sequence number 1 402900962
150629 15:44:35 [ERROR] /Applications/MAMP/Library/libexec/mysqld: Can't find file: './mysql/host.frm' (errno: 13)
150629 15:44:35 [ERROR] Fatal error: Can't open and lock privilege tables: Can't find file: './mysql/host.frm' (errno: 13)
150629 15:44:35 mysqld_safe mysqld from pid file /Applications/MAMP/tmp/mysql/mysql.pid ended
I can't find mysql.sock file anywhere. This is MAMP 1.9 on OS X version 10.8.5
The first thing to try is to change the ownership of the datadir of MySQL, for example, if you run MySQL with user mysql:
chown -R mysql:mysql /path/to/datadir
check the privilges of /Applications/MAMP/tmp/mysql/ directory for creating socket.

Getting error "Plugin 'InnoDB' registration as a STORAGE ENGINE failed" when starting MySQL

I found many similar question on Stackoverflow but didn't get the exact error solution.
My issue is when starting MySQL service on one of the Dedicated Centos 6.5 machine, I am getting error :
141018 05:13:46 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
141018 5:13:47 [Warning] Can't create test file /var/lib/mysql/ip-184-168-73-83.lower-test
141018 5:13:47 [Warning] Can't create test file /var/lib/mysql/ip-184-168-73-83.lower-test
/usr/libexec/mysqld: Can't create/write to file '/tmp/ibkTWnhE' (Errcode: 28)
141018 5:13:48 InnoDB: Error: unable to create temporary file; errno: 28
141018 5:13:48 [ERROR] Plugin 'InnoDB' init function returned error.
141018 5:13:48 [ERROR] Plugin 'InnoDB' registration as a STORAGE ENGINE failed.
141018 5:13:48 [ERROR] Can't start server : Bind on unix socket: No space left on device
141018 5:13:48 [ERROR] Do you already have another mysqld server running on socket: /var/lib/mysql/mysql.sock ?
141018 5:13:48 [ERROR] Aborting
141018 5:13:48 [Note] /usr/libexec/mysqld: Shutdown complete
141018 05:13:48 mysqld_safe mysqld from pid file /var/run/mysqld/mysqld.pid ended
Here are free command status:
free -m
total used free shared buffers cached
Mem: 3743 3631 111 0 2705 21
-/+ buffers/cache: 905 2838
Swap: 2047 0 2047
This error also happens when your Database data is corrupt. You may fix this issue by moving your Db data files (ib_logfile0 and ib_logfile1) mentioned below to another location. ib_logfile0 and ib_logfile1 are system tablespace for the InnoDB infrastructure. These files contains several classes for information vital for InnoDB. You may read about these files here.
Before following below steps please keep a copy of files (ib_logfile0 and ib_logfile1) so you may restore your data in case it is lost:
Follow below steps:
Login to server via SSH with root access.
Navigate to /var/lib/mysql.
If you see files like, ib_logfile0 and ib_logfile1, rename or move them to some other folder.
Stop and start the MySQL service by running sudo service mysql stop and sudo service mysql start
These files will be recreated after you restart the server and the issue will be fixed hopefully.
Thanks
I have the same problems, this my solution:
Add more RAM to the server
Decrease the value of innodb-buffer-pool size in the config file:
sudo nano /etc/mysql/my.cnf
innodb_buffer_pool_size = 10M
After save /etc/mysql/my.cnf.
Restart mysql service:
sudo service mysql restart
exit
This is frequently occurred issue. Do following -
delete/move out these "aria_log_contro, ib_logfile0, ib_logfile1, ib_data1" files from location "..\xampp\mysql\data" and also from "..\xampp\mysql\backup".
stop and start apache server and mysql form xampp control panel
This should fix the issue; actually it worked for me.
NOTE: THIS IS GOING TO RESET THE DB IN MANY CASES BE VERY CAREFUL
Changing the values of innodb_buffer_pool_size and innodb_log_file_size didn't work for me.
Moving ib_logfile0 and ib_logfile1 files didn't help either.
What did help was:
> service mysql stop
Edit my.cfg and add innodb_force_recovery = 1
> service mysql start
> service mysql stop
Comment the innodb_force_recovery = 1 line.
> service mysql start
And voilá. (I should note that I have no idea if this involves any data loss or not)
Although late but putting answer here so that solution that helped me can help someone. I took following steps:
Added more RAM to sever
Decrease the value of innodb-buffer-pool size
Set innodb_log_file_size
Restart mysql
Example of addition to my.cnf:
innodb_buffer_pool_size = 10M
innodb_log_file_size = 1000M
After few unsuccess hours, i checked the disk space... and was full...
I was getting below mysql error log:-
[Note] Plugin 'FEDERATED' is disabled.
InnoDB: The InnoDB memory heap is disabled
InnoDB: Mutexes and rw_locks use GCC atomic builtins
InnoDB: Compressed tables use zlib 1.2.3
InnoDB: Using Linux native AIO
InnoDB: Initializing buffer pool, size = 128.0M
InnoDB: mmap(137363456 bytes) failed; errno 12
InnoDB: Completed initialization of buffer pool
InnoDB: Fatal error: cannot allocate memory for the buffer pool
[ERROR] Plugin 'InnoDB' init function returned error.
[ERROR] Plugin 'InnoDB' registration as a STORAGE ENGINE failed.
[ERROR] Unknown/unsupported storage engine: InnoDB
[ERROR] Aborting
[Note] /usr/libexec/mysqld: Shutdown complete
I found out there are two solutions which are:-
1)Set innodb_log_file_size equal to the actual size of the existing InnoDB log files.
To see what size of innoDB log allocated, login mysql and enter following cmd:-
SHOW GLOBAL VARIABLES LIKE 'innodb_log_file_size';
Expected result example:- 5242880
After that, insert that value in my.cnf:-
vi /etc/my.cnf
innodb_log_file_size =5242880
2)Rename or move both the ./ib_logfile0 and ./ib_logfile1 files, and then start the MySQL server.This normally will be located at /var/lib/mysql. After start mysql, it create new innoDB log file and restore possible half-written data from the file of .ibd.
The expexted mysql log example:-
InnoDB: Database physically writes the file full: wait...
161216 9:58:54 InnoDB: Log file ./ib_logfile1 did not exist: new to be created
InnoDB: Setting log file ./ib_logfile1 size to 5 MB
InnoDB: Database physically writes the file full: wait...
161216 9:58:54 InnoDB: highest supported file format is Barracuda.
InnoDB: The log sequence number in ibdata files does not match
InnoDB: the log sequence number in the ib_logfiles!
161216 9:58:54 InnoDB: Database was not shut down normally!
InnoDB: Starting crash recovery.
InnoDB: Reading tablespace information from the .ibd files...
InnoDB: Restoring possible half-written data pages from the doublewrite
InnoDB: buffer...
161216 9:58:54 InnoDB: Waiting for the background threads to start
161216 9:58:55 InnoDB: 5.5.50 started; log sequence number 1589772
161216 9:58:55 [Note] Server hostname (bind-address): '0.0.0.0'; port: 3306
161216 9:58:55 [Note] - '0.0.0.0' resolves to '0.0.0.0';
161216 9:58:55 [Note] Server socket created on IP: '0.0.0.0'.
161216 9:58:55 [Note] Event Scheduler: Loaded 0 events
161216 9:58:55 [Note] /usr/libexec/mysqld: ready for connections.
Version: '5.5.50' socket: '/var/lib/mysql/mysql.sock' port: 3306 MySQL Community Server (GPL) by Remi
References:-
JUSTIN KULESZA (2011). MySQL: Failed Registration of InnoDB as a Storage Engine. Available at: https://spin.atomicobject.com/2011/05/09/mysql-failed-registration-of-innodb-as-a-storage-engine/.
RolandoMySQLDBA (2014). MySQL my.cnf: innodb_log_file_size is missing. Available at: https://dba.stackexchange.com/questions/75688/mysql-my-cnf-innodb-log-file-size-is-missing/158325#158325
Changing the Number or Size of InnoDB Redo Log Files. Available at: http://dev.mysql.com/doc/refman/5.7/en/innodb-data-log-reconfiguration.html
Nothing was working with reinstalls, removes, and others (I had no data to keep, not a fix; more of a data destruction process, big caveat there):
1005 mysql_install_db
1007 /usr/bin/mysqld_safe --datadir='/var/lib/mysql
1008 /usr/bin/mysqld_safe --datadir='/var/lib/mysql' (^z)
1009 bg
1010 mysql
1011 mysql_secure_installation
1012 mysql
1013 mysql -p
And viola; actually usable database.
for me the solution was to change the config to add
innodb_use_native_aio = 0
in mysql config
Just move this log file (ib_logfile0) to some other place for safer side and start the mysql services it worked for me.
I also met the same issue when restore a backup set made via innobackupex to a new instance. Finally ,the root cause is innodb_log_file_size doesn't match original instance that take the backup, and fix steps by steps like below:
Get innodb_log_file_size value from oragin instance via below command:
mysql uroot -ppasswd -NBe "show global variables like 'innodb_log_file_size';"
Modify the /etc/my.cnf of new instance with last get value:
vim /etc/my.cnf
Restart mysqld via :
systemctl restart mysqld

Running MySQL in a Docker container

So my ultimate end goal is to run a MySQL Docker container (say tutum/mysql from the public registry) and then link a Gitlab Docker container (say sameersbn/gitlab) to it where both containers use persistent storage.
However, I am stuck on the MySQL part. Every time I try and run a pre-made MySQL Docker container (mysql, tutum/mysql and sameersbn/mysql) as outlined below, I get the below output.
Steps
This is just one way of getting to the error message below.
docker.io pull tutum/mysql:latest
docker.io run -it tutum/mysql bash
Once attached to the new container run "/run.sh" (as per tutum/mysql dockerfile)
At this point a "Waiting for confirmation of MySQL service startup" message constantly repeats.
At this point if I cancel the "/run.sh" command and start MySQL myself I get the error message below.
Output:
root#1bbeb34f3491:/# mysqld
140730 4:49:04 [Warning] Using unique option prefix key_buffer instead of key_buffer_size is deprecated and will be removed in a future release. Please use the full name instead.
140730 4:49:04 [Warning] Using unique option prefix myisam-recover instead of myisam-recover-options is deprecated and will be removed in a future release. Please use the full name instead.
140730 4:49:04 [Note] Plugin 'FEDERATED' is disabled.
mysqld: Table 'mysql.plugin' doesn't exist
140730 4:49:04 [ERROR] Can't open the mysql.plugin table. Please run mysql_upgrade to create it.
140730 4:49:04 InnoDB: The InnoDB memory heap is disabled
140730 4:49:04 InnoDB: Mutexes and rw_locks use GCC atomic builtins
140730 4:49:04 InnoDB: Compressed tables use zlib 1.2.8
140730 4:49:04 InnoDB: Using Linux native AIO
140730 4:49:04 InnoDB: Initializing buffer pool, size = 128.0M
140730 4:49:04 InnoDB: Completed initialization of buffer pool
140730 4:49:04 InnoDB: highest supported file format is Barracuda.
140730 4:49:04 InnoDB: Waiting for the background threads to start
140730 4:49:05 InnoDB: 5.5.37 started; log sequence number 1595675
140730 4:49:05 [Note] Server hostname (bind-address): '0.0.0.0'; port: 3306
140730 4:49:05 [Note] - '0.0.0.0' resolves to '0.0.0.0';
140730 4:49:05 [Note] Server socket created on IP: '0.0.0.0'.
140730 4:49:05 [ERROR] Can't start server : Bind on unix socket: Permission denied
140730 4:49:05 [ERROR] Do you already have another mysqld server running on socket: /var/run/mysqld/mysqld.sock ?
140730 4:49:05 [ERROR] Aborting
140730 4:49:05 InnoDB: Starting shutdown...
140730 4:49:06 InnoDB: Shutdown completed; log sequence number 1595675
140730 4:49:06 [Note] mysqld: Shutdown complete
Addressing the errors
"Please run mysql_upgrade to create it" => run mysql_upgrade command which outputs
root#1bbeb34f3491:/# mysql_upgrade
Looking for 'mysql' as: mysql
Looking for 'mysqlcheck' as: mysqlcheck
FATAL ERROR: Upgrade failed
"Do you already have another mysqld server running on socket" => Nope. Running service mysql stop does nothing and running ps doesn't show mysqld. Running ls -a /var/run/mysqld/ suggests that the socket file doesn't exist.
No matter which MySQL container I try, eventually when I start MySQL the same error message came up. This almost certainly means there is something wrong with my setup which confuses me because I thought a Docker container, with no exposed ports or persistent storage, would be isolated from the system Docker is installed on?
I have also tried running a MySQL container with the -d flag then running a fresh ubuntu 14.04 container (docker.io run -it --link mysql:mysql ubuntu:14.04 bash) linked to it. On the Ubuntu container I installed mysql-client through apt-get and tried to connect to the MySQL container on the ip address in MYSQL_PORT_3306_TCP_ADDR but that doesn't work either.
Equally the problem might be that I do not understand how Docker works. If this is the case, can someone create a set of steps that uses one of the MySQL containers on the Docker index and then link a container to it that can connect. This will also help to see whether there is something wrong with my Docker installation (or some other unknown problem that is causing this issue).
My host system is running Ubuntu 14.04 and Docker was installed through apt-get and is version 0.9.1.
I wasn't quite sure what to put in this explanation because the problem seems quite weird to me. If there is anything I have missed please ask and I will add it for you.
Thanks,
JamesStewy
This works for me:
docker run -d -p 3306:3306 -e MYSQL_PASS="mypass" tutum/mysql
No need to run the script from bash, no need for anything clever.