Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

adnan_morshed_'s avatar

SQLSTATE[HY000] [1044] Access denied for user 'sail'@'%' to database ':memory:

Recently I started using laravel sail. And the problem started to appear in phpunit test. I did migrate the database I connected my database with tableplus but when I wanted to test I changed the phpunit.xml to this:

<env name="APP_ENV" value="testing"/>
        <env name="BCRYPT_ROUNDS" value="4"/>
        <env name="CACHE_DRIVER" value="array"/>
        <env name="MAIL_MAILER" value="array"/>
        <env name="QUEUE_CONNECTION" value="sync"/>
        <env name="SESSION_DRIVER" value="array"/>
        <env name="DB_CONNECTON" value="sqlite"/>
        <env name="DB_DATABASE" value=":memory:"/>

every thing is still working but I can not run any test. and shows the error

SQLSTATE[HY000] [1044] Access denied for user 'sail'@'%' to database ':memory:' (SQL: select count(*) as aggregate from `projects` where (`title` = Voluptatem sed fugiat vel modi facere occaecati. and `description` = Eum voluptatem laudantium aut quis est voluptatem dolorem. At exercitationem molestiae et ut porro nam. Quo nisi dolore ut.))

Does anyone know how to solve it? need help.

0 likes
12 replies
okusax's avatar

hi, @adnan_morshed_ how is configured your table plus client? I think you are misconfiguring some of the PHPUnit parameters, double-check the user, password, and database name are the same as table plus.

rotaercz's avatar

@MohamedTammam Is there a place where can I see a list of all the arguments (like -v) that sail takes? I tried Googling but nothing is coming up for some reason.

MohamedTammam's avatar

@rotaercz That discussion was 3 months ago and your question doesn't relate to it. Please create a new discussion with your question detail, so we don't spam the OP.

prexma's avatar

@MohamedTammam Thanks for the tip! Using sail down -v followed by sail up solved my problem. The -v flag removes the Docker volumes along with the containers.

marensas's avatar

Try this (laravel 9):

<env name="DB_CONNECTION" value="sqlite"/>
<env name="DB_DATABASE" value=":memory:"/>

And sail config:clear

5 likes
diegochecarelli2019's avatar

Hey there. I've changed the database username in .env file and worked for me. So, in the env file change this line: DB_USERNAME=sail to this: DB_USERNAME=root and restart the container and run migrate command again. Good luck

2 likes
flssol's avatar

There is no need to change the .env just for the purposes of adjusting the env value in testing: you can use phpunit.xml for that:

<phpunit>
    ...
    <php>
        ...
        <env name="DB_USERNAME" value="root"/>
    <php>
</phpunit>

Also, and this is not obvious - if you change the DB username using phpunit.xml, testing in parallel may fail if your cached your config.

Please or to participate in this conversation.