93

I'm using Ubuntu 12.04 LTS.

There is on MySQL server situated remotely. I want to restart it.

Can someone please give me in detail step-by-step instructions to restart the MySQL server?

Following are the Database server details of MYSQL I got from phpMyAdmin UI:

Server: Localhost via UNIX socket
Server type: MySQL
Server version: 5.5.40-0ubuntu0.14.04.1 - (Ubuntu)
Protocol version: 10
User: root@localhost
Server charset: UTF-8 Unicode (utf8)

Can someone please help me?

Huey
  • 5,110
  • 6
  • 32
  • 44
PHPLover
  • 1
  • 51
  • 158
  • 311

8 Answers8

186
  1. SSH into the machine. Using the proper credentials and ip address, ssh root@128.0.0.1. This should provide you with shell access to the Ubuntu server.
  2. Restart the mySQL service. sudo service mysql restart should do the job.

If your mySQL service is named something else like mysqld you may have to change the command accordingly or try this: sudo /etc/init.d/mysql restart

Huey
  • 5,110
  • 6
  • 32
  • 44
  • Sorry your answer didn't work out for me. After executing above command I was able to restart MySQL but couldn't do login through phpMyAdmin and also the database was not accessible. Why so happened? Though on terminal the status of start and stop was shown 'Ok'. Then I tried the command sudo service mysql restart and everything started working properly. Can you please guide me what was wrong with your answer and what's the difference between these two commands? – PHPLover May 08 '15 at 04:49
  • 3
    Technically, they're the same. One executes the commad using `service` whilst the other uses the full path, so they both do the same job if sudoed. But using `service` is the recommended method, I'll update my answer. – Huey May 09 '15 at 00:03
  • `service mysqld restart` on MySQL 5.7 linux Fedora 28 – Accountant م Jul 14 '18 at 06:42
28
sudo service mysql stop;
sudo service mysql start;

If the above process will not work let's check one the given code above you can stop Mysql server and again start server

Ahmad
  • 5,551
  • 8
  • 41
  • 57
Ram Neduri
  • 448
  • 5
  • 7
25

Another way is:

systemctl restart mysql
simhumileco
  • 31,877
  • 16
  • 137
  • 115
felixmpa
  • 2,028
  • 1
  • 15
  • 16
4
  • To restart mysql use this command

sudo service mysql restart

Or

sudo restart mysql

Reference

Ayman Elshehawy
  • 2,746
  • 23
  • 21
0

I SSH'ed into my AWS Lightsail wordpress instance, the following worked: sudo /opt/bitnami/ctlscript.sh restart mysql I learnt this here: https://docs.bitnami.com/aws/infrastructure/mysql/administration/control-services/

0

I have had a problem with my WordPress site, the connection with MySql has gone away, and to get it back I had to restart the server. This has been an annoying issue as I do not have that high traffic on the site.

I tried to check if MySQL is up and make the cronjob restart it but that does not work that well. I have been looking at the log, using.

tail /var/log/mysql/error.log

In the log, I looked for shutdown messages or errors. I identified that the MySQL connection crashed when the server run out of memory, so why did it run out of memory. I started to optimize Mysql resources by using the optimization tool from Percona tools.

I also checked when my WordPress is running smoothly or what is causing heavy traffic peaks to your DB. One way is to increase the size of the server, I did not have that much traffic, so I installed the New Relic tool on my server to monitor the server resources to find out which processes are consuming memory.

I found out that the server did not have enough memory and MySQL can’t allocate what it needs so it crashes, what I did was add swap space to help this.

here is the method to Add Swap Space
https://www.digitalocean.com/community/tutorials/how-to-add-swap-space-on-ubuntu-16-04

If that's not enough, you may need to consider upgrading to a larger server. Either way, you should take a closer look at your memory consumption to better understand the problem.

0

You can simply run from your local terminal
ssh username@www.remoteserver.com -- sudo service mysqld restart

Dimitris
  • 21
  • 1
-3

What worked for me on an Amazon EC2 server was:

sudo service mysqld restart
simhumileco
  • 31,877
  • 16
  • 137
  • 115
Jonathan Plackett
  • 2,346
  • 2
  • 20
  • 33