Kontact in Kubuntu 16.10 will not start because the Akonadi server will not start

I am using Kubuntu 16.10 and am unable to get Kontact to start because Akonadi will not start. Below is the output from akonadictl start.

It appears there is something seriously wrong with Akonadi. Does anyone have any ideas? Am I just sol? Can a downlevel version of Akonadi and Kontact be install?

trekker@trekker-HP-Notebook:/usr/bin$ akonadictl start
Starting Akonadi Server...
   done.
Connecting to deprecated signal QDBusConnectionInterface::serviceOwnerChanged(QString,QString,QString)
trekker@trekker-HP-Notebook:/usr/bin$ akonadiprivate_log: search paths:  ("/home/trekker/bin", "/home/trekker/.local/bin", "/usr/local/sbin", "/usr/local/bin", "/usr/sbin", "/usr/bin", "/sbin", "/bin", "/usr/games", "/usr/local/games", "/snap/bin", "/usr/sbin", "/usr/local/sbin", "/usr/local/libexec", "/usr/libexec", "/opt/mysql/libexec", "/opt/local/lib/mysql5/bin", "/opt/mysql/sbin")
Found mysql_install_db:  "/usr/bin/mysql_install_db"
Found mysqlcheck:  "/usr/bin/mysqlcheck"
Using mysqld: "/usr/sbin/mysqld-akonadi"
mysqld reports version 5.7.16 (Oracle MySQL)
Executing:  "/usr/sbin/mysqld-akonadi" "--defaults-file=/etc/xdg/akonadi/mysql-global.conf --initialize --datadir=/home/trekker/.local/share/akonadi/db_data/"
mysqld: [ERROR] Could not open required defaults file: /etc/xdg/akonadi/mysql-global.conf
mysqld: [ERROR] Fatal error in defaults handling. Program aborted!
Executing: "/usr/sbin/mysqld-akonadi" "--defaults-file=/home/trekker/.local/share/akonadi/mysql.conf --datadir=/home/trekker/.local/share/akonadi/db_data/ --socket=/tmp/akonadi-trekker.LbKUAD/mysql.socket"
Database process exited unexpectedly during initial connection!
executable: "/usr/sbin/mysqld-akonadi"
arguments: ("--defaults-file=/home/trekker/.local/share/akonadi/mysql.conf", "--datadir=/home/trekker/.local/share/akonadi/db_data/", "--socket=/tmp/akonadi-trekker.LbKUAD/mysql.socket")
stdout: ""
stderr: "mysqld: Error on realpath() on '/var/lib/mysql-files' (Error 2 - No such file or directory)\n2016-11-18T19:16:26.102182Z 0 [Warning] The syntax '--log_warnings/-W' is deprecated and will be removed in a future release. Please use '--log_error_verbosity' instead.\n2016-11-18T19:16:26.102229Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).\n2016-11-18T19:16:26.102276Z 0 [ERROR] Failed to access directory for --secure-file-priv. Please make sure that directory exists and is accessible by MySQL Server. Supplied value : /var/lib/mysql-files\n2016-11-18T19:16:26.102279Z 0 [ERROR] Aborting\n\n2016-11-18T19:16:26.102290Z 0 [Note] Binlog end\n"
exit code: 1
process error: "Unknown error"
terminating service threads
terminating connection threads
stopping db process
Failed to remove Unix socket
Failed to remove runtime connection config file
Application 'akonadiserver' exited normally...

trekker@trekker-HP-Notebook:/usr/bin$ 

It seems I have found a fix. Based on a thread I found in Kubuntu Forums, I did the following:

sudo mkdir /var/lib/mysql-files


Solution 1:

Solved it removing the local configuration directory rm ~/.local/share/akonadi and restarting it with akonadictl start

Solution 2:

for me this didn't help (lubuntu 17.04) but I found this bug

so this solved my issue :

sudo apt-get install apparmor-utils
sudo aa-complain usr.sbin.mysqld-akonadi

Solution 3:

I solved the issue with these steps:

Created the folder:

sudo mkdir /var/lib/mysql-files

Started the service:

akonadictl start

Purged and reinstalled Kontact:

sudo apt purge kontact && sudo apt install Kontact

Start Kmail

Hope this helps.

Regards.