Database Error Code: Access denied for user 'civi'@'localhost' (using password: YES), 1045
MySQL 5.7 has "pluggable authentication", which means that you're not always logging in by password from your terminal.  You'll want to ensure that the mysql.user table shows a value of mysql_native_password for all users in the plugin column.

If you're logging in to the terminal as the root user on Ubuntu 16.04, then by default you're not using mysql_native_password, you're using auth_socket.  This could lead to misleading results where you can log in from the command line with what SEEMS like a good password!  If this is your problem, you may need to install the mysql_native_password plugin before you can set the password.