I was following this tutorial:
So far, I installed mysql-server mysql-client libmysqlclient-dev, and I was suppose to tell MySQL to create its database directory structure where it will store its information using sudo mysql_install_db
.
$ sudo mysql_install_db
[WARNING] mysql_install_db is deprecated. Please consider switching to mysqld --initialize
[ERROR] The data directory needs to be specified.
I thought running mysqld --initialize
would solve the issue:
$ mysqld --initialize
mysqld: Can't create directory '/var/lib/mysql/' (Errcode: 17 - File exists)
[Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
[ERROR] Aborting
How do I tell MySQL to create its database directory structure where it will store its information?
Best Answer
I managed to solve the problem using a previously answered question, How to install mysql on Ubuntu 16.04, but I needed to modify the solution to work for me.
When I deleted/moved
/var/lib/mysql
directory,mysqld --initialize
couldn't create the database directory I want in replacement for/var/lib/mysql
, and it gave meErrcode: 13 - Permission denied
even though I preceded it withsudo
.I deleted/moved the content of
/var/lib/mysql/
, but not the directory itself. I tried again to runsudo mysql --initialize
, and it worked, and created new content within the/var/lib/mysql/
directory. The content produced bymysql --initialize
is different than the previous content I deleted/moved.I continued the rest of the steps in the tutorial, and worked perfectly.
P.S. I needed to use
sudo -i
to access/var/lib/mysql
.