How do I start/stop mysql server?

I tried to find in some articles describing how to correctly start & stop mysql server.

I found this link: How to start/stop MySql server on Ubuntu 8.04 | Abhi's Blogging World

I ran this command:

/etc/init.d/mysql start 

but I see this error

ERROR 1045 (28000) Access denied for user....

After I tried this command:

sudo /etc/init.d/mysql start

I entered my password, and again I see the same error.

Next command:

sudo /etc/init.d/mysql - root -p start

results in:

ERROR 1049 (42000) Unknown database 'start'.

And when I run this command:

sudo service mysql start

MySQL server success started. Cool!

So, what's wrong with the other commands? Why do they result in error?


Your first two commands weren't run as root so that is expected behaviour. You need to be root to stop/start mysql.

However:

sudo /etc/init.d/mysql start

should work. Indeed it does, for me:

kojan:~> sudo /etc/init.d/mysql restart
[sudo] password for chris: 
Stopping MySQL database server: mysqld.
Starting MySQL database server: mysqld.
Checking for corrupt, not cleanly closed and upgrade needing tables..

I used restart rather than start, since it was already running, but the effect is the same. Are you sure you entered your password correctly? :) Have you edited your sudo config at all which would stop this working?

This one..

sudo /etc/init.d/mysql - root -p start

The arguments are wrong. an init.d script only takes start or stop or restart - just one word telling it what to do. You cannot give it multiple arguments as you were trying to do.

Anyway, the short answer is the one you actually got to work, is the recommended way. service is replacing all the init.d scripts over time, so you should get into the habit of using service. The page you link to was written in 2008, so has to be taken with some salt :)


Also helps to double check that "mysql" is the correct service name. In my case it wasn't. I kept getting following response: mysql: unrecognized service when running

service mysql status 

Then I checked /etc/init.d and found script named mysqld which listed process name: mysqld and prog=mysqld

So then I did

service mysqld status
service mysqld stop
service mysqld start 

and they all worked fine.


For Ubuntu 12.10 to 14.04 (Upstart)

Newer versions of Ubuntu use systemd.

START MYSQL:

sudo start mysql

RESTART MYSQL:

sudo restart mysql # The service must be running

STOP MYSQL:

sudo stop mysql # The service must be running

Actually, I got a strange error, when I installed mysql-workbench on my Ubuntu machine. After that I tried to start the mysql service using this command:

service mysql start

So I got the solution that the MySQL server was not installed, so I installed it and my problem was solved. The command to install mysql-server is:

sudo apt-get install mysql-server

After successful installation, start the MySQL server as:

service mysql start

I had the same issue with Ubuntu64 and I fixed by simply not using systemctl but instead this:

sudo service mysql restart

hopefully this command will work for you.