Database migration failure #1528

Closed
opened 2026-02-05 01:09:15 +03:00 by OVERLORD · 8 comments
Owner

Originally created by @killadelphia on GitHub (Feb 10, 2020).

Describe the bug
php artisan migrate command fails after restoring mysql dump from Bookstack 0.27.5 to Bookstack 0.28 installation

Illuminate\Database\QueryException : SQLSTATE[HY000] [1045] Access denied for user 'bookstack'@'localhost' (using password: YES) (SQL: select * from information_schema.tables where table_schema = bookstack and table_name = migrations and table_type = 'BASE TABLE')

Steps To Reproduce
Steps to reproduce the behavior:
Run Ubuntu 18.04 installation script on Ubuntu 18.04.3 LTS
Restore SQL database using "mysql -u user -p bookstack < bookstack.backup.sql"
Run "php artisan migrate"

Illuminate\Database\QueryException : SQLSTATE[HY000] [1045] Access denied for user 'bookstack'@'localhost' (using password: YES) (SQL: select * from information_schema.tables where table_schema = bookstack and table_name = migrations and table_type = 'BASE TABLE')

Expected behavior
Successful update to Bookstack 0.28

Your Configuration (please complete the following information):

  • Exact BookStack Version: 0.28.0
  • PHP Version: 7.2.24
  • Hosting Method: Apache
Originally created by @killadelphia on GitHub (Feb 10, 2020). **Describe the bug** php artisan migrate command fails after restoring mysql dump from Bookstack 0.27.5 to Bookstack 0.28 installation > Illuminate\Database\QueryException : SQLSTATE[HY000] [1045] Access denied for user 'bookstack'@'localhost' (using password: YES) (SQL: select * from information_schema.tables where table_schema = bookstack and table_name = migrations and table_type = 'BASE TABLE') **Steps To Reproduce** Steps to reproduce the behavior: Run Ubuntu 18.04 installation script on Ubuntu 18.04.3 LTS Restore SQL database using "mysql -u user -p bookstack < bookstack.backup.sql" Run "php artisan migrate" > Illuminate\Database\QueryException : SQLSTATE[HY000] [1045] Access denied for user 'bookstack'@'localhost' (using password: YES) (SQL: select * from information_schema.tables where table_schema = bookstack and table_name = migrations and table_type = 'BASE TABLE') **Expected behavior** Successful update to Bookstack 0.28 **Your Configuration (please complete the following information):** - Exact BookStack Version: 0.28.0 - PHP Version: 7.2.24 - Hosting Method: Apache
OVERLORD added the 🐕 Support label 2026-02-05 01:09:15 +03:00
Author
Owner

@ssddanbrown commented on GitHub (Feb 10, 2020):

Hi @killadelphia,
Are you able to connect to mysql manually using the same credentials as are defined in your BookStack .env file? If so, are you able to manually run the command:

select * from information_schema.tables where table_schema = 'bookstack' and table_name = 'migrations' and table_type = 'BASE TABLE';
@ssddanbrown commented on GitHub (Feb 10, 2020): Hi @killadelphia, Are you able to connect to mysql manually using the same credentials as are defined in your BookStack `.env` file? If so, are you able to manually run the command: ```sql select * from information_schema.tables where table_schema = 'bookstack' and table_name = 'migrations' and table_type = 'BASE TABLE'; ```
Author
Owner

@killadelphia commented on GitHub (Feb 11, 2020):

Hey Dan,
First of all thanks for your response. I was able to get my Bookstack install working again by matching the password for the 'bookstack' user to the password in my .env file.

I was able to run the SQL command you listed, here is what it returned.

mysql> select * from information_schema.tables where table_schema = 'bookstack' and table_name = 'migrations' and table_type = 'BASE TABLE';
+---------------+--------------+------------+------------+--------+---------+------------+------------+----------------+-------------+-----------------+--------------+-----------+----------------+---------------------+---------------------+------------+--------------------+----------+----------------+---------------+ | TABLE_CATALOG | TABLE_SCHEMA | TABLE_NAME | TABLE_TYPE | ENGINE | VERSION | ROW_FORMAT | TABLE_ROWS | AVG_ROW_LENGTH | DATA_LENGTH | MAX_DATA_LENGTH | INDEX_LENGTH | DATA_FREE | AUTO_INCREMENT | CREATE_TIME | UPDATE_TIME | CHECK_TIME | TABLE_COLLATION | CHECKSUM | CREATE_OPTIONS | TABLE_COMMENT | +---------------+--------------+------------+------------+--------+---------+------------+------------+----------------+-------------+-----------------+--------------+-----------+----------------+---------------------+---------------------+------------+--------------------+----------+----------------+---------------+ | def | bookstack | migrations | BASE TABLE | InnoDB | 10 | Dynamic | 43 | 381 | 16384 | 0 | 0 | 0 | 44 | 2020-02-10 19:09:17 | 2020-02-10 19:09:18 | NULL | utf8mb4_unicode_ci | NULL | | | +---------------+--------------+------------+------------+--------+---------+------------+------------+----------------+-------------+-----------------+--------------+-----------+----------------+---------------------+---------------------+------------+--------------------+----------+----------------+---------------+ 1 row in set (0.00 sec)

When running php artisan migrate now I get this error:

Migrating: 2019_12_29_120917_add_api_auth

Illuminate\Database\QueryException : SQLSTATE[42S01]: Base table or view already exists: 1050 Table 'api_tokens' already exists (SQL: create table api_tokens (id int unsigned not null auto_increment primary key, name varchar(191) not null, token_id varchar(191) not null, secret varchar(191) not null, user_id int unsigned not null, expires_at date not null, created_at timestamp null, updated_at timestamp null) default character set utf8mb4 collate 'utf8mb4_unicode_ci')

The bookstack install does seem to be working fine so far though.

@killadelphia commented on GitHub (Feb 11, 2020): Hey Dan, First of all thanks for your response. I was able to get my Bookstack install working again by matching the password for the 'bookstack' user to the password in my .env file. I was able to run the SQL command you listed, here is what it returned. > mysql> select * from information_schema.tables where table_schema = 'bookstack' and table_name = 'migrations' and table_type = 'BASE TABLE'; +---------------+--------------+------------+------------+--------+---------+------------+------------+----------------+-------------+-----------------+--------------+-----------+----------------+---------------------+---------------------+------------+--------------------+----------+----------------+---------------+ | TABLE_CATALOG | TABLE_SCHEMA | TABLE_NAME | TABLE_TYPE | ENGINE | VERSION | ROW_FORMAT | TABLE_ROWS | AVG_ROW_LENGTH | DATA_LENGTH | MAX_DATA_LENGTH | INDEX_LENGTH | DATA_FREE | AUTO_INCREMENT | CREATE_TIME | UPDATE_TIME | CHECK_TIME | TABLE_COLLATION | CHECKSUM | CREATE_OPTIONS | TABLE_COMMENT | +---------------+--------------+------------+------------+--------+---------+------------+------------+----------------+-------------+-----------------+--------------+-----------+----------------+---------------------+---------------------+------------+--------------------+----------+----------------+---------------+ | def | bookstack | migrations | BASE TABLE | InnoDB | 10 | Dynamic | 43 | 381 | 16384 | 0 | 0 | 0 | 44 | 2020-02-10 19:09:17 | 2020-02-10 19:09:18 | NULL | utf8mb4_unicode_ci | NULL | | | +---------------+--------------+------------+------------+--------+---------+------------+------------+----------------+-------------+-----------------+--------------+-----------+----------------+---------------------+---------------------+------------+--------------------+----------+----------------+---------------+ 1 row in set (0.00 sec) When running php artisan migrate now I get this error: > Migrating: 2019_12_29_120917_add_api_auth >Illuminate\Database\QueryException : SQLSTATE[42S01]: Base table or view already exists: 1050 Table 'api_tokens' already exists (SQL: create table `api_tokens` (`id` int unsigned not null auto_increment primary key, `name` varchar(191) not null, `token_id` varchar(191) not null, `secret` varchar(191) not null, `user_id` int unsigned not null, `expires_at` date not null, `created_at` timestamp null, `updated_at` timestamp null) default character set utf8mb4 collate 'utf8mb4_unicode_ci') The bookstack install does seem to be working fine so far though.
Author
Owner

@slimninja commented on GitHub (Feb 14, 2020):

If anyone else has a similar issue, this is what solved it for me:

Similarly, was getting the following error
Illuminate\Database\QueryException : SQLSTATE[28000] [1045] Access denied for user 'sn_bookstack'@'localhost' (using password: YES) (SQL: select * from information_schema.tables where table_schema = sn_bookstack and table_name = migrations and table_type = 'BASE TABLE')

I was able to run the query manually using the same user. After playing with my .env settings for a while, I searched where else the sn_bookstack credentials were used.

I found that in bootstrap/cache/config.php, the password was truncated (password below is modified)

    'host' => 'localhost',
    'database' => 'sn_bookstack',
    'username' => 'sn_bookstack',
    'password' => '^13&e!',

Only thing I can think of is that special characters in my password caused something funky during the update. I updated the password in my .env file and config.php file to something else, and now everything is working as expected.

@ssddanbrown - My only question - I have an auto-update script that uses the following order.. Is this incorrect?

composer install
php artisan down
php artisan migrate
php artisan cache:clear
php artisan view:clear
php artisan up
@slimninja commented on GitHub (Feb 14, 2020): If anyone else has a similar issue, this is what solved it for me: Similarly, was getting the following error `Illuminate\Database\QueryException : SQLSTATE[28000] [1045] Access denied for user 'sn_bookstack'@'localhost' (using password: YES) (SQL: select * from information_schema.tables where table_schema = sn_bookstack and table_name = migrations and table_type = 'BASE TABLE')` I was able to run the query manually using the same user. After playing with my .env settings for a while, I searched where else the sn_bookstack credentials were used. I found that in bootstrap/cache/config.php, the password was truncated (password below is modified) 'host' => 'localhost', 'database' => 'sn_bookstack', 'username' => 'sn_bookstack', 'password' => '^13&e!', Only thing I can think of is that special characters in my password caused something funky during the update. I updated the password in my .env file and config.php file to something else, and now everything is working as expected. @ssddanbrown - My only question - I have an auto-update script that uses the following order.. Is this incorrect? ``` composer install php artisan down php artisan migrate php artisan cache:clear php artisan view:clear php artisan up ```
Author
Owner

@ssddanbrown commented on GitHub (Feb 15, 2020):

@salimnanji I'd probably swap the first two around, Since composer install processes could cause side affects if accessed during that time so better to take app down first.


@killadelphia That error now indicates something went wrong at some point during a migration. You'll be stuck where you are so it is something that should ideally be addressed otherwise you'll have problems with API token permissions or problems updating next time.

You could try deleting the api_tokens table in the database then re-migrating.

@ssddanbrown commented on GitHub (Feb 15, 2020): @salimnanji I'd probably swap the first two around, Since composer install processes could cause side affects if accessed during that time so better to take app down first. --- @killadelphia That error now indicates something went wrong at some point during a migration. You'll be stuck where you are so it is something that should ideally be addressed otherwise you'll have problems with API token permissions or problems updating next time. You could try deleting the `api_tokens` table in the database then re-migrating.
Author
Owner

@lithium-ap commented on GitHub (Feb 22, 2020):

Hi, I wanted to provide some feedback. @slimjim91's change fixed my php artisan migrate command as well. Specifically it was a # character in the password that was causing the issue. I updated the MySQL user password and php artisan migrate worked immediately.

Additionally, I had an older version of composer that created an update issue. I ran apt remove composer && apt autoremove && apt install composer, but composer did not update to the current version. Ultimately I performed the following and was able to complete the update from v27 to v28.2

sudo apt autoremove	
sudo curl -s https://getcomposer.org/installer | php
sudo mv composer.phar /usr/bin/composer
@lithium-ap commented on GitHub (Feb 22, 2020): Hi, I wanted to provide some feedback. @slimjim91's change fixed my ```php artisan migrate``` command as well. Specifically it was a # character in the password that was causing the issue. I updated the MySQL user password and php artisan migrate worked immediately. Additionally, I had an older version of composer that created an update issue. I ran ```apt remove composer && apt autoremove && apt install composer```, but composer did not update to the current version. Ultimately I performed the following and was able to complete the update from v27 to v28.2 ```sudo apt-get remove composer sudo apt autoremove sudo curl -s https://getcomposer.org/installer | php sudo mv composer.phar /usr/bin/composer
Author
Owner

@ssddanbrown commented on GitHub (Mar 12, 2020):

Thanks for the extra insight @lithium-ap.


Since the original issue poster has not responded to move this on I'll close this off. If this issue remains please open a new issue, referencing this one.

@ssddanbrown commented on GitHub (Mar 12, 2020): Thanks for the extra insight @lithium-ap. --- Since the original issue poster has not responded to move this on I'll close this off. If this issue remains please open a new issue, referencing this one.
Author
Owner

@tikotal commented on GitHub (Feb 25, 2021):

I had similar issue.
The only way I had this working is by forcing the migration, the original command in the installer is
$ php artisan migrate --no-interaction --force
and not just
$ php artisan migrate

I also had to use mysql and change the password for the user "bookstack", I did that after restoring the database using the root user (sudo mysql -u root) and made sure that the password I set is the same one as I set in the .env file.

Changing Password: https://www.mysqltutorial.org/mysql-changing-password.aspx

Don't forget to restart Apache:
$ sudo systemctl restart apache2

@tikotal commented on GitHub (Feb 25, 2021): I had similar issue. The only way I had this working is by forcing the migration, the original command in the installer is `$ php artisan migrate --no-interaction --force` and not just `$ php artisan migrate` I also had to use mysql and change the password for the user "bookstack", I did that after restoring the database using the root user (sudo mysql -u root) and made sure that the password I set is the same one as I set in the .env file. > Changing Password: https://www.mysqltutorial.org/mysql-changing-password.aspx Don't forget to restart Apache: `$ sudo systemctl restart apache2`
Author
Owner

@eekdro commented on GitHub (May 5, 2024):

I've done various tests with the same problem. As a result of several tests, the same problem occurs except for the APP_URL option. When entering IP, you must write down the IP that can be accessed from the outside.

@eekdro commented on GitHub (May 5, 2024): I've done various tests with the same problem. As a result of several tests, the same problem occurs except for the APP_URL option. When entering IP, you must write down the IP that can be accessed from the outside.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/BookStack#1528