How to list posts by terms

$terms = get_terms('CUSTOM_TAXONOMY', ['hide_empty' => true]);
foreach( $terms as $term ){
    echo '<section>';
    echo '<h1>' . $term->name . '</h1>';

    $posts = get_posts([
        'post_type' => 'CUSTOM_POST_TYPE'
        'tax_query' => [
            [
                'taxonomy'  => 'CUSTOM_TAXONOMY',
                'field'     => 'term_id',
                'terms'     => $term->term_id
            ]
        ]   
    ]);

    echo '<ul>';
    foreach($posts as $post){
            echo sprintf('<li><a href="%s">%s</a></li>', get_permalink($post), $post->post_title);
    }
    echo '</ul>';
    echo '</section>';
}

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)