MySQL installation from deb, permissions issues - mysql

I am trying to install MySQL on ubuntu 14.04 from the deb packages. I am having trouble starting the mysql server, it looks like a permissions problem. I followed the steps outlined here. Downloaded/untarred/installed deb tar bundle.
sudo apt-get install libaio1
tar -xvf mysql-server_5.7.4-m14-2ubuntu14.04_amd64.deb-bundle.tar
md5sum mysql-server_5.7.4-m14-2ubuntu14.04_amd64.deb-bundle.tar
sudo dpkg -i mysql-common_5.7.4-m14-2ubuntu14.04_amd64.deb
sudo dpkg -i mysql-community-server_5.7.4-m14-2ubuntu14.04_amd64.deb
sudo dpkg -i mysql-community-client_5.7.4-m14-2ubuntu14.04_amd64.deb
sudo dpkg -i libmysqlclient18_5.7.4-m14-2ubuntu14.04_amd64.deb
Here is where the files are installed on my system:
All configuration files (like my.cnf) are under /etc.
All binaries, libraries, headers, etc., are under /usr.
The data directory is under /var.
Following these instructions
I create a mysql group and user:
groupadd mysql
useradd -r -g mysql mysql
I change the ownership of mysql scripts to mysql (as per the instructions, but doubt this is necesssary)
cd /usr/bin
sudo chown mysql mysq*
sudo chgrp mysql mysq*
I run mysql_install_db to set up grant tables
sudo mysql_install_db --user=mysql
I switch back to root the ownership and group of mysql scripts.
cd /usr/bin
sudo chown root mysq*
sudo chgrp root mysq*
I change the ownership and group of /data to mysql. Location is /var/lib/mysql
cd /var/lib
ls -l mysql
total 122896
-rw-rw-rw- 1 mysql mysql 56 Jul 26 10:17 auto.cnf
-rw-rw-rw- 1 mysql mysql 12582912 Jul 26 10:17 ibdata1
-rw-rw-rw- 1 mysql mysql 50331648 Jul 26 10:17 ib_logfile0
-rw-rw-rw- 1 mysql mysql 50331648 Jul 24 17:36 ib_logfile1
-rw-rw---- 1 mysql mysql 12582912 Jul 26 10:17 ibtmp1
drwxrwxrw- 2 mysql mysql 4096 Jul 24 17:36 mysql
drwxrw-rw- 2 mysql mysql 4096 Jul 24 17:36 performance_schema
drwxrw-rw- 2 mysql mysql 4096 Jul 24 17:36 test
Now, when I try to start the mysql server, I get permission errors:
mysqld_safe --user=mysql &
[4] 5680
/var/lib$ 140727 00:42:17 mysqld_safe Logging to '/var/log/mysql/error.log'.
cat: /var/run/mysqld/mysqld.pid: Permission denied
rm: cannot remove ‘/var/run/mysqld/mysqld.pid’: Permission denied
140727 00:42:17 mysqld_safe Fatal error: Can't remove the pid file:
/var/run/mysqld/mysqld.pid
Please remove it manually and start /usr/bin/mysqld_safe again;
mysqld daemon not started
/usr/bin/mysqld_safe: 129: /usr/bin/mysqld_safe: cannot create /var/log/mysql/error.log: Permission denied
Similarly, if I try to start the server as root:
mysqld_safe -p -u root
140727 00:54:08 mysqld_safe Logging to '/var/log/mysql/error.log'.
140727 00:54:08 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
/usr/bin/mysqld_safe: 129: /usr/bin/mysqld_safe: cannot create /var/log/mysql/error.log: Permission denied
/usr/bin/mysqld_safe: 1: eval: cannot create /var/log/mysql/error.log: Permission denied
140727 00:54:08 mysqld_safe mysqld from pid file /var/run/mysqld/mysqld.pid ended
/usr/bin/mysqld_safe: 129: /usr/bin/mysqld_safe: cannot create /var/log/mysql/error.log: Permission denied
Apparently there are many places where I should be changing permissions, which does not look like the way to go. Three questions:
Is there some evident point where I went wrong, or should I just uninstall and apt-get everything?
Should I have owner mysql and group mysql for all files that the server needs to update?
Is there a comprehensive list of locations where these files are?

You cannot create /var/log/mysql/error.log. First create the directory if it doesn't exist
sudo mkdir -p /var/log/mysql
Next, change ownership
sudo chown -R mysql /var/log/mysql
and then try again to start the server as root:
sudo mysqld_safe --user=mysql &
If the server does not start paste here the error messages

Related

Error with ibdata1 write when starting customised Docker MySQL container as non-root user

I need to start a MySQL container based on a MySQL image having an existing database as part of the image and set as the default database. It needs to run with non-root user of mysql since running as root is not permitted on our private Kubernetes cluster. Referencing another solution from SO for starting MySQL with a pre-existing database, created below Dockerfile. It started up a container successfully locally on Docker desktop UNTIL I made changes to try and make container runnable as user mysql.
The database schema was output from existing database on a VM using mysqdump and out to eddie_backup2.sql.
Dockerfile:
FROM containerregistry-na.foocompany/container-external/mysql:5.7.29 as builder
# That file does the DB initialization but also runs mysql daemon, by removing the last line it will only init
RUN ["sed", "-i", "s/exec \"$#\"/echo \"not running $#\"/", "/usr/local/bin/docker-entrypoint.sh"]
ENV MYSQL_ALLOW_EMPTY_PASSWORD="y"
ENV MYSQL_USER="eddie" MYSQL_PASSWORD="eddie_pwd" MYSQL_DATABASE="eddie"
ADD eddie_backup2.sql /tmp/eddie_backup2.sql
COPY setup.sql docker-entrypoint-initdb.d/
# Need to change the datadir to something else that /var/lib/mysql because the parent docker file defines it as a volume.
# https://docs.docker.com/engine/reference/builder/#volume :
# Changing the volume from within the Dockerfile: If any build steps change the data within the volume after
# it has been declared, those changes will be discarded.
RUN ["/usr/local/bin/docker-entrypoint.sh", "mysqld", "--datadir", "/initialized-db" ]
# added below line to change ownership
RUN ["/bin/bash", "-c", "chown -R mysql:mysql /initialized-db/"]
# starting with mysql image again and using the generated datadirectory from above interim image
FROM containerregistry.foocompany.net/container-external/mysql:5.7.29 as actual_base
COPY --from=builder /initialized-db /var/lib/mysql
# change owner to mysql and list immediately to verify it was done
RUN ["/bin/bash", "-c", "chown -R mysql:mysql ./var/lib/mysql/ -v && ls -lrt /var/lib/mysql"]
USER mysql
CMD mysqld --datadir=/var/lib/mysql --user=mysql
MySQL script setup.sql run at initialisation, as it is located in special directory where the process looks:
use eddie;
source /tmp/eddie_backup2.sql ;
However, the logs indicated an issue with permissions to write to Innodb* folders. I think these are or should be present under /var/lib/mysql . That is as far as I got.
docker build --no-cache -t eddie-mysql:0.3 .
Logs:
changed ownership of './var/lib/mysql/performance_schema/file_summary_by_event_n
ame.frm' from root:root to mysql:mysql
changed ownership of './var/lib/mysql/performance_schema/events_transactions_sum
mary_by_thread_by_event_name.frm' from root:root to mysql:mysql
changed ownership of './var/lib/mysql/performance_schema/hosts.frm' from root:ro
ot to mysql:mysql
changed ownership of './var/lib/mysql/performance_schema' from root:root to mysq
l:mysql
changed ownership of './var/lib/mysql/ib_buffer_pool' from root:root to mysql:my
sql
changed ownership of './var/lib/mysql/ca.pem' from root:root to mysql:mysql
changed ownership of './var/lib/mysql/private_key.pem' from root:root to mysql:m
ysql
changed ownership of './var/lib/mysql/ibdata1' from root:root to mysql:mysql
changed ownership of './var/lib/mysql/auto.cnf' from root:root to mysql:mysql
changed ownership of './var/lib/mysql/client-key.pem' from root:root to mysql:my
sql
ownership of './var/lib/mysql/' retained as mysql:mysql
total 176196
-rw------- 1 mysql mysql 1680 Oct 2 15:07 server-key.pem
-rw-r--r-- 1 mysql mysql 1112 Oct 2 15:07 server-cert.pem
-rw-r----- 1 mysql mysql 50331648 Oct 2 15:07 ib_logfile1
-rw-r--r-- 1 mysql mysql 1112 Oct 2 15:07 ca.pem
-rw------- 1 mysql mysql 1676 Oct 2 15:07 ca-key.pem
-rw-r----- 1 mysql mysql 56 Oct 2 15:07 auto.cnf
-rw------- 1 mysql mysql 1680 Oct 2 15:07 client-key.pem
-rw-r--r-- 1 mysql mysql 1112 Oct 2 15:07 client-cert.pem
-rw-r--r-- 1 mysql mysql 452 Oct 2 15:07 public_key.pem
-rw------- 1 mysql mysql 1680 Oct 2 15:07 private_key.pem
-rw-r----- 1 mysql mysql 79691776 Oct 2 15:07 ibdata1
-rw-r----- 1 mysql mysql 50331648 Oct 2 15:07 ib_logfile0
-rw-r----- 1 mysql mysql 1452 Oct 2 15:07 ib_buffer_pool
drwxr-x--- 2 mysql mysql 12288 Oct 2 15:07 sys
drwxr-x--- 2 mysql mysql 4096 Oct 2 15:07 performance_schema
drwxr-x--- 2 mysql mysql 4096 Oct 2 15:07 mysql
drwxr-x--- 2 mysql mysql 4096 Oct 2 15:07 eddie
Removing intermediate container 29e35ac511ea
---> ce46892514e4
Step 13/14 : USER mysql
---> Running in fd1831317581
Removing intermediate container fd1831317581
---> ae9d3e300cbf
Step 14/14 : CMD mysqld --datadir=/var/lib/mysql --user=mysql
---> Running in 17143095e06f
Removing intermediate container 17143095e06f
---> 9712fc738c4c
Successfully built 9712fc738c4c
Successfully tagged eddie-mysql:0.3
It can be seen above ibdata1 ownership changed to mysql. This is relevant later . .
docker run -d --name abc eddie-mysql:0.3
docker logs 746a210065840
Below log indicates ibdata is not writeable by user mysql even though according to image build log it is owned by mysql !
2020-10-02T15:13:08.264040Z 0 [Note] InnoDB: Completed initialization of buffer
pool
2020-10-02T15:13:08.265201Z 0 [Note] InnoDB: If the mysqld execution user is aut
horized, page cleaner thread priority can be changed. See the man page of setpri
ority().
2020-10-02T15:13:08.275162Z 0 [ERROR] InnoDB: The innodb_system data file 'ibdat
a1' must be writable
2020-10-02T15:13:08.275231Z 0 [ERROR] InnoDB: The innodb_system data file 'ibdat
a1' must be writable
2020-10-02T15:13:08.275263Z 0 [ERROR] InnoDB: Plugin initialization aborted with
error Generic error
2020-10-02T15:13:08.876474Z 0 [ERROR] Plugin 'InnoDB' init function returned err
or.
2020-10-02T15:13:08.876491Z 0 [ERROR] Plugin 'InnoDB' registration as a STORAGE
ENGINE failed.
2020-10-02T15:13:08.876494Z 0 [ERROR] Failed to initialize builtin plugins.
2020-10-02T15:13:08.876496Z 0 [ERROR] Aborting
2020-10-02T15:13:08.876500Z 0 [Note] Binlog end
2020-10-02T15:13:08.876723Z 0 [Note] Shutting down plugin 'CSV'
2020-10-02T15:13:08.877008Z 0 [Note] mysqld: Shutdown complete
This may not be the most elegant solution but as mentioned earlier I could see that user mysql owns the file as a result of the chown added to my dockerfile. However discovered, it did not have write permission to it (confimred that after temporarily adding RUN ls -lrt /var/lib/mysql -v to list folder perms for debugging purposes ) which makes sense given the error message. Seems there is no publicly available image that takes care of this use case of starting a mySQL container as non root user.
So amended my Dockerfile to give most priveleged permissions to file ibdata1 (as well as the containing folder for good measure) right after mysqld initialisation with no-default data directory:
RUN ["/usr/local/bin/docker-entrypoint.sh", "mysqld", "--datadir", "/initialized-db" ]
RUN ["/bin/bash", "-c", "chown -R mysql:mysql /initialized-db/"]
RUN ["/bin/bash", "-c", "chmod ugo=rwx -R /initialized-db/"]
RUN chmod -R ugo+rwx /initialized-db/ibdata1
Here is the pertinent part of the build log:
Step 9/13 : RUN ["/bin/bash", "-c", "chown -R mysql:mysql /initialized-db/"]
---> Running in 973c96b0f535
Removing intermediate container 973c96b0f535
---> f190deb49406
Step 10/13 : RUN ["/bin/bash", "-c", "chmod ugo=rwx -R /initialized-db/"]
---> Running in 2e4612d7674c
Removing intermediate container 2e4612d7674c
---> efa6715342e2
Step 11/13 : RUN chmod -R ugo+rwx /initialized-db/ibdata1
---> Running in 3c2e288c19b7
Removing intermediate container 3c2e288c19b7
---> 1c0e7a32b2a4
Step 12/13 : FROM some-private-registry.net/container-external/mysql:5.7
.29 as actual_base
---> 5d9483f9a7b2
Step 13/13 : COPY --from=builder /initialized-db /var/lib/mysql
---> 19f51e56ae40
I could then run the image as user mysql:
docker container run -d --user mysql --name foo_name --user mysql foo-mysql:1.0

Docker run command with -v flag puts container in Exited status

I am trying to map a local directory /home/ubuntu/data to /var/lib/mysql folder in container by using -v flag but container's status becomes Exited (0) 1. However, if I don't use -v flag at all, container is Up but this is not what I want. What could be the reason? I see volume mount line is missing in event logs opposed to working example.
$ docker -v
Docker version 17.09.0-ce, build afdb6d4
Dockerfile
FROM ubuntu:16.04
RUN apt-get update \
&& DEBIAN_FRONTEND=noninteractive apt-get install -y mysql-server \
&& sed -i "s/127.0.0.1/0.0.0.0/g" /etc/mysql/mysql.conf.d/mysqld.cnf \
&& mkdir /var/run/mysqld \
&& chown -R mysql:mysql /var/run/mysqld
VOLUME ["/var/lib/mysql"]
EXPOSE 3306
CMD ["mysqld_safe"]
This is the which doesn't work.
$ docker run -i -t -d -v /home/ubuntu/data:/var/lib/mysql --name mysql_container mysql_image
Event logs.
2017-11-... container create 08b44c094... (image=mysql_image, name=mysql_container)
2017-11-... network connect 62bb211934... (container=08b44c094..., name=bridge, type=bridge)
2017-11-... container start 08b44c094... (image=mysql_image, name=mysql_container)
2017-11-... container die 08b44c094... (exitCode=0, image=mysql_image, name=mysql_container)
2017-11-... network disconnect 62bb211934... (container=08b44c094..., name=bridge, type=bridge)
Container logs.
$ docker logs -t mysql_container
2017-11-... mysqld_safe Logging to syslog.
2017-11-... mysqld_safe Logging to '/var/log/mysql/error.log'.
2017-11-... mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
This works without -v
$ docker run -i -t -d --name mysql_container mysql_image
Event logs.
2017-11-... container create 84993141... (image=mysql_image, name=mysql_container)
2017-11-... network connect 62bb2119... (container=84993141..., name=bridge, type=bridge)
2017-11-... volume mount 8c36b53d33... (container=84993141...7, destination=/var/lib/mysql, driver=local, propagation=, read/write=true)
2017-11-... container start 84993141... (image=mysql_image, name=mysql_container)
Container logs.
$ docker logs -t mysql_container
2017-11-... mysqld_safe Logging to syslog.
2017-11-... mysqld_safe Logging to '/var/log/mysql/error.log'.
2017-11-... mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
2017-11-... mysqld_safe mysqld from pid file /var/run/mysqld/mysqld.pid ended
It's a little complicated but interesting case.
So how you can check what's happening? Use following command:
docker run -i -t -v /tmp/data:/var/lib/mysql mysql_image bash
Now you are inside container so let's try command:
mysqld_safe
And it's ending but let's look into /var/log/mysql/error.log
We see there:
2017-11-25T17:22:24.006180Z 0 [ERROR] InnoDB: Operating system error number 13 in a file operation.
2017-11-25T17:22:24.006211Z 0 [ERROR] InnoDB: The error means mysqld does not have the access rights to the directory.
2017-11-25T17:22:24.006221Z 0 [ERROR] InnoDB: Operating system error number 13 in a file operation.
2017-11-25T17:22:24.006229Z 0 [ERROR] InnoDB: The error means mysqld does not have the access rights to the directory.
2017-11-25T17:22:24.006237Z 0 [ERROR] InnoDB: Cannot open datafile './ibdata1'
Ok let's see how /var/lib/mysql looks without volume mapping:
root#4474b1cd4300:/var/lib/mysql# ls -lah
total 109M
drwx------ 5 mysql mysql 4.0K Nov 25 17:24 .
drwxr-xr-x 1 root root 4.0K Nov 25 17:13 ..
-rw-r----- 1 mysql mysql 56 Nov 25 17:13 auto.cnf
-rw-r--r-- 1 root root 0 Nov 25 17:13 debian-5.7.flag
-rw-r----- 1 mysql mysql 419 Nov 25 17:13 ib_buffer_pool
-rw-r----- 1 mysql mysql 48M Nov 25 17:13 ib_logfile0
-rw-r----- 1 mysql mysql 48M Nov 25 17:13 ib_logfile1
-rw-r----- 1 mysql mysql 12M Nov 25 17:13 ibdata1
drwxr-x--- 2 mysql mysql 4.0K Nov 25 17:13 mysql
drwxr-x--- 2 mysql mysql 4.0K Nov 25 17:13 performance_schema
drwxr-x--- 2 mysql mysql 12K Nov 25 17:13 sys
mysql:mysql is owner of that directory
We have a lot mysql specific files there
Let's see what we've got with volume mapping:
root#fca45ee1e8fb:/var/lib/mysql# ls -lah
total 8.0K
drwxr-xr-x 2 root root 4.0K Nov 25 17:22 .
drwxr-xr-x 1 root root 4.0K Nov 25 17:13 ..
Docker is mapping this directory as root user
Docker is mapping this directory into host so all files disappear because on host machine that directory is empty
How to get this work?
Change your command to:
CMD chown -R mysql:mysql /var/lib/mysql && if [ ! -c /var/lib/mysql/ibdata1 ]; then mysqld --initialize-insecure; fi && mysqld_safe
What's happening there?
chown -R mysql:mysql /var/lib/mysql - get back mysql:mysql owner
if [ ! -c /var/lib/mysql/ibdata1 ]; then mysqld --initialize-insecure; fi - recreate mysql files with root user without pass but only if files not already exists (required for next runs)
mysqld_safe - run mysql

How to kill mysql started with "mysql_safe" script?

Short version: I started mysql with mysql_safe and I can't kill it.
Long version: Installing an older version of mysql with macport displayed this suggestion:
$ sudo port install mysql55-server
---> Computing dependencies for mysql55-server
---> Fetching archive for mysql55-server
---> Attempting to fetch mysql55-server-5.5.49_0.darwin_14.noarch.tbz2 from https://packages.macports.org/mysql55-server
---> Attempting to fetch mysql55-server-5.5.49_0.darwin_14.noarch.tbz2.rmd160 from https://packages.macports.org/mysql55-server
---> Installing mysql55-server #5.5.49_0
---> Activating mysql55-server #5.5.49_0
If this is a new install you might want to run:
$ sudo -u _mysql /opt/local/lib/mysql55/bin/mysql_install_db
Running that gave these instructions:
$ sudo -u _mysql /opt/local/lib/mysql55/bin/mysql_install_db
Installing MySQL system tables...
161102 13:15:44 [Note] /opt/local/lib/mysql55/bin/mysqld (mysqld 5.5.49) starting as process 54176 ...
OK
Filling help tables...
161102 13:15:44 [Note] /opt/local/lib/mysql55/bin/mysqld (mysqld 5.5.49) starting as process 54180 ...
OK
To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system
PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
To do so, start the server, then issue the following commands:
/opt/local/lib/mysql55/bin/mysqladmin -u root password 'new-password'
/opt/local/lib/mysql55/bin/mysqladmin -u root -h myusername password 'new-password'
Alternatively you can run:
/opt/local/lib/mysql55/bin/mysql_secure_installation
which will also give you the option of removing the test
databases and anonymous user created by default. This is
strongly recommended for production servers.
See the manual for more instructions.
You can start the MySQL daemon with:
cd /opt/local ; /opt/local/lib/mysql55/bin/mysqld_safe &
You can test the MySQL daemon with mysql-test-run.pl
cd /opt/local/mysql-test ; perl mysql-test-run.pl
Please report any problems at http://bugs.mysql.com/
At this point I (unwisely, it seems) ran:
$ cd /opt/local ; /opt/local/lib/mysql55/bin/mysqld_safe &
Now I cannot figure out how to stop the mysql and/or daemondo process(es):
$ ps aux | grep mysql55
myusername 54937 0.1 0.0 2432772 660 s001 R+ 1:39PM 0:00.00 grep mysql55
_mysql 54888 0.0 0.1 2667884 6340 ?? S 1:36PM 0:00.12 /opt/local/lib/mysql55/bin/mysqld --user=_mysql
root 54885 0.0 0.0 2479468 700 ?? Ss 1:36PM 0:00.00 /opt/local/bin/daemondo --label=mysql55-server --start-cmd /opt/local/lib/mysql55/bin/mysqld --user=_mysql ; --pid=exec
I've tried many variations of kill, targeting both mysql (which seems pointless) and daemondo, including (but not limited to) the following:
sudo kill -9 54888 // killing the mysql process results in a new pid
sudo kill 54885 // the doemondo process
sudo kill -SIGHUP 54885
sudo killall mysqld_safe
sudo kill -9 54822 // a reincarnation of the doemondo process
sudo mysqladmin shutdown
For centos or mint
/usr/bin# initctl
for ubuntu
pkill mysqld

cannot touch `/var/log/mysqld.log': Permission denied

i have reinstalled mysql server in cent OS RHEL5.5 , Im getting the following error
touch: cannot touch `/var/log/mysqld.log': Permission denied
chown: changing ownership of `/var/log/mysqld.log': Operation not permitted
chmod: changing permissions of `/var/log/mysqld.log': Operation not permitted
MySQL Daemon failed to start.
Starting mysqld: [FAILED]
I have checked the permissions for log files , its having correct permissions as mysql user
-rw-r----- 1 mysql mysql 5931 Mar 9 04:36 mysqld.log
Please let me know the issue on this and how to solve it.
Thanks
Ok. I have solved the issue,
$ /usr/libexec/mysqld --skip-grant &
[1] 5388
InnoDB: Error: log file ./ib_logfile0 is of different size 0 50331648 bytes
InnoDB: than specified in the .cnf file 0 5242880 bytes!
150312 10:03:28 [Note] /usr/libexec/mysqld: ready for connections.
Version: '5.0.95' socket: '/var/lib/mysql/mysql.sock' port: 3306 Source distribution
$ rm -rf /var/lib/mysql/ib_logfile0
$ rm -rf /var/lib/mysql/ib_logfile1
$ ls -l /var/lib/mysql
i have removed the log files and restart the mysql server.
Thanks
The workaround is:
$ sudo touch /var/log/mysqld.log
$ sudo chown mysql:mysql /var/log/mysqld.log
$ sudo chcon system_u:object_r:mysqld_log_t:s0 /var/log/mysqld.log
In my case, this happened to me after downgrading an AWS EC2 instance. The error was as follows:
$ service mysqld start
touch: cannot touch ‘/var/log/mysqld.log’: Permission denied
chown: changing ownership of ‘/var/log/mysqld.log’: Operation not permitted
chmod: changing permissions of ‘/var/log/mysqld.log’: Operation not permitted
chown: changing ownership of ‘/var/lib/mysql’: Operation not permitted
chmod: changing permissions of ‘/var/lib/mysql’: Operation not permitted
MySQL Daemon failed to start.
Starting mysqld: [FAILED]
Turns out the issue was the new downgraded VM didn't have enough memory as MySQL was trying to reserve.
Updating the value reserved for InnoDB on etc/my.cnf solved the issue:
innodb_buffer_pool_size=4G
No other changes on the file system permissions were needed.
In my case, there is problem with ubuntu apparmor.
Solution:
Edit mysqld profiles (usually in /etc/apparmor.d/usr.sbin.mysqld) and make sure you have:
/var/log/mysqld.log rw,
systemctl reload apparmor
touch /var/log/mysqld.log
chown mysql:mysql /var/log/mysqld.log
chmod 0644 /var/log/mysqld.log
systemctl restart mysql

MySql server PID not found

I have CentOS 6.4 with NGINX.
When I try to start/stop/restart mysql server (/etc/init.d/mysqld restart) I get this error:
MySQL server PID file could not be found! [FAILED]
Starting MySQL..The server quit without updating PID file ([FAILED]/mysql/mysqld.pid).
What can I do to solve this problem?
Thanks!
I got the same error on a CentOS 6.3 where I upgraded MySQL to 5.6.14 but I kept the old my.cnf file. After upgrade, MySQL did not start anymore, giving me the same error as you described.
The problem was that I had this setting in my.cnf:
table_cache=2048
According to this link table_cache renamed table_open_cache..
"Seem like in 5.5 the system variable table_cache was renamed
table_open_cache..
In 5.6 mysqld fails if it finds an unknown variable
this means that upgrades from versions earlier than 5.5 can have
problems if table_cache is specified in my.cnf."
After I changed the above line to
table_open_cache=2048
MySQL started perfectly.
So, in the case you have MySQL 5.5+ (and maybe an older my.cnf), I suggest you to do the following:
remove my.cnf from /etc folder and try to start MySQL
if MySQL starts, the the problem is in my.cnf. Comment/uncomment all the settings one by one in order to see which is causing the problem.
Hope this helps.
I upgraded my Mac OS to 10.9.3 and encountered the above problem on mysql.server restart
The following fixed my problem
sudo chmod -R o+rwx /usr/local/var/mysql/
sudo chown -R mysql /usr/local/var/mysql/
sudo mysql.server restart
First of all make sure that which folder/file is not exist in /var/run/mysqld/mysqld.pid
if dir not exists then create it as:
sudo mkdir -p /var/run/mysqld/
if mysqld.pid is not exists then create it as:
sudo touch /var/run/mysqld/mysqld.pid
change ownership as:
sudo chown mysql:mysql -R /var/run/mysqld
chmod 775 -R /var/run/mysqld
restart mysql service
sudo service mysql restart
I find that sometimes MySQL processes are still running. Certainly this was the case on my OS X Yosemite system so use the following command to find any processes that show up with MySQL in the name:
ps aux | grep mysql
Then kill them using the command
sudo kill -9 PID, replacing PID with the offending process ID.
Check if there is a lock.
/etc/init.d/mysql status
If the OS says that there is a lock, something like:
ERROR! MySQL is not running, but lock file (/var/lock/subsys/mysql) exists
remove that lock file and restart.
I found this worked....
# ps aux | grep mysql
root 3668 0.0 0.0 11432 1240 ? S 2014 0:00 /bin/sh /usr/bin/mysqld_safe --datadir=/db/data01 --pid-file=/var/lib/mysql/mysql.pid
mysql 5303 0.1 0.4 1964748 12368 ? S<l 2014 1663:35 /usr/sbin/mysqld --basedir=/usr --datadir=/db/data01 --plugin-dir=/usr/lib64/mysql/plugin --user=mysql --log-error=/db/logs01/mysql-error.err --open-files-limit=8192 --pid-file=/var/lib/mysql/mysql.pid --socket=/var/lib/mysql/mysql.sock --port=3306
root 12369 0.0 0.0 6376 680 pts/0 S+ 09:05 0:00 grep mysql
# kill -9 3668 5303
# rm /var/lock/subsys/mysql rm: remove regular empty file `/var/lock/subsys/mysql'? y
# service mysql start Starting MySQL (Percona Server).. SUCCESS!