代码之家  ›  专栏  ›  技术社区  ›  Jacobo

PDOException:SQLSTATE[HY000][2054]服务器请求的身份验证方法客户端未知(Bitbucket管道)

  •  0
  • Jacobo  · 技术社区  · 6 年前

    我正在运行一个bitbucket管道,用PHP单元执行所有单元测试。当我在本地执行测试时,它们都通过了。但在bitbucket管道上,它总是失败。在本例中,测试与我们正在检查的外部服务相关。

    <?php
    
    namespace Tests\Unit;
    
    use Tests\TestCase;
    use Illuminate\Foundation\Testing\RefreshDatabase;
    
    use MyService;
    
    class MyTest extends TestCase
    {
        /**
         * Test the dummies in this new system
         *
         * @return void
         */
        public function testDumies()
        {
            $games = DummyService::getDummies();
            $this->assertTrue(count($dummies) > 0);
        }
    
        public function testDummiesOfUser()
        {
            $dummies = DummyService::getDummiesOfUser('someemail@mail.com');
            $this->assertTrue(count($dummies) > 0);
        }
    }
    

    下面是获取假人的服务

    <?php
    namespace App\Services;
    
    class DummyService {
    
        /**
         * Get dummies
         *
         * @return void
         */
        public function getDummies() {
            $collection = [];
    
            $games = $this->getDummiesInUrl('http://my-project/api/v1/platform/dummies');
            foreach($dummies as $dummy) {
                $collection[] = $dummy;
            }
    
            return $collection;
        }
    
        /**
         * Retrieves the dummies in url
         *
         * @param string $endpoint
         * @return array
         */
        public function getDummiesInUrl($endpoint) {
            $client = new \GuzzleHttp\Client();
            $res = $client->request('GET', $endpoint);
            $body = $res->getBody();
            $body = json_decode($body, true);
            $data = $body['data'];
            $dummies = $data['dummies'];
            return $dummies;
        }
    
        /**
         * Returns the dummies of an user
         *
         * @param string $email
         * @return array
         */
        public function getDummiesOfUser($email) {
            $collection = [];
            $dummies = $this->getDummiesOfUserInUrl('http://myroute/api/v1/platform/dummies/user', $email);
            foreach($dummies as $d) {
                $collection[] = $d;
            }
            return $collection;
        }
    
        /**
         * Get gameplays in url
         *
         * @param string $endpoint
         * @param string $email
         * @return array
         */
        public function getDummiesOfUserInUrl($endpoint, $email) {
            $client = new \GuzzleHttp\Client();
            $res = $client->request('GET', $endpoint, ['query' => ['email' => $email]]);
            $body = $res->getBody();
            $body = json_decode($body, true);
            $data = $body['data'];
            $dummies = $data['dummiess'];
            return $dummies;
        }
    }
    

    但在bitbucket管道上测试时,我发现以下错误:

    PDOException: SQLSTATE[HY000] [2054] The server requested authentication method unknown to the client Caused by PDOException:PDO::__construct(): The server requested authentication method unknown to the client [caching_sha2_password]

    1 回复  |  直到 6 年前
        1
  •  1
  •   Jacobo    6 年前

    显然,mysql 8的新公共版本改变了很多事情。因此,为了继续使用您的管道,我编辑了 bitbucket-pipelines.yml 并将mysql镜像版本从mysql改为mysql:5.7.22

    definitions:
      services:
        mysql:
          image: mysql:5.7.22
          environment:
            MYSQL_DATABASE: 'homestead'
            MYSQL_RANDOM_ROOT_PASSWORD: 'yes'
            MYSQL_USER: 'homestead'
            MYSQL_PASSWORD: 'secret'