I had this error:
root@ubuntu-2gb-nbg1-1 ~ # mysqld --initialize
2019-01-23T15:11:22.428139Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2019-01-23T15:11:22.435428Z 0 [ERROR] --initialize specified but the data directory has files in it. Aborting.
2019-01-23T15:11:22.435653Z 0 [ERROR] Aborting
Solution (this will delete all your databases and tables, make a backup!):
/etc/init.d/mysql stop
rm /var/lib/mysql -rf
mkdir /var/lib/mysql
chown mysql:mysql /var/lib/mysql
mysqld --initialize
Now add skip-grant-tables
in your /etc/mysql/mysql.conf.d/mysqld.cnf
, because the root password is not valid, so we need to login somehow and set a new one.
/etc/init.d/mysql start
mysql
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
4 rows in set (0.00 sec)
mysql> use mysql;
Database changed
mysql> show tables;
+---------------------------+
| Tables_in_mysql |
+---------------------------+
| columns_priv |
| db |
| engine_cost |
| event |
| func |
| general_log |
| gtid_executed |
| help_category |
| help_keyword |
| help_relation |
| help_topic |
| innodb_index_stats |
| innodb_table_stats |
| ndb_binlog_index |
| plugin |
| proc |
| procs_priv |
| proxies_priv |
| server_cost |
| servers |
| slave_master_info |
| slave_relay_log_info |
| slave_worker_info |
| slow_log |
| tables_priv |
| time_zone |
| time_zone_leap_second |
| time_zone_name |
| time_zone_transition |
| time_zone_transition_type |
| user |
+---------------------------+
31 rows in set (0.00 sec)
So now you have a new mysql database with user table, but the password is "messed up". So you need to set a valid password:
SET PASSWORD FOR 'root'@'localhost' = PASSWORD('somepass');
FLUSH PRIVILEGES;
ctrl+d
Now remove the skip-grant-tables
from your config, otherwise your setup is insecure.
Now you can login "normally": mysql -u root -p
(enter somepass
)
mysqld
returns an error. Reinstalling viayum reinstall mysql mysql-server
succeeds but does not restore the db. – Odelsting