Laravel Sail 中 MySQL 和 MariaDB 有什么区别

问题描述 投票:0回答:1

我在项目中使用MySQL,必须切换到MariaDB。到目前为止我知道,它是相同的,我唯一要做的就是将图像从:

image: 'mysql/mysql-server:8.0'
更改为
image: 'mariadb:latest'
,因为它应该是相同的。

docker-compose.yml

    mysql:
        image: 'mariadb:latest'
        ports:
            - '${FORWARD_DB_PORT:-3306}:3306'
        environment:
            MYSQL_ROOT_PASSWORD: '${DB_PASSWORD}'
            MYSQL_ROOT_HOST: "%"
            MYSQL_DATABASE: '${DB_DATABASE}'
            MYSQL_USER: '${DB_USERNAME}'
            MYSQL_PASSWORD: '${DB_PASSWORD}'
            MYSQL_ALLOW_EMPTY_PASSWORD: 1
        volumes:
            - 'sail-project-mysql:/var/lib/mysql'
            - './vendor/laravel/sail/database/mysql/create-testing-database.sh:/docker-entrypoint-initdb.d/10-create-testing-database.sh'
        networks:
            - sail
        healthcheck:
            test:
                - CMD
                - mysqladmin
                - ping
                - '-p${DB_PASSWORD}'
            retries: 3
            timeout: 5s

数据库.php

    'mysql' => [
            'driver' => 'mysql',
            'url' => env('DATABASE_URL'),
            'host' => env('DB_HOST', 'mysql'),
            'port' => env('DB_PORT', '3306'),
            'database' => env('DB_DATABASE', 'forge'),
            'username' => env('DB_USERNAME', 'forge'),
            'password' => env('DB_PASSWORD', ''),
            'unix_socket' => env('DB_SOCKET', ''),
            'charset' => 'utf8mb4',
            'collation' => 'utf8mb4_unicode_ci',
            'prefix' => '',
            'prefix_indexes' => true,
            'strict' => true,
            'engine' => null,
            'options' => extension_loaded('pdo_mysql') ? array_filter([
                PDO::MYSQL_ATTR_SSL_CA => env('MYSQL_ATTR_SSL_CA'),
            ]) : [],
        ],

.env

DB_CONNECTION=mysql
DB_HOST=localhost
DB_PORT=3306
DB_DATABASE=<database_name>
DB_USERNAME=<username>
DB_PASSWORD=<password>
sail artisan migrate

   Illuminate\Database\QueryException 

  SQLSTATE[HY000] [2002] No such file or directory (Connection: mysql, SQL:
select 
   table_name as `name`,
   (data_length + index_length) as `size`,
   table_comment as `comment`,
   engine as `engine`,
   table_collation as `collation` 
from information_schema.tables 
where table_schema = '<database_name>' 
  and table_type in ('BASE TABLE', 'SYSTEM VERSIONED') order by table_name)

我跑了

sail artisan up --build
并且跑成功了。 Docker 中的 DB 服务器在线并且日志中没有错误

2024-01-21 18:34:25 2024-01-21 17:34:25 0 [Note] Starting MariaDB 11.2.2-MariaDB-1:11.2.2+maria~ubu2204 source revision 929532a9426d085111c24c63de9c23cc54382259 as process 1
2024-01-21 18:34:25 2024-01-21 17:34:25 0 [Note] InnoDB: Compressed tables use zlib 1.2.11
2024-01-21 18:34:25 2024-01-21 17:34:25 0 [Note] InnoDB: Number of transaction pools: 1
2024-01-21 18:34:25 2024-01-21 17:34:25 0 [Note] InnoDB: Using ARMv8 crc32 + pmull instructions
2024-01-21 18:34:25 2024-01-21 17:34:25 0 [Note] mariadbd: O_TMPFILE is not supported on /tmp (disabling future attempts)
2024-01-21 18:34:25 2024-01-21 17:34:25 0 [Note] InnoDB: Using liburing
2024-01-21 18:34:25 2024-01-21 17:34:25 0 [Note] InnoDB: Initializing buffer pool, total size = 128.000MiB, chunk size = 2.000MiB
2024-01-21 18:34:25 2024-01-21 17:34:25 0 [Note] InnoDB: Completed initialization of buffer pool
2024-01-21 18:34:25 2024-01-21 17:34:25 0 [Note] InnoDB: File system buffers for log disabled (block size=512 bytes)
2024-01-21 18:34:25 2024-01-21 17:34:25 0 [Note] InnoDB: End of log at LSN=47959
2024-01-21 18:34:25 2024-01-21 17:34:25 0 [Note] InnoDB: Opened 3 undo tablespaces
2024-01-21 18:34:25 2024-01-21 17:34:25 0 [Note] InnoDB: 128 rollback segments in 3 undo tablespaces are active.
2024-01-21 18:34:25 2024-01-21 17:34:25 0 [Note] InnoDB: Setting file './ibtmp1' size to 12.000MiB. Physically writing the file full; Please wait ...
2024-01-21 18:34:25 2024-01-21 17:34:25 0 [Note] InnoDB: File './ibtmp1' size is now 12.000MiB.
2024-01-21 18:34:25 2024-01-21 17:34:25 0 [Note] InnoDB: log sequence number 47959; transaction id 16
2024-01-21 18:34:25 2024-01-21 17:34:25 0 [Note] InnoDB: Loading buffer pool(s) from /var/lib/mysql/ib_buffer_pool
2024-01-21 18:34:25 2024-01-21 17:34:25 0 [Note] Plugin 'FEEDBACK' is disabled.
2024-01-21 18:34:25 2024-01-21 17:34:25 0 [Note] Plugin 'wsrep-provider' is disabled.
2024-01-21 18:34:25 2024-01-21 17:34:25 0 [Note] InnoDB: Buffer pool(s) load completed at 240121 17:34:25
2024-01-21 18:34:25 2024-01-21 17:34:25 0 [Note] Server socket created on IP: '0.0.0.0'.
2024-01-21 18:34:25 2024-01-21 17:34:25 0 [Note] Server socket created on IP: '::'.
2024-01-21 18:34:25 2024-01-21 17:34:25 0 [Note] mariadbd: Event Scheduler: Loaded 0 events
2024-01-21 18:34:25 2024-01-21 17:34:25 0 [Note] mariadbd: ready for connections.
2024-01-21 18:34:25 Version: '11.2.2-MariaDB-1:11.2.2+maria~ubu2204'  socket: '/run/mysqld/mysqld.sock'  port: 3306  mariadb.org binary distribution

在 Laravel 的文档中我没有找到有关此的一些信息。 哪个配置丢失了,或者在我的情况下是错误的?

mysql laravel docker mariadb laravel-sail
1个回答
0
投票

以下帖子似乎与您的问题相关。请检查是否对您有帮助。 谢谢 https://laracasts.com/discuss/channels/laravel/laravel-sail-cant-create-mariadb-or-mysql-images

© www.soinside.com 2019 - 2024. All rights reserved.