I checked this page:
http://dev.mysql.com/doc/refman/5.7/en/mysql-install-db.html
mysql_install_db
is removed, however, when I use mysqld --initialize
. It promotes these errors and warning.
[Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
[ERROR] --initialize specified but the data directory has files in it. Aborting.
[ERROR] Aborting
The first one can be ignored according to this:How to enable explicit_defaults_for_timestamp?
I don’t know how to solve the second problem.
asked Jun 5, 2016 at 16:21
Pls, read error carefully:
[ERROR] —initialize specified but the data directory has files in it. Aborting.
Your directory is not empty. You have to remove all the contents of it or choose another one.
answered Jun 5, 2016 at 21:08
Eugene LisitskyEugene Lisitsky
11.8k5 gold badges37 silver badges58 bronze badges
13
I had this issue with Kubernetes and MySQL 5.7 as well.
Adding the suggestion from yosifki to my container’s definition got things working.
A new ext4 disk partition is not usually empty;
there is a lost+found directory, which mysql is known to choke on. You
could try adding —ignore-db-dir=lost+found to the CMD to know for
sure (from mysql docs)
Here’s an extract of my working YAML definition:
name: mysql-master
image: mysql:5.7
args:
- "--ignore-db-dir=lost+found"
And here, a docker-compose snippet for better clarify:
version: '3'
services:
mysql-master:
image: mysql:5.7
command: [--ignore-db-dir=lost+found]
environment:
- MYSQL_ROOT_PASSWORD=root
answered Feb 20, 2021 at 23:30
Thiago G. AlvesThiago G. Alves
1,0491 gold badge12 silver badges23 bronze badges
2
I faced the sample problem. i renamed the container directory from
/var/lib/mysql
to
/var/lib/minesql or some different name
. Now the container is started.
Previous Command:
docker container run --name=mysql -d -e MYSQL_ROOT_PASSWORD=abc1234 -e MYSQL_DATABASE=sample -e MYSQL_USER=ashik -e MYSQL_PASSWORD=abc123 -v mysql_volume:/var/lib/mysql mysql
Working Command:
docker container run --name=mysql -d -e MYSQL_ROOT_PASSWORD=abc1234 -e MYSQL_DATABASE=sample -e MYSQL_USER=ashik -e MYSQL_PASSWORD=abc123 -v mysql_volume:/var/lib/minesql mysql
answered May 24, 2019 at 12:37
Ashik AhmedAshik Ahmed
1441 silver badge10 bronze badges
Its usually means your data directory is not empty. If you remove or rename the data directory and the problem still exist, check your config file /etc/my.cnf
and delete validate_password_policy
variable in the initialize step. after starting the server you can set this variable to any things you want.
answered Jun 2, 2017 at 20:31
3
just remove /data directory. this is worked for me :
as simple like this :
image: mysql:5.7
volumes:
- ./db:/var/lib/mysql
and make sure your «./db» directory is empty.
answered Feb 22, 2020 at 16:40
nur zazinnur zazin
91010 silver badges13 bronze badges
In my case the solution was to edit volume directory in my docker-compose.yml
from:
image: mysql:5.6
volumes:
- ./db:/var/lib/mysql/data
To
image: mysql:5.6
volumes:
- ./db_data:/var/lib/mysql/data
And run again
sudo docker-compose build
sudo docker-compose up
And then you may need to run migrate sudo docker-compose run web rake db:create
for my Rails app.
answered Oct 28, 2019 at 17:47
1
I had similar issue, but no mysql
folder inside the /usr/local
.
In my case mysql
was located inside the /usr/local/var
so rm -rf /usr/local/var/mysql
fixed the problem
answered May 24, 2021 at 12:41
spirito_liberospirito_libero
1,1161 gold badge12 silver badges19 bronze badges
Proceed as suggested in the @Eugene Lisitsky’s answer,= erasing the /var/lib/mysql directory, the mysql directory contents. But do not keep the option innodb_force_recovery
present in the /etc/my.cnf configuration file (or some such other alternative configuration I suppose, which would prevent initialization/installation due to own files).
answered Aug 16, 2021 at 14:09
FantomX1FantomX1
1,4672 gold badges15 silver badges21 bronze badges
Disable SElinux.
Setenforce 0
Also create log directory in /var/logs/ mysql folder
It have to mysql user owner
cd /var/log/
mkdir mysql
chown -R mysql:mysql mysql/
then change log direcotry in /etc/my.cnf
answered Mar 29, 2020 at 15:15
Turan ZamanlıTuran Zamanlı
3,7581 gold badge15 silver badges21 bronze badges
I need to save my database from a docker mysql container so other team members can also work on it. Until now we were using this, which worked just fine:
volumes:
- ./db/:/var/lib/mysql/
However the /db folder was really messy, because the /mysql folder contains all the mysql files, not just the database. So I tried to save only the database folder:
volumes:
- ./db/:/var/lib/mysql/database/
But unfortunately i keep getting this error:
[ERROR] --initialize specified but the data directory has files in it. Aborting.
[ERROR] Aborting
However despite what the error says, the /db folder is empty (no hidden files either), so I have no idea what the error actually is.
I have also tried other subdirectories inside /mysql and got the same result. When I revert the changes back to
- ./db/:/var/lib/mysql/
the error goes away.
Full docker-compose.yml:
mysql:
image: mysql:${MYSQL_VERSION:-latest}
restart: always
ports:
- "3306:3306"
volumes:
- ./db/:/var/lib/mysql/${DB_NAME}
networks:
- backend
environment:
MYSQL_ROOT_PASSWORD: "${DB_ROOT_PASSWORD}"
MYSQL_DATABASE: "${DB_NAME}"
MYSQL_USER: "${DB_USERNAME}"
MYSQL_PASSWORD: "${DB_PASSWORD}"
container_name: ${PROJECT_PREFIX}_mysql
Home
>
MySQL
>
Detail page
My environment: redhat6.5
Database version: mysql5.7
Problem: after MySQL is installed, fail to initialize
Installation: RPM package
Cause of the problem:
When MySQL is initialized, it detects of data directory exists,
If it does not exist, MySQL will create it,
If there is, and there is data in this directory, MySQL will report error and terminate initialization:
[root@server1 ~]# /etc/init.d/mysqld start
Initializing MySQL database: 2017-06-26T02:33:40.212541Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2017-06-26T02:33:40.215791Z 0 [ERROR] --initialize specified but the data directory has files in it. Aborting.
2017-06-26T02:33:40.215877Z 0 [ERROR] Aborting
Solution:
Delete or rename this data directory. If the data is important data, it is recommended to rename and later re-import it.
I used the RPM package installation, and the default data directory is in
/var/lib/mysql/
I delete it directly
rm -fr /var/lib/mysql
then restart successfully:
[root@server1 lib] Stopping mysqld: [ OK ] Initializing MySQL database: [ OK ] Installing validate password plugin: [ OK ] Starting mysqld: [ OK ]
Posted by iamtop1982
in MySQL
at Jun 26, 2017 — 1:04 AM
[error] – initialize specified but the data directory has files in it. About.:
Problem Description:
MySQL is installed in Linux. Because it has been installed and uninstalled before, the uninstallation is not clean. When installing again, the following error occurs when initializing the password
2021-11-23T02:08:16.247240Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2021-11-23T02:08:16.248753Z 0 [ERROR] --initialize specified but the data directory has files in it. Aborting.
2021-11-23T02:08:16.248780Z 0 [ERROR] Aborting
Cause analysis:
reason: the old version of MySQL software does not delete the original data file, that is, the content under the path/var/lib/MySQL/
Solution: delete all contents under the path, including files and folders.
[[email protected] mysql]# rm -rf /var/lib/mysql/
After successful execution, initialize the password:
[[email protected] opt]# mysqld --initialize --user=mysql
[[email protected] opt]# cat /var/log/mysqld.log
2021-11-23T02:17:47.821574Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2021-11-23T02:17:47.988844Z 0 [Warning] InnoDB: New log files created, LSN=45790
2021-11-23T02:17:48.010498Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2021-11-23T02:17:48.066559Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 8d49959d-4c03-11ec-be82-000c29bdc989.
2021-11-23T02:17:48.067296Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2021-11-23T02:17:48.067886Z 1 [Note] A temporary password is generated for [email protected]: UBX6u)ekR:kB
Because there is no data saved in my data, direct deletion will not affect subsequent tasks, but!!! If you have data, you must back it up first~
Read More:
I’ve just installed a fresh version of MySQL on my CentOS machine. The problem I’m facing is that when I run this command:
# service mysqld start
I get in the console this error message:
[ERROR] Can’t change data directory owner to mysql
I’m not exactly sure what it means and how to fix it. Any comments and solutions are welcome. Thanks!
EDIT
It seems like I’ve fixed it with:
chown -R mysql /var/lib/mysql
But the very same command # service mysqld start
now leads to another error message:
[ERROR] —initialize specified but the data directory has files in it. Aborting
Indeed, it has files, because during installation CentOS itself created this folder /var/lib/mysql
and put some files in it. I did not do anything manually. So, what the heck is going on with CentOS and how to fix it?? Thanks!!
EDIT
It seems like either MySQL or CentOS has gone crazy. The catch is, if I delete all files from data directory, on start-up (when I run #service mysqld start
) it creates a bunch of files in it, like ca-key.pem
and other .pem
files. So, it creates files and then throws an error, that the data directory is not empty. What a stupid behaviour! But how can I solve all this???
I have just installed MySQL 5.7 on a fresh CentOS 6.7(vm).
When I start the MySQL service with this command:
sudo service mysqld start
It doesn’t start and raise this error:
Initializing MySQL database: 2015-12-07T11:00:51.060114Z 0 [Warning]
TIMESTAMP with implicit DEFAULT value is deprecated. Please use
—explicit_defaults_for_timestamp server option (see documentation for more details). 2015-12-07T11:00:51.062305Z 0 [ERROR]
—initialize specified but the data directory has files in it.
Aborting. 2015-12-07T11:00:51.062347Z 0 [ERROR] Aborting [FAILED]
Do you know what is the problem?
asked Dec 7, 2015 at 11:03
0
I faced the same issue myself and I successfully resolved it.
What needs to be done is:
Open the my.conf
file in vi editor and add a line under [mysqld]
:
explicit_defaults_for_timestamp = 1
This will fix the first issue.
Now check the access rights of the location pointed by datadir
field and make sure mysql can access it.
Worst case rename the location it points to. eg:
datadir=/var/lib/mysql1
Marco
3,6804 gold badges21 silver badges30 bronze badges
answered Jan 4, 2017 at 8:23
Yes, (I suppose it’s bug of MySql) right now I have solved the same issue. In my case I have created separated partition (mount point) for MySQL database. There was created the directory «lost+found». You should temporary move it or other files or folders to any other place and clean /var/lib/mysql . After this just run again «sudo service mysqld start» then you will see something like this:
Initializing MySQL database: [ OK ]
Installing validate password plugin: [ OK ]
Starting mysqld: [ OK ]
Good luck.
answered Dec 23, 2016 at 12:40
You can follow the below steps
mysqld --initialize-insecure --user=username --datadir=datadir_path
you can also opt to --initialize-secure
, but it would ask for root password as it was in previous versions with secure_installation
.
Make sure the datadir
is an empty created folder or else it will throw errors and then you can use following to start mysql
:
./bin/mysqld_safe --defaults-file=path to cnf file
or
serivce mysqld start
Please check for error log file and share if you face any errors following above steps and do set root password once it is started.
Paul White♦
77.2k28 gold badges387 silver badges607 bronze badges
answered Dec 8, 2015 at 8:29
Nawaz SohailNawaz Sohail
1,4003 gold badges9 silver badges25 bronze badges
I had a similar issue with Kubernetes and MySQL 5.7 as well.
Adding the suggestion from yosifki to my container’s definition got things working.
A new ext4 disk partition is not usually empty;
there is a lost+found directory, which mysql is known to choke on. You
could try adding —ignore-db-dir=lost+found to the CMD to know for
sure (from mysql docs)
Here’s an extract of my working YAML definition:
name: mysql-master
image: mysql:5.7
args:
- "--ignore-db-dir=lost+found"
Here’s an example snippet in docker-compose to clarify:
version: '3'
services:
mysql-master:
image: mysql:5.7
command: [--ignore-db-dir=lost+found]
environment:
- MYSQL_ROOT_PASSWORD=root
answered Feb 20, 2021 at 23:35