This question already has an answer here:

I have a problem with install mysql_install_db.

When I call mysql_install_db I get this error:

[WARNING] mysql_install_db is deprecated. Please consider switching to mysqld --initialize
2016-10-10 16:06:57 [ERROR]   The data directory needs to be specified.
root@furniture-ecommerce:~# mysqld --initialize
2016-10-10T16:13:24.343724Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2016-10-10T16:13:24.350429Z 0 [ERROR] --initialize specified but the data directory has files in it. Aborting.
2016-10-10T16:13:24.350786Z 0 [ERROR] Aborting

I deleted the directory /var/lib/mysql as here recommend - post but when I call mysqld --initialize then this error occurs:

mysqld: Can't create directory '/var/lib/mysql/' (Errcode: 13 -     Permission denied)
2016-10-10T16:23:29.515470Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2016-10-10T16:23:29.519420Z 0 [ERROR] Aborting

Can you help me with it?

marked as duplicate by David Foerster, Charles Green, Sumeet Deshmukh, user364819, Eric Carvalho Jun 30 '17 at 22:28

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • Did u try reinstalling mysql – minigeek Oct 11 '16 at 9:02
  • Yes and each time I have the same statement – Dominik Wiśniewski Oct 11 '16 at 11:53
  • How do you remove it ??.with autoremove or remove command?? – minigeek Oct 11 '16 at 13:19
  • Thanks for your answer but I uninstalled almost the same to you through: sudo apt-get purge mysql-server mysql-client mysql-common then sudo apt-get autoremove and sudo apt-get autoclean and I have the same statement.. – Dominik Wiśniewski Oct 11 '16 at 17:10
  • I still think mysql is not installed properly...and why do u remove those directories!!?..i have mysql installed and mysql _install_db is working fine..... May b u should try sudo apt-get purge mysql* and then run sudo apt-get install --reinstall mysql-server this time dont install anything else..and just setup mysql and login using mysql -u root -p if it let u loggin..it is installed properly...and now run what you wanted to run at beginning – minigeek Oct 11 '16 at 18:08
up vote 1 down vote accepted

I recommend you do the following.
Create the directory:

mkdir -p /var/lib/mysql

Note: If you want to change the default dir above for mysql data storage, then you need to add the new dir in the apparmor config as well in order to use.

Install MySQL server packages and others.

sudo apt-get install mysql-server mysql-client mysql-common

Apply ownership and permissions required.

chown -R mysql.mysql /var/lib/mysql
chmod -R 775 /var/lib/mysql

If you don't want apparmor to make unnecessary issues, better disable it as follows.

sudo service apparmor stop
sudo ln -s /etc/apparmor.d/usr.sbin.mysqld /etc/apparmor.d/disable/
sudo service apparmor restart
sudo aa-status

Now reboot the system.

sudo reboot

Now initialise MySQL as follows.

mysql_install_db

Check everything went fine. You can now use secure installation procedure.

sudo mysql_secure_installation

Thats all.

Open terminal and type :

sudo apt-get purge mysql-server

(Can also put mysql*)

sudo apt-get autoclean
sudo apt-get install mysql-server
  • After I removed mysql and I installed again, I call sudo mysql_install_db and I get this error: – Dominik Wiśniewski Oct 11 '16 at 17:18

I have deleted/moved the content of /var/lib/mysql/, but not the directory itself. I tried again to run

sudo mysqld --initialize

and it worked, and created new content within the /var/lib/mysql/ directory

Not the answer you're looking for? Browse other questions tagged or ask your own question.