Ok, i'm following official Mysql docs to enable encryption on a mysql database on docker:
Using the keyring_file File-Based Plugin
Keyring Plugin Installation
keyring_file_data
So here's what i've done:
added early-plugin-load and keyring_file_data to /etc/mysql/my.cnf (i used echo stuff >> file since mysql docker image has no text editor), so now it is:
[mysqld]
pid-file = /var/run/mysqld/mysqld.pid
socket = /var/run/mysqld/mysqld.sock
datadir = /var/lib/mysql
secure-file-priv= NULL
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
# Custom config should go here
!includedir /etc/mysql/conf.d/
early-plugin-load=keyring_file.so
keyring_file_data=/usr/local/mysql/mysql-keyring/keyring
created keyring file with
cd /usr/local/mysql
mkdir mysql-keyring
chmod 750 mysql-keyring
chown mysql mysql-keyring
chgrp mysql mysql-keyring
restarted container to restart mysql
connected to mysql and checked plugin availability (whith no luck) with
mysql> SELECT PLUGIN_NAME, PLUGIN_STATUS
FROM INFORMATION_SCHEMA.PLUGINS
WHERE PLUGIN_NAME LIKE 'keyring%';
Checked the logs for errors:
2020-03-15T12:30:08.669015Z 0 [ERROR] [MY-011370] [Server] Plugin keyring_file reported: 'File '/usr/local/mysql/mysql-keyring/keyring' not found (OS errno 20 - Not a directory)'
2020-03-15T12:30:08.669036Z 0 [ERROR] [MY-011355] [Server] Plugin keyring_file reported: 'keyring_file initialization failure. Please check if the keyring_file_data points to readable keyring file or keyring file can be created in the specified location. The keyring_file will stay unusable until correct path to the keyring file gets provided'
2020-03-15T12:30:08.669053Z 0 [ERROR] [MY-010202] [Server] Plugin 'keyring_file' init function returned error.
So it look like that i correctly enabled the plugin, but something is wrong with the file.
Am i missing some steps?
keyring file
root#8c3670db35d4:/# ls -la /usr/local/mysql/mysql-keyring/
total 8
drwxr-s--- 2 mysql mysql 4096 Mar 15 12:34 .
drwxr-sr-x 3 root staff 4096 Mar 15 12:33 ..
-rw-r----- 1 mysql mysql 0 Mar 15 12:34 keyring
Are you sure you created the keyring file correctly inside the container ? This is how I was able to achieve the above with a correctly crafted Dockerfile.
Create a folder for your image project (use whatever folder you like)
mkdir /tmp/testMysqlKeyring
cd /tmp/testMysqlKeyring
Create a mysql keyring dropin configuration file keyring.cnf with the following content:
[mysqld]
early-plugin-load=keyring_file.so
keyring_file_data=/usr/local/mysql/mysql-keyring/keyring
Create a Dockerfile with the following content
FROM mysql:8
# Place the dropin config file in the relevant folder
COPY keyring.cnf /etc/mysql/conf.d/
# Create the keyring folder and adapt perms
RUN mkdir -p /usr/local/mysql/mysql-keyring && \
chmod 750 /usr/local/mysql/mysql-keyring && \
chown mysql.mysql /usr/local/mysql/mysql-keyring
Build image from the above configuration:
docker build -t file_keyringed_mysql:latest .
Run a container from that image (you will adapt with your exact volumes and environment later...)
docker run -d --rm --name my_keyring_test -e MYSQL_ALLOW_EMPTY_PASSWORD=true file_keyringed_mysql:latest
Check that plugin is correctly installed inside the container
$ docker exec my_keyring_test mysql -e "SELECT PLUGIN_NAME, PLUGIN_STATUS FROM INFORMATION_SCHEMA.PLUGINS WHERE PLUGIN_NAME LIKE 'keyring%';"
PLUGIN_NAME PLUGIN_STATUS
keyring_file ACTIVE
Related
I'm running docker in Ubuntu and trying to create and run a MySql container. I want to use a mounted network share for the data directory. I am trying the following docker run command, but I'm having issues with permissions. How do I fix this?
root#jarvis:/mnt/wayne/mysql-data$ sudo docker run -it -p 3306:3306 -e MYSQL_ROOT_PASSWORD=admin -v /mnt/wayne/mysql:/var/lib/mysql/ --name mysqlserver mysql/mysql-server
[Entrypoint] MySQL Docker Image 8.0.20-1.1.16
[Entrypoint] Initializing database
2020-06-08T21:43:25.253898Z 0 [System] [MY-013169] [Server] /usr/sbin/mysqld (mysqld 8.0.20) initializing of server in progress as process 22
2020-06-08T21:43:25.281460Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2020-06-08T21:43:27.815075Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
mysqld: Cannot change permissions of the file 'ca.pem' (OS errno 1 - Operation not permitted)
2020-06-08T21:43:29.851875Z 0 [ERROR] [MY-010295] [Server] Could not set file permission for ca.pem
2020-06-08T21:43:29.852970Z 0 [ERROR] [MY-013236] [Server] The designated data directory /var/lib/mysql/ is unusable. You can remove all files that the server added to it.
2020-06-08T21:43:29.854806Z 0 [ERROR] [MY-010119] [Server] Aborting
2020-06-08T21:43:31.947298Z 0 [System] [MY-010910] [Server] /usr/sbin/mysqld: Shutdown complete (mysqld 8.0.20) MySQL Community Server - GPL.
You use CIFs for network mount means the remote server is windows right? My answer is based on this assumption.
The latest mysql docker image has a user named mysql and its uid=27,gid=27
You verify this by mounting an empty folder as data_dir. You will see that the files created by mysql container has user and group is as 27.
Hence the mysql container expects files with uid/gid(owner userid and owner group id) as 27 in its data_dir. But the files that you mounted from the windows share has uid/gid which belongs to the user that executes mount command in ubuntu. This is the default behavior of mount command.
To solve this you need to pass "uid=27,gid=27" parameters to the Linux mount command.
For instance
sudo mount -t cifs -o
username=windows-username,uid=27,gid=27
//WIN_SHARE_IP/ /mnt/wayne
You can have look here for further details
I must say it is unlikely to run mysql over a network share. It won't perform well.
This is not exactly with MySQL but I hope it can give you an idea, I basically use this for testing against a MySQL database from my local environment, for this I use docker-compose and MariaDB, I configure the "data-dir" as a volume so that I can stop/start the docker container without the need to "seed" every time the database.
This is the content of the /your/path/docker-compose.yml file:
---
version: '3'
services:
mariadb:
image: mariadb:10.4.13
container_name: mariadb
restart: always
ports:
- 13306:3306
environment:
MYSQL_DATABASE: world
MYSQL_ROOT_PASSWORD: test
command: --transaction-isolation=READ-COMMITTED --binlog-format=ROW
volumes:
- ${PWD}/mariadb/db/:/var/lib/mysql
In the same directory, I have the volume directory /your/path/mariadb/db
Then to bring up the container I use:
$ docker-compose up
From the docker-compose.yml has you can see I use port 13306 therefore for testing/connection I use:
$ mysql -h 127.0.0.1 -P13306 -uroot -p
All the data (databases) will be in /your/path/mariadb/db
If you run into the same "permissions" problem:
mysqld: Cannot change permissions of the file 'ca.pem' (OS errno 1 - Operation not permitted)
Try to change the permissions of your volume/mount point, for example:
chmod -R 777 /your/volume/mount_point
okay, I tried this and google also, what I found is
https://github.com/docker-library/mysql/issues/302#issuecomment-308745834
So basically if you are using mysql:5.7 then upgrade to mysql:5.7.16.
And if this doesn't help then I have one more solution.
Basically the problem is you are sharing dir to container -v /mnt/wayne/mysql:/var/lib/mysql/ but you ubuntu is not giving permission to access the /mnt/wayne/mysql dir. so give admin permission to this location or you can create a docker user chown and chmode.
Basically give permission to the host machine directory. so that docker container can access it.
and One more thing give permission to the docker container dir also, that is showing in your error
The designated data directory /var/lib/mysql/ is unusable. You can remove all files that the server added to it.
Create a user in a docker container which have chown and chmod permissions to the dir /var/lib/mysql/.
if you are using dockerfile to create mysql container then use these following 2 lines in it
FROM mysql:5.7.16
WORKDIR /app
RUN chown -R admin:admin /app
RUN chmod 755 /app
USER admin
CMD ["Your command"]
To operate normally, MariaDB or MySQL needs to set some permissions on their own files. Some external file systems (such as FTP and many others) do not support these features. You need to use a file system which supports these features.
there is a permission issue to access the mounted volume. Please read the documentation about use volumes:
https://docs.docker.com/storage/volumes/#use-a-volume-driver
For NFSv3 Partition:
$ docker service create -d \
--name nfs-service \
--mount 'type=volume,source=nfsvolume,target=/app,volume-driver=local,volume-opt=type=nfs,volume-opt=device=:/var/docker-nfs,volume-opt=o=addr=10.0.0.10' \
nginx:latest
Or check the CA.pem file permissions (use chmod 777 /path/to/ca.pem)
For NFSv4 Partition:
docker service create -d \
--name nfs-service \
--mount 'type=volume,source=nfsvolume,target=/app,volume-driver=local,volume-opt=type=nfs,volume-opt=device=:/var/docker-nfs,"volume-opt=o=10.0.0.10,rw,nfsvers=4,async"' \
nginx:latest
Check https://docs.docker.com/storage/volumes/#use-a-volume-driver
I've just compiled the version MySQL 8.0.12 in a Ubuntu 16.0.4.
After following the instructions in the website and making the following my.cnf file:
[mysqld]
datadir=/usr/local/mysql/data
socket=/tmp/mysql.sock
port=3306
log-error=/usr/local/mysql/data/localhost.localdomain.err
user=mysql
secure_file_priv=/usr/local/mysql/mysql-files
local_infile=OFF
log_error = /var/log/mysql/error.log
# Remove case sensitive in table names
lower_case_table_names=1
I get the following error:
2018-08-11T19:45:06.461585Z 1 [ERROR] [MY-011087] [Server] Different lower_case_table_names settings for server ('1') and data dictionary ('0').
What should I change so that data dictionary is aligned to server settings?
So far, I can get it to work with a workaround (I originally posted on askubuntu): by re-initializing MySQL with the new value for lower_case_table_names after its installation. The following steps apply to a new installation. If you have already data in a database, export it first to import it back later:
Install MySQL:
sudo apt-get update
sudo apt-get install mysql-server -y
Stop the MySQL service:
sudo service mysql stop
Delete the MySQL data directory:
sudo rm -rf /var/lib/mysql
Recreate the MySQL data directory (yes, it is not sufficient to just delete its content):
sudo mkdir /var/lib/mysql
sudo chown mysql:mysql /var/lib/mysql
sudo chmod 700 /var/lib/mysql
Add lower_case_table_names = 1 to the [mysqld] section in /etc/mysql/mysql.conf.d/mysqld.cnf.
Re-initialize MySQL with --lower_case_table_names=1:
sudo mysqld --defaults-file=/etc/mysql/my.cnf --initialize --lower_case_table_names=1 --user=mysql --console
Start the MySQL service:
sudo service mysql start
Retrieve the new generated password for MySQL user root:
sudo grep 'temporary password' /var/log/mysql/error.log
Change the password of MySQL user root either by:
sudo mysql -u root -p
and executing:
ALTER USER 'root'#'localhost' IDENTIFIED BY 'MyNewPa$$w0rd';
afterwards, OR by calling the "hardening" script anyway:
sudo mysql_secure_installation
After that, you can verify the lower_case_table_names setting by entering the MySQL shell:
sudo mysql -u root -p
and executing:
SHOW VARIABLES LIKE 'lower_case_%';
Expected output:
+------------------------+-------+
| Variable_name | Value |
+------------------------+-------+
| lower_case_file_system | OFF |
| lower_case_table_names | 1 |
+------------------------+-------+
As per this link, lower_case_table_names should be set together with --initialize option.
MySQL Documentation says
lower_case_table_names can only be configured while initializing the server. Changing the lower_case_table_names setting after the server is initialized is prohibited.
https://dev.mysql.com/doc/refman/8.0/en/identifier-case-sensitivity.html
The best way to prevent this problem is :At first add
[mysqld]
lower_case_table_names=1
then start mysql service for first time.
But anyway if you have started the server already,to solve your problem:
1.stop mysql:
systemctl stop mysql
2.clean data directory or change the default, the following is for new installations , if you have data in your database BACK UP them beforehand
rm -rf /var/lib/mysql
3.Insert lower_case_table_names = 1 in your my.cnf:
[mysqld]
lower_case_table_names=1
4.Start again
systemctl start mysqld
To fix this issue,
Just take the backup of the existing db Schema using the following command inside bin folder (/usr/local/mysql/bin)
./mysqldump -uroot -p password > dump.sql
Once the backup is taken delete the existing data folder in Mysql Home(/usr/local/mysql/) using the command
rm -rf data
Now add the configuration as "lower_case_table_names=1" in my.cnf under MYSQLD section (/etc/my.cnf)
Now Initialize the data directory using the following command inside bin directory (/usr/local/mysql/bin)
For Secure mode
./mysqld --defaults-file=/etc/my.cnf --initialize --user=mysql --console
For Insecure mode
./mysqld --defaults-file=/etc/my.cnf --initialize-insecure --user=mysql --console
Once the data directory initialized, For Insecure mode repeat the Installation again and For Secure mode use the root password which is initialized during the run time of data directory Initialization.
Now import the existing dump file inside the Mysql Server using the command inside (/usr/local/mysql/bin) directory
./mysql -uroot -p password < file.sql
If anyone runs into this issue now, if you already initialized mysql, meaning you already had it up and running and then this error occurred, just comment out this line in the my.ini file.
lower_case_table_names=
I'm using laradock.
when I use docker-compose up mysql
I got this error.
mysql_1 | Initializing database
mysql_1 | 2018-04-22T10:41:01.362165Z 0 [ERROR] --initialize specified but the data directory has files in it. Aborting.
mysql_1 | 2018-04-22T10:41:01.362585Z 0 [ERROR] Aborting
mysql_1 |
laradock_mysql_1 exited with code 1
I tried to add this setting on laradock/mysql/Dockerfile like this
ARG MYSQL_VERSION=latest
FROM mysql:${MYSQL_VERSION}
LABEL maintainer="Mahmoud Zalt <mahmoud#zalt.me>"
#####################################
# Set Timezone
#####################################
ARG TZ=UTC
ENV TZ ${TZ}
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
RUN chown -R mysql:root /var/lib/mysql/
COPY my.cnf /etc/mysql/conf.d/my.cnf
CMD ["mysqld --ignore-db-dir=lost+found"]
EXPOSE 3306
but, I'm still getting above error.
Do you have any idea on this solution?
Thanks,
I had a similar issue. In order to solve it, you have to
go to C:\Program Files\MySQL\MySQL Server 5.7
you will find a folder named data. rename it into data1.
launch command prompt as an administrator.
execute mysqld --initialize-insecure.
go to the services in the control panel, stop all services related to MySql such as MySQL57.
Start MySQL
Console says
[root#ip-172-31-18-2 mysql]# service mysqld start
Starting mysqld (via systemctl): Job for mysqld.service failed because the control process exited with an error code. See "systemctl status mysqld.service" and "journalctl -xe" for details.
mysqld.service
[root#ip-172-31-18-2 mysql]# systemctl status mysqld.service
● mysqld.service - SYSV: MySQL database server.
Loaded: loaded (/etc/rc.d/init.d/mysqld)
Active: failed (Result: exit-code) since Sat 2017-02-18 20:59:17 IST; 36s ago
Docs: man:systemd-sysv-generator(8)
Process: 9925 ExecStart=/etc/rc.d/init.d/mysqld start (code=exited, status=1/FAILURE)
Feb 18 20:59:16 ip-172-31-18-2.ap-southeast-1.compute.internal systemd[1]: Starting SYSV: MySQL database server....
Feb 18 20:59:17 ip-172-31-18-2.ap-southeast-1.compute.internal mysqld[9925]: MySQL Daemon failed to start.
Feb 18 20:59:17 ip-172-31-18-2.ap-southeast-1.compute.internal mysqld[9925]: Starting mysqld: [FAILED]
Feb 18 20:59:17 ip-172-31-18-2.ap-southeast-1.compute.internal systemd[1]: mysqld.service: control process exited, code=exited status=1
Feb 18 20:59:17 ip-172-31-18-2.ap-southeast-1.compute.internal systemd[1]: Failed to start SYSV: MySQL database server..
Feb 18 20:59:17 ip-172-31-18-2.ap-southeast-1.compute.internal systemd[1]: Unit mysqld.service entered failed state.
Feb 18 20:59:17 ip-172-31-18-2.ap-southeast-1.compute.internal systemd[1]: mysqld.service failed.
What I have tried until now:
mysqld_safe --defaults-file=/etc/my.cf
chown -R mysql:mysql /var/lib/mysql
/etc/init.d/mysqld start
/etc/init.d/mysqld stop
systemctl restart systemd-logind
rebooted the server
Still no luck.
my.cnf file
# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html
[mysqld]
#
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for a dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
#
# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin
#
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
This amazingly worked.
/etc/init.d/mysql stop
service mysql stop
killall -KILL mysql mysqld_safe mysqld
/etc/init.d/mysql start
service mysql start
I had the same error, the problem was because I no longer had disk space.
to check the space run this:
$ df -h
Then delete some files that you didn't need.
After this commands:
service mysql start
systemctl status mysql.service
mysql -u root -p
After entering with the root password verify that the mysql service was active
I met this problem today, and fix it with bellowed steps.
1, Check the log file /var/log/mysqld.log
tail -f /var/log/mysqld.log
2017-03-14T07:06:53.374603Z 0 [ERROR] /usr/sbin/mysqld: Can't create/write to file '/var/run/mysqld/mysqld.pid' (Errcode: 2 - No such file or directory)
2017-03-14T07:06:53.374614Z 0 [ERROR] Can't start server: can't create PID file: No such file or directory
The log says that there isn't a file or directory /var/run/mysqld/mysqld.pid
2, Create the directory /var/run/mysqld
mkdir -p /var/run/mysqld/
3, Start the mysqld again service mysqld start, but still fail, check the log again /var/log/mysqld.log
2017-03-14T07:14:22.967667Z 0 [ERROR] /usr/sbin/mysqld: Can't create/write to file '/var/run/mysqld/mysqld.pid' (Errcode: 13 - Permission denied)
2017-03-14T07:14:22.967678Z 0 [ERROR] Can't start server: can't create PID file: Permission denied
It saids permission denied.
4, Grant the permission to mysql
chown mysql.mysql /var/run/mysqld/
5, Restart the mysqld
# service mysqld restart
Restarting mysqld (via systemctl): [ OK ]
These are the steps I took to correct this:
Back up your my.cnf file in /etc/mysql and remove or rename it
sudo mv /etc/mysql/my.cnf /etc/mysql/my.cnf.bak
Remove the folder /etc/mysql/mysql.conf.d/ using
sudo rm -r /etc/mysql/mysql.conf.d/
Verify you don't have a my.cnf file stashed somewhere else (I did in my home dir!) or in /etc/alternatives/my.cnf use
sudo find / -name my.cnf
Now reinstall every thing
sudo apt purge mysql-server mysql-server-5.7 mysql-server-core-5.7
sudo apt install mysql-server
In case your syslog shows an error like "mysqld: Can't read dir of '/etc/mysql/conf.d/'" create a symbolic link:
sudo ln -s /etc/mysql/mysql.conf.d /etc/mysql/conf.d
Then the service should be able to start with sudo service mysql start.
I hope it work
In my particular case, the error was appearing due to missing /var/log/mysql with mysql-server package 5.7.21-1 on Debian-based Linux distro. Having ran strace and sudo /usr/sbin/mysqld --daemonize --pid-file=/run/mysqld/mysqld.pid ( which is what the systemd service actually runs), it became apparent that the issue was due to this:
2019-01-01T09:09:22.102568Z 0 [ERROR] Could not open file '/var/log/mysql/error.log' for error logging: No such file or directory
I've recently removed contents of several directories in /var/log so it was no surprise. The solution was to create the directory and make it owned by mysql user as in
$ sudo mkdir /var/log/mysql
$ sudo chown -R mysql:mysql /var/log/mysql
Having done that I've happily logged in via sudo mysql -u root and greeted with the old and familiar mysql> prompt
if your problem not fix, you can try check more problem.
maybe mysql crash , like this :
you can check log in
sudo cat /var/log/mysql/error.log
or you check
sudo ls /var/crash
try
sudo chown mysql:mysql -R /var/lib/mysql
then start your mysql service
systemctl start mysqld
the issue is with the "/etc/mysql/my.cnf". this file must be modified by other libraries that you installed. this is how it originally should look like:
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License, version 2.0,
# as published by the Free Software Foundation.
#
# This program is also distributed with certain software (including
# but not limited to OpenSSL) that is licensed under separate terms,
# as designated in a particular file or component or in included license
# documentation. The authors of MySQL hereby grant you an additional
# permission to link the program and your derivative works with the
# separately licensed software that they have included with MySQL.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License, version 2.0, for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#
# The MySQL Server configuration file.
#
# For explanations see
# http://dev.mysql.com/doc/mysql/en/server-system-variables.html
# * IMPORTANT: Additional settings that can override those from this file!
# The files must end with '.cnf', otherwise they'll be ignored.
#
!includedir /etc/mysql/conf.d/
!includedir /etc/mysql/mysql.conf.d/
I was also facing same issue .
root#*******:/root >mysql -uroot -password
mysql: [Warning] Using a password on the command line interface can be
insecure. ERROR 2002 (HY000): Can't connect to local MySQL server
through socket '/var/lib/mysql/mysql.sock' (2)
I found ROOT FS was also full and then I killed below lock session .
root#**********:/var/lib/mysql >ls -ltr
total 0
-rw------- 1 mysql mysql 0 Sep 9 06:41 mysql.sock.lock
Finally Issue solved .
open my.cnf and copy the log-error path
then check the permission for the copied log file using
$ ls -l /var/log/mysql.log
if any log file permission may changed from mysql:mysql, please change the file permission to
$ chown -R mysql:mysql /var/log/mysql.log
then restart the mysql server
$ service mysql restart || systemctl restart mysqld
note: this kind of errors formed by the permission issues. all the mysql service start commands using the log file for writing the status of mysql. If the permission has been changed, the service can't be write anything into the log files. If it happens it will stopped to run the service
remove any command of "secure_file_priv" in /etc/mysql/my.cnf and restart mysql.
If you want to use a file in mysql, copy those files to the main folder.
The main folder is obtained this way : SHOW VARIABLES LIKE "secure_file_priv";
You can purge all mysql-related packages and reinstall them with the following commands:
PACKAGES="mysql-server mysql-community-server mysql-community-server-core mysql-client mysql-client mysql-community-client mysql-community-client-core mysql-common mysql-community-client-plugins php-mysql"
apt purge $PACKAGES
echo "any remaining installed packages:"
dpkg -l|grep ii|grep mysql
apt install --reinstall mysql-common
apt install $PACKAGES
If there are any remaining packages (apart from mysql-core), add those to your list
Backup your config or data and reinstall mysql
sudo apt remove --purge mysql-server
sudo apt purge mysql-server
sudo apt autoremove
sudo apt autoclean
sudo apt remove dbconfig-mysql
sudo apt-get remove --purge mysql* -y
sudo apt-get autoremove -y
sudo apt-get autoclean
Then install it again.
That works here.
i have got the same "systemctl status mysql.service" and "journalctl -xe" for details. ERROR.
after repeated deinstallation and installation does not work at all.
but this one work well> https://linuxtut.com/en/5a5b0f46620ae1b27b10/
you just need to remove everything from my.cnf file except [mysqld] and start the server. this really work. but you might not have the password for root in that case skip-grant-tables and restart server in safe mode and use mysql and
update mysql.user set authentication_string=null where user='root' and then can alter user 'root'#'localhost' identified by 'your_$$new_99pwd#';
then login to secure mode and then you can create new user.
Also don't forget to check on your docker containers, for me it was my docker has mysql running on the background.
Connect to the server using SSH.
Stop the affected MySQL service and the service plesk-web-socket to prevent it from attempting to start MySQL:
service mysql stop || service mariadb stop && service plesk-web-socket stop
Back up all the MySQL data storage files. By default, they are located in the directory /var/lib/mysql/.
For example:
cp -a /var/lib/mysql /root/mysql_backup
Add the parameter innodb_force_recovery to the section [mysqld] of the MySQL configuration file. This option allows starting MySQL service in the recovery mode and try creating dumps of databases.
For example:
vi /etc/my.cnf
[mysqld]
innodb_force_recovery = 2
Start the MySQL service.
after having tested several solutions without success, the one that finally worked is the following:
you can load the default configuration of your apache server
sudo a2ensite 000-default.conf
sudo a2dissite my.conf
systemctl reload apache2
then reload the configuration for your website
sudo a2ensite my.conf
sudo a2dissite 000-default.conf
systemctl reload apache2
I had the same issue and after hours the solution was for me:
Open this file nano /etc/mysql/my.cnf
#I use mysql service if you use mysqld service, type mysqld instead of mysql
[mysql]
innodb_force_recovery = 1
Had the same problem. Solved as given below.
Use command :
sudo tail -f /var/log/messages|grep -i mysql
to check if SELinux policy is causing the issue. If so, first check if SELinux policy is enabled using command #sestatus. If it shows enabled, then disable it.
To disable:
# vi /etc/sysconfig/selinux
change 'SELINUX=enforcing' to 'SELINUX=disabled'
restart linux
check with sestatus and it should show "disabled"
Uninstall and reinstall mysql. It should be working.
I trying to set up master replication server. When I try to start/restart the server after added log-bin directory as following in my.cnf,
log-bin = /var/log/mysql/mysql-bin.log
the server is not starting up.
MySQL status
mysqld.service - MySQL Server
Loaded: loaded (/etc/systemd/system/mysqld.service; enabled)
Active: inactive (dead) since Mon, 13 Jul 2015 17:46:47 +0800; 1s ago
Process: 14145 ExecStart=/usr/bin/mysqld_safe --defaults-file=/etc/my.cnf --datadir=/var/lib/mysql --socket=/var/lib/mysql/mysql.sock (code=exited, status=0/SUCCESS)
CGroup: name=systemd:/system/mysqld.service
But after I changed the log-bin as following (without folder path)
log-bin = mysql-bin.log
the server is running successfully.
MySQL status
mysqld.service - MySQL Server
Loaded: loaded (/etc/systemd/system/mysqld.service; enabled)
Active: active (running) since Mon, 13 Jul 2015 17:47:43 +0800; 2s ago
Main PID: 15272 (mysqld_safe)
CGroup: name=systemd:/system/mysqld.service
├ 15272 /bin/sh /usr/bin/mysqld_safe --defaults-file=/etc/my.cnf --datadir=/var/lib/mysql --socket=/var/lib/mysql/mysq...
└ 15615 /usr/libexec/mysqld --defaults-file=/etc/my.cnf --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib/...
Update
From mysqld.log :
/var/log/mysql/mysql-bin.index' not found (Errcode: 2)
But my mysql-bin.index by default at
/var/lib/mysql/mysql-bin.index
Could anyone please help me out as I just start to learn master-slave replication? Do I need to create a folder name mysql and change the permission to mysql and put in log directory or how I can make sure it locates my mysql-bin.index file correctly?
Finally I have found the solution. Not sure whether I did it in a right way.
After searched about (Errcode: 2), found that it is indicate that the file or directory does not exist. So I have created the folder named as mysql and added in log directory (Logged in as root user). When I try to restart the server, it gives me another error:
/var/log/mysql/mysql-bin.index' not found (Errcode: 13)
Errcode: 13 indicates permission denied. So I have change the ownership from root to mysql :
chown -R mysql:mysql /var/log/mysql
I restart the server and it runs successfully.
If there is an error in path access related to data and logs of mysql it will call the default /var/lib/mysql and /var/log/mysql. To ovveride mysql log file path do the following.
create new path
make the path with ownership of mysql user
example - sudo shown -R mysql:mysql /mnt/mysql/logs
pass the path to apparmor to read this directory.
file location - /etc/apparmor.d/usr.sbin.mysqld
content
# Allow log file access
/mnt/mysql/logs/ r,
/mnt/mysql/logs/** rw,
Note: if apparmor has not correct path then it will give issue of permission that confuses with simple chown and chmod