简体   繁体   中英

Laravel Sail starting error related to MySQL on Ububtu 22

I added Sail to a current Laravel project

composer require laravel/sail --dev
php artisan sail:install

but when I run ./vendor/bin/sail up I get MySQL error:

:~/work/dashboard$ ./vendor/bin/sail up 
[+] Running 3/3
 ⠿ Network dashboard_sail              Created                                                                                                                                   0.1s
 ⠿ Container dashboard-mysql-1         Created                                                                                                                                   2.8s
 ⠿ Container dashboard-laravel.test-1  Created                                                                                                                                   1.1s
Attaching to dashboard-laravel.test-1, dashboard-mysql-1
dashboard-mysql-1         | [Entrypoint] MySQL Docker Image 8.0.31-1.2.10-server
dashboard-mysql-1         | [Entrypoint] Starting MySQL 8.0.31-1.2.10-server
dashboard-mysql-1         | 2022-10-17T10:10:38.740784Z 0 [Warning] [MY-011068] [Server] The syntax '--skip-host-cache' is deprecated and will be removed in a future release. Please use SET GLOBAL host_cache_size=0 instead.
dashboard-mysql-1         | 2022-10-17T10:10:38.741647Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.0.31) starting as process 1
dashboard-mysql-1         | 2022-10-17T10:10:38.750935Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
dashboard-mysql-1         | 2022-10-17T10:10:38.795221Z 1 [ERROR] [MY-012960] [InnoDB] Cannot create redo log files because data files are corrupt or the database was not shut down cleanly after creating the data files.
dashboard-mysql-1         | 2022-10-17T10:10:39.287522Z 1 [ERROR] [MY-010334] [Server] Failed to initialize DD Storage Engine
dashboard-mysql-1         | 2022-10-17T10:10:39.287656Z 0 [ERROR] [MY-010020] [Server] Data Dictionary initialization failed.
dashboard-mysql-1         | 2022-10-17T10:10:39.287668Z 0 [ERROR] [MY-010119] [Server] Aborting
dashboard-mysql-1         | 2022-10-17T10:10:39.287971Z 0 [System] [MY-010910] [Server] /usr/sbin/mysqld: Shutdown complete (mysqld 8.0.31)  MySQL Community Server - GPL.
dashboard-laravel.test-1  | 2022-10-17 10:10:41,882 INFO Set uid to user 0 succeeded
dashboard-laravel.test-1  | 2022-10-17 10:10:41,883 INFO supervisord started with pid 1
dashboard-laravel.test-1  | 2022-10-17 10:10:42,885 INFO spawned: 'php' with pid 16
dashboard-laravel.test-1  | 
dashboard-laravel.test-1  |    Illuminate\Database\QueryException 
dashboard-laravel.test-1  | 
dashboard-laravel.test-1  |   SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo for mysql failed: Temporary failure in name resolution (SQL: select * from information_schema.tables where table_schema = dashboard and table_name = report_errors and table_type = 'BASE TABLE')

.env

DB_CONNECTION=mysql
DB_HOST=mysql
DB_PORT=3306
DB_DATABASE=dashboard
DB_USERNAME=sail
DB_PASSWORD=password

and when I open http://localhost I get This site can't be reached . How to fix this?

在此处输入图像描述


[Update]

I run docker ps -a and fount 2 containers: onr for sail and the other for MySQL.

f20cf9718056   sail-8.1/app           ... dashboard-laravel.test-1
b7007d3a061c   mysql/mysql-server:8.0 ... dashboard-mysql-1

I run docker-compose start and both containers are running.

docker-compose start
Starting mysql        ... done
Starting laravel.test ... done

Now I try to run ./vendor/bin/sail up But I get

SQLSTATE[HY000] [2002] Connection refused

I run docker ps but the MySQL container exit

f20cf9718056   sail-8.1/app   "start-container"   About an hour ago   Up 2 minutes   0.0.0.0:80->80/tcp, :::80->80/tcp, 0.0.0.0:5173->5173/tcp, :::5173->5173/tcp, 8000/tcp   dashboard-laravel.test-1

MySQL Logs

docker logs dashboard-mysql-1
[Entrypoint] MySQL Docker Image 8.0.31-1.2.10-server
[Entrypoint] Starting MySQL 8.0.31-1.2.10-server
2022-10-17T14:01:13.615764Z 0 [Warning] [MY-011068] [Server] The syntax '--skip-host-cache' is deprecated and will be removed in a future release. Please use SET GLOBAL host_cache_size=0 instead.
2022-10-17T14:01:13.616826Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.0.31) starting as process 1
2022-10-17T14:01:13.627454Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2022-10-17T14:01:13.832319Z 1 [ERROR] [MY-012960] [InnoDB] Cannot create redo log files because data files are corrupt or the database was not shut down cleanly after creating the data files.
2022-10-17T14:01:14.321686Z 1 [ERROR] [MY-010334] [Server] Failed to initialize DD Storage Engine
2022-10-17T14:01:14.321863Z 0 [ERROR] [MY-010020] [Server] Data Dictionary initialization failed.
2022-10-17T14:01:14.321881Z 0 [ERROR] [MY-010119] [Server] Aborting
2022-10-17T14:01:14.322186Z 0 [System] [MY-010910] [Server] /usr/sbin/mysqld: Shutdown complete (mysqld 8.0.31)  MySQL Community Server - GPL.
[Entrypoint] MySQL Docker Image 8.0.31-1.2.10-server
[Entrypoint] Starting MySQL 8.0.31-1.2.10-server
2022-10-17T14:10:37.311446Z 0 [Warning] [MY-011068] [Server] The syntax '--skip-host-cache' is deprecated and will be removed in a future release. Please use SET GLOBAL host_cache_size=0 instead.
2022-10-17T14:10:37.312494Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.0.31) starting as process 1
2022-10-17T14:10:37.331341Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2022-10-17T14:10:37.442677Z 1 [ERROR] [MY-012960] [InnoDB] Cannot create redo log files because data files are corrupt or the database was not shut down cleanly after creating the data files.
2022-10-17T14:10:37.932648Z 1 [ERROR] [MY-010334] [Server] Failed to initialize DD Storage Engine
2022-10-17T14:10:37.932756Z 0 [ERROR] [MY-010020] [Server] Data Dictionary initialization failed.
2022-10-17T14:10:37.932772Z 0 [ERROR] [MY-010119] [Server] Aborting
2022-10-17T14:10:37.933079Z 0 [System] [MY-010910] [Server] /usr/sbin/mysqld: Shutdown complete (mysqld 8.0.31)  MySQL Community Server - GPL.
[Entrypoint] MySQL Docker Image 8.0.31-1.2.10-server
[Entrypoint] Starting MySQL 8.0.31-1.2.10-server
2022-10-17T14:10:47.381949Z 0 [Warning] [MY-011068] [Server] The syntax '--skip-host-cache' is deprecated and will be removed in a future release. Please use SET GLOBAL host_cache_size=0 instead.
2022-10-17T14:10:47.382974Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.0.31) starting as process 1
2022-10-17T14:10:47.389572Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2022-10-17T14:10:47.411196Z 1 [ERROR] [MY-012960] [InnoDB] Cannot create redo log files because data files are corrupt or the database was not shut down cleanly after creating the data files.
2022-10-17T14:10:47.901979Z 1 [ERROR] [MY-010334] [Server] Failed to initialize DD Storage Engine
2022-10-17T14:10:47.902111Z 0 [ERROR] [MY-010020] [Server] Data Dictionary initialization failed.
2022-10-17T14:10:47.902128Z 0 [ERROR] [MY-010119] [Server] Aborting
2022-10-17T14:10:47.902444Z 0 [System] [MY-010910] [Server] /usr/sbin/mysqld: Shutdown complete (mysqld 8.0.31)  MySQL Community Server - GPL.
[Entrypoint] MySQL Docker Image 8.0.31-1.2.10-server
[Entrypoint] Starting MySQL 8.0.31-1.2.10-server
2022-10-17T15:04:03.773574Z 0 [Warning] [MY-011068] [Server] The syntax '--skip-host-cache' is deprecated and will be removed in a future release. Please use SET GLOBAL host_cache_size=0 instead.
2022-10-17T15:04:03.774621Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.0.31) starting as process 1
2022-10-17T15:04:03.788273Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2022-10-17T15:04:03.852948Z 1 [ERROR] [MY-012960] [InnoDB] Cannot create redo log files because data files are corrupt or the database was not shut down cleanly after creating the data files.
2022-10-17T15:04:04.341269Z 1 [ERROR] [MY-010334] [Server] Failed to initialize DD Storage Engine
2022-10-17T15:04:04.341410Z 0 [ERROR] [MY-010020] [Server] Data Dictionary initialization failed.
2022-10-17T15:04:04.341425Z 0 [ERROR] [MY-010119] [Server] Aborting
2022-10-17T15:04:04.341726Z 0 [System] [MY-010910] [Server] /usr/sbin/mysqld: Shutdown complete (mysqld 8.0.31)  MySQL Community Server - GPL.

I did not use Laravel Sail I prefer to make my own docker and docker-compose files so let me get you a bit closer to the error. Error: Failed to connect to server: php.network_getaddresses: getaddrinfo failed this error can occur due to two reasons.

  1. there might be an issue with your DNS settings
  2. PHP may not be able to get the.network addresses for a given host/domain name. so you need to make sure the service name in your docker file for MYSQL is used in your Laravel.env file as a DB_HOST. and one more thing Laravel is trying to make a select statement somehow outside of the container so you got the mentioned error above in case you took care of the 2 points I mentioned above.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM