Is there a full explanation on how to share a database with two WordPress sites on same server?

It is possible to add custom queries to the 2nd site, and pull posts from the first site:

<?php
$mydb = new wpdb('root','root','dev1','localhost');
$query_result = $mydb->get_results("SELECT * FROM $wpdb->posts WHERE post_status="publish"");
if ($query_result) {
    foreach ($query_result as $result) {
        setup_postdata($result);
        get_template_part( 'content', get_post_format() );
    }
} else {
    echo "<p>Not found</p>" ;
}
?>

See wpdb and setup_postdata.