8

I am following this digital ocean tutorial for Ubuntu 14.04 to install mysql on Ubuntu 16.04 for my Rails projects. I had, maybe wrongly, assumed that the procedure would be the same.

However, when I run the command sudo mysql_install_db, I receive the following error:

2016-06-15 18:40:36 [WARNING] mysql_install_db is deprecated. Please consider switching to mysqld --initialize
2016-06-15 18:40:36 [ERROR]   The data directory needs to be specified.

How can I complete the setup? I have successfully followed the same procedure several times in the past on Ubuntu 14.04.

  • 4
    What if you do what it suggests: mysqld --initialize? – Jos Jun 15 '16 at 13:56
  • 2
    @Jos It gives the following error: mysqld: Can't create directory '/var/lib/mysql/' (Errcode: 17 - File exists) 2016-06-15T14:00:28.483462Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details). 2016-06-15T14:00:28.484374Z 0 [ERROR] Aborting – Jawad Khawaja Jun 15 '16 at 14:01
  • 2
    You can probably get around that issue by deleting the directory /var/lib/mysql and rerunning the --initialize process. – Jos Jun 15 '16 at 14:16
  • 1
    Thank you for that! I was worried it might cause issues as it contained a number of files. But it worked. I have completed the installation now. – Jawad Khawaja Jun 15 '16 at 14:36
  • @Jos You should post your comment as answer. – Byte Commander Jun 15 '16 at 14:59
9

Installation of the MySQL server involves roughly three steps: 1) unpacking the software; 2) creating a default database; 3) creating a default user/password (and storing this in the database).

Should you accidentally lose the database files (usually located in /var/lib/mysql) then you can start again without completely reinstalling the server package. This is done with the command mysqld --initialize. If you run this command while a database is already in place, it will report an error ("File exists") and it won't attempt to overwrite the database. However, if you're unsure if the installation procedure has completed correctly, it's OK to delete the directory /var/lib/mysql and re-initialize the database.

The --initialize flag will cause MySQL to generate a root user and a random password, which is then written to the log file. For more information, see man mysqld.

| improve this answer | |
5

First check the version of Mysql using mysql --version.

If you have version 5.7.6 or later, the data directory would be initialized automatically and no need for running sudo mysql_install_db.

some more info on installing mysql on DigitalOcean server is on https://www.digitalocean.com/community/tutorials/how-to-install-mysql-on-ubuntu-14-04

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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