I think you are aware, that you can create hooks on install process.
Here is my approach, where I after install publish plugin as an example
First check your session handler in configuration.php and try to set it to 'none'.
$session_handler = 'none';
That should work in most cases and you might get some information on the true causes of the failure.
In my case, the $session_handler was set to 'database' and I had an error in my database setup. If this applies to you as well, check your database ...
JDatabaseDriver::quoteName() is for quoting SQL identifiers. Use JDatabaseDriver:quote() to quote and escape strings.
$query->where($db->quoteName('element') . ' = ' . $db->quote('com_componentname'));