28

I am running ubuntu server. When I tried to login to mysql(which was running),I got the following error

ERROR 2002 (HY000): Can't connect to local MySQL server through socket         '/var/run/mysqld/mysqld.sock' (2)

But mysqld.sock file doesn't exist inside /var/run/mysqld folder. On executing ps aux | grep mysql command,I realized that mysql server was not running.

I then tried to restart mysql server using

service mysql start
service mysql restart
/etc/init.d/mysql start

But,the start process failed in all 3 cases. /var/log/mysql/mysql.log and /var/log/mysql/mysql.err files are empty.

But /var/log/error.log shows following information:

140425 12:49:05 [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.
140425 12:49:05 [Note] Plugin 'FEDERATED' is disabled.
140425 12:49:05 InnoDB: The InnoDB memory heap is disabled
140425 12:49:05 InnoDB: Mutexes and rw_locks use GCC atomic builtins
140425 12:49:05 InnoDB: Compressed tables use zlib 1.2.8
140425 12:49:05 InnoDB: Using Linux native AIO
140425 12:49:05 InnoDB: Initializing buffer pool, size = 3.0G
140425 12:49:05 InnoDB: Completed initialization of buffer pool
InnoDB: Error: log file ./ib_logfile0 is of different size 0 5242880 bytes
InnoDB: than specified in the .cnf file 0 26214400 bytes!
140425 12:49:05 [ERROR] Plugin 'InnoDB' init function returned error.
140425 12:49:05 [ERROR] Plugin 'InnoDB' registration as a STORAGE ENGINE failed.
140425 12:49:05 [ERROR] /usr/sbin/mysqld: unknown variable 'record_buffer=64M'
140425 12:49:05 [ERROR] Aborting

140425 12:49:05 [Note] /usr/sbin/mysqld: Shutdown complete
  • see if this helps: serverfault.com/questions/104014/… – Rinzwind Apr 25 '14 at 7:35
  • 1
    What is the output of ls /var/lib/mysql/ib_logfile*? – jobin Apr 25 '14 at 7:40
  • ls: cannot access /var/lib/mysql/ib_logfile*: No such file or directory – ananth Apr 25 '14 at 7:46
  • 1
    Is your /var/lib/mysql directory writable for mysql? – Jos Apr 25 '14 at 8:10
  • 1
    I am a linux newbie..I changed the permissions of /var/lib/mysql by using chmod 777 . Can you please suggest me how to check if this is not the right way? – ananth Apr 25 '14 at 8:27

10 Answers 10

29

Open a terminal(Ctrl+Alt+t) and do the following:

sudo service mysql stop
sudo rm /var/lib/mysql/ib_logfile0
sudo rm /var/lib/mysql/ib_logfile1

and comment out the line record_buffer=64M in /etc/mysql/my.cnf [1]

and then restart msyql using:

sudo service mysql restart

(Source)

| improve this answer | |
  • 1
    I ran the commands you mentioned..On running sudo service mysql restart, it gave a message stop: Unknown instance and shell prompt didn't appear(restart is still running from past 50 mins) – ananth Apr 25 '14 at 9:30
  • 1
    Also, now the error log says: -140425 15:09:11 InnoDB: highest supported file format is Barracuda. 140425 15:09:12 InnoDB: Waiting for the background threads to start 140425 15:09:13 InnoDB: 5.5.37 started; log sequence number 940942258188 140425 15:09:13 [ERROR] /usr/sbin/mysqld: unknown variable 'record_buffer=64M' 140425 15:09:13 [ERROR] Aborting 140425 15:09:13 InnoDB: Starting shutdown... 140425 15:09:14 InnoDB: Shutdown completed; log sequence number 940942258188 140425 15:09:14 [Note] /usr/sbin/mysqld: Shutdown complete – ananth Apr 25 '14 at 9:45
  • No..I did sudo service mysql restart. – ananth Apr 25 '14 at 9:49
  • Can you try doing sudo service mysql start? – jobin Apr 25 '14 at 9:50
  • Should I kill the mysql restart process which is running? Will it cause any problem?? – ananth Apr 25 '14 at 9:55
9

This solved my problem:

mkdir /var/run/mysqld

touch /var/run/mysqld/mysqld.sock

chown -R mysql /var/run/mysqld

/etc/init.d/mysql restart

| improve this answer | |
  • 3
    after applying these steps my database is got deleted. Now what will I do?? – Amit Yadav Nov 3 '17 at 14:01
7

I solved the problem in the following way:

chown -R mysql:mysql /var/lib/mysql
mysql_install_db --user=mysql -ldata=/var/lib/mysql/

In another context, I faced it because the mysql daemon failed to start. So start daemon with command - mysqld start and then try to start the service.

| improve this answer | |
2

I had the same error message and the same emptyness in the log files. In my config-file (my.cnf) I had specified that I wanted to use myisam tables, by adding this line in the [mysqld]-section:

default-table-type = myisam

After upgrading mysql it seems this causes mysql not to start. I have changed this to:

default-storage-engine = myisam

and now everything works fine.

| improve this answer | |
1

Increasing the available RAM by adding new Swap space might also help. Steps are here

Make sure that you create /swapfile of the size smaller than the available space shown by

df -h

For example for me output of df- h was:

Filesystem      Size  Used Avail Use% Mounted on
/dev/xvda1      7.8G  1.2G  6.3G  16% /
none            4.0K     0  4.0K   0% /sys/fs/cgroup
udev            492M   12K  492M   1% /dev
tmpfs           100M  336K   99M   1% /run

So I created using 2 G

sudo fallocate -l 2G /swapfile

And then just start the service

sudo /etc/init.d/mysql restart

Hope this helps. All the best.

| improve this answer | |
1

My solution:

Check if in all /etc/rc1.d ... /etc/rc5.d the mysql script starts with S (Ex S10mysql) and not K AS K10mysql.

Explanation: K prefix loads with stop, kind of kill service; and S prefix starts with start parameter.

execute in terminal:   
(command        script action  runlevel)
---------------------------------------
sudo update-rc.d mysql enable  2
sudo update-rc.d mysql enable  3
sudo update-rc.d mysql enable  4
sudo update-rc.d mysql enable  5
| improve this answer | |
1

In my case, it was a space issue. Check if you have enough space left.

from /var/log/mysql/error.log I got some hints from two lines:

2018-08-04T05:25:29.519139Z 0 [ERROR] InnoDB: Write to file ./ibtmp1failed at offset 3145728, 1048576 bytes should have been written, only 704512 were writt$
2018-08-04T05:25:29.519145Z 0 [ERROR] InnoDB: Error number 28 means 'No space left on device'

I could see that it is a space issue.

root@xxx:/home/user1# df -h
Filesystem                            Size  Used Avail Use% Mounted on
udev                                  477M     0  477M   0% /dev
tmpfs                                 100M   11M   89M  11% /run
/dev/mapper/server1--osticket--vg-root  8.3G  7.9G     0 100% /
tmpfs                                 497M     0  497M   0% /dev/shm
tmpfs                                 5.0M     0  5.0M   0% /run/lock
tmpfs                                 497M     0  497M   0% /sys/fs/cgroup
/dev/vda1                             472M  467M     0 100% /boot
tmpfs                                 100M     0  100M   0% /run/user/1000

From here, I could see that there was not enough space left on the virtual server /dev/mapper/server1--osticket--vg-root 8.3G 7.9G 0 100% /. And I thought on either migrating or increasing the virtual drive, but I decided to remove unnecessary files first.

So, had to clean up cache and files that were not needed:

#apt-get clean
#apt-get -f autoremove

Then, do not forget to remove the mysql corrupted log files afterwards. They would be generated again when you restart mysql

#service mysql stop
#cd /var/lib/mysql
#rm ib_logfile*
#service mysql start

Check your mysql server service and it is probably up and running

root@server1-osticket:/var/lib/mysql# service mysql status
● mysql.service - MySQL Community Server
   Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled)
   Active: active (running) since Sat 2018-08-04 23:07:24 WAT; 7min ago
  Process: 1559 ExecStartPost=/usr/share/mysql/mysql-systemd-start post (code=exited, status=0/SUCCESS)
  Process: 1549 ExecStartPre=/usr/share/mysql/mysql-systemd-start pre (code=exited, status=0/SUCCESS)
 Main PID: 1558 (mysqld)
    Tasks: 29
   Memory: 280.3M
      CPU: 589ms
   CGroup: /system.slice/mysql.service
           └─1558 /usr/sbin/mysqld

Aug 04 23:07:19 server1-osticket systemd[1]: Starting MySQL Community Server...
Aug 04 23:07:24 server1-osticket systemd[1]: Started MySQL Community Server.
root@server1-osticket:/var/lib/mysql#

Case closed. I hope it helps.

| improve this answer | |
0

Remove the file /var/lib/mysql/.run-mysql_upgrade and it should start

;)

"With great power comes great responsibility"

| improve this answer | |
0

I had this problem when I set max_allowed_packet = 0.5M in /etc/mysql/my.cnf.

I solved it by changing max_allowed_packet to 1M.

| improve this answer | |
0

The following command resolve my issue and mysql could start after it.(it might to useful in some cases)

chown -R mysql: /var/lib/mysql
| improve this answer | |

Not the answer you're looking for? Browse other questions tagged or ask your own question.