wercker.com连接到MySQL数据库

前端之家收集整理的这篇文章主要介绍了wercker.com连接到MySQL数据库 前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

背景

我正在尝试使用http://wercker.com为Yii2应用程序构建一些自动化测试.我创建了自己的Docker存储库https://hub.docker.com/r/consynki/yii2/,该存储库提供了一个简单的LAMP堆栈.

我将Docker存储库用作wercker.yml文件中的框,并通过一些简单的步骤来设置我的应用,初始化数据库,然后运行PHPunit测试

Box: consynki/yii2

build:
  steps:

- script:
    name: Update enviroment dependencies
    code: |-
      curl -sS https://getcomposer.org/installer | PHP -- --install-dir=/usr/bin/ --filename=composer

- script:
    name: Install Composer dependencies
    code: |-
      rm -rf ./vendor
      /usr/bin/composer install --no-interaction --prefer-source

- script:
    name: Apache site install
    code: |-
      sudo chmod -R 755 /var/www
      sudo cp -r ./ /var/www/example.lan/
      sudo chown -R $USER:$USER /var/www/example.lan/
      sudo cp ./config/example.lan.conf /etc/apache2/sites-available/example.lan.conf
      sudo a2ensite example.lan.conf
      sudo cp -fr ./config/hosts /etc/hosts
      sudo service apache2 restart

- script:
    name: Create database
    code: |-
      MysqL -uroot -e "SHOW DATABASES;"
      MysqL -uroot -e "CREATE DATABASE IF NOT EXISTS test"

- script:
    name: PHPUnit integration tests
    code: |-
      ./vendor/bin/PHPunit --configuration PHPunit.xml

问题

问题是,当我使用wercker CLI wercker构建运行我的构建时,它无法连接到MysqL.我不断收到以下连接错误ERROR 2002(HY000):尝试运行“创建数据库”步骤时,无法通过套接字’/var/run/MysqLd/MysqLd.sock'(2)连接到本地MysqL服务器.

 - script:
    name: Create database
    code: |-
      MysqL -uroot -e "SHOW DATABASES;"
      MysqL -uroot -e "CREATE DATABASE IF NOT EXISTS test"

我知道docker容器具有MysqL连接,因为我可以SSH进入它并运行MysqL -uroot -e“ SHOW DATABASES;”.

编辑我当前进行中的巫师灯模板可在https://github.com/levi-putna/php-cli-template获得

请求

我知道wercker.com相对较新,并且没有很多文档.但我希望有人能提供一个示例,说明如何在wercker测试运行中使用MysqL.

编辑-使用Wercker服务

我还尝试使用Wercker MariaBD服务进行连接,因为它并非完全是MysqL,因此不是对我的生产环境的真实测试,但应该足以开始测试.

我更新了wercker.yml以添加mariadb服务.简化了使数据库连接正常工作的步骤.

Box: consynki/yii2

services:
    - id: mariadb

      # your credentials for Docker Hub
      username: $USERNAME
      password: $PASSWORD
      tag: latest

      # set the required environment variable
      env:
        MysqL_ROOT_PASSWORD: mypassword
        MysqL_DATABASE: test_database
        MysqL_USER: admin
        MysqL_PASSWORD: test123

build:

  steps:

    - script:
        name: Create database
        code: |-
          MysqL -h $MARIADB_PORT_3306_TCP_ADDR -P $MARIADB_PORT_3306_TCP_PORT -u $MysqL_USER -p test123 -v
          MysqL -h $MARIADB_PORT_3306_TCP_ADDR -P $MARIADB_PORT_3306_TCP_PORT -u $MysqL_USER -p test123 -e "SHOW DATABASES;"

我似乎仍然遇到与原始方法相同的错误.错误2002(HY000):无法通过套接字’/var/run/MysqLd/MysqLd.sock'(2)连接到本地MysqL服务器

在wercker步骤退出后,我还看到了一些其他日志消息.

WARNING Box container has already stopped.
Initializing database
2016-03-01 22:51:00 140429748197312 [Note] /usr/sbin/MysqLd (MysqLd 10.1.12-MariaDB-1~jessie) starting as process 51 ...
2016-03-01 22:51:00 140429748197312 [Note] InnoDB: Using mutexes to ref count buffer pool pages
2016-03-01 22:51:00 140429748197312 [Note] InnoDB: The InnoDB memory heap is disabled
2016-03-01 22:51:00 140429748197312 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2016-03-01 22:51:00 140429748197312 [Note] InnoDB: Memory barrier is not used
2016-03-01 22:51:00 140429748197312 [Note] InnoDB: Compressed tables use zlib 1.2.8
2016-03-01 22:51:00 140429748197312 [Note] InnoDB: Using Linux native AIO
2016-03-01 22:51:00 140429748197312 [Note] InnoDB: Using SSE crc32 instructions
2016-03-01 22:51:00 140429748197312 [Note] InnoDB: Initializing buffer pool,size = 256.0M
2016-03-01 22:51:00 140429748197312 [Note] InnoDB: Completed initialization of buffer pool
2016-03-01 22:51:00 140429748197312 [Note] InnoDB: The first specified data file ./ibdata1 did not exist: a new database to be created!
2016-03-01 22:51:00 140429748197312 [Note] InnoDB: Setting file ./ibdata1 size to 12 MB
2016-03-01 22:51:00 140429748197312 [Note] InnoDB: Database physically writes the file full: wait...
2016-03-01 22:51:01 140429748197312 [Note] InnoDB: Setting log file ./ib_logfile101 size to 48 MB
2016-03-01 22:51:01 140429748197312 [Note] InnoDB: Setting log file ./ib_logfile1 size to 48 MB
2016-03-01 22:51:01 140429748197312 [Note] InnoDB: Renaming log file ./ib_logfile101 to ./ib_logfile0
2016-03-01 22:51:01 140429748197312 [Warning] InnoDB: New log files created,LSN=45883
2016-03-01 22:51:01 140429748197312 [Note] InnoDB: Doublewrite buffer not found: creating new
2016-03-01 22:51:01 140429748197312 [Note] InnoDB: Doublewrite buffer created
2016-03-01 22:51:01 140429748197312 [Note] InnoDB: 128 rollback segment(s) are active.
2016-03-01 22:51:01 140429748197312 [Warning] InnoDB: Creating foreign key constraint system tables.
2016-03-01 22:51:01 140429748197312 [Note] InnoDB: Foreign key constraint system tables created
2016-03-01 22:51:01 140429748197312 [Note] InnoDB: Creating tablespace and datafile system tables.
2016-03-01 22:51:01 140429748197312 [Note] InnoDB: Tablespace and datafile system tables created.
2016-03-01 22:51:01 140429748197312 [Note] InnoDB: Waiting for purge to start
2016-03-01 22:51:01 140429748197312 [Note] InnoDB:  Percona XtraDB (http://www.percona.com) 5.6.28-76.1 started; log sequence number 0
2016-03-01 22:51:01 140428963710720 [Note] InnoDB: Dumping buffer pool(s) not yet started
2016-03-01 22:51:03 140216194230208 [Note] /usr/sbin/MysqLd (MysqLd 10.1.12-MariaDB-1~jessie) starting as process 80 ...
2016-03-01 22:51:03 140216194230208 [Note] InnoDB: Using mutexes to ref count buffer pool pages
2016-03-01 22:51:03 140216194230208 [Note] InnoDB: The InnoDB memory heap is disabled
2016-03-01 22:51:03 140216194230208 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2016-03-01 22:51:03 140216194230208 [Note] InnoDB: Memory barrier is not used
2016-03-01 22:51:03 140216194230208 [Note] InnoDB: Compressed tables use zlib 1.2.8
2016-03-01 22:51:03 140216194230208 [Note] InnoDB: Using Linux native AIO
2016-03-01 22:51:03 140216194230208 [Note] InnoDB: Using SSE crc32 instructions
2016-03-01 22:51:03 140216194230208 [Note] InnoDB: Initializing buffer pool,size = 256.0M
2016-03-01 22:51:03 140216194230208 [Note] InnoDB: Completed initialization of buffer pool
2016-03-01 22:51:03 140216194230208 [Note] InnoDB: Highest supported file format is Barracuda.
2016-03-01 22:51:03 140216194230208 [Note] InnoDB: 128 rollback segment(s) are active.
2016-03-01 22:51:03 140216194230208 [Note] InnoDB: Waiting for purge to start
2016-03-01 22:51:03 140216194230208 [Note] InnoDB:  Percona XtraDB (http://www.percona.com) 5.6.28-76.1 started; log sequence number 1616799
2016-03-01 22:51:04 140215410722560 [Note] InnoDB: Dumping buffer pool(s) not yet started
2016-03-01 22:51:06 140659046377408 [Note] /usr/sbin/MysqLd (MysqLd 10.1.12-MariaDB-1~jessie) starting as process 109 ...
2016-03-01 22:51:06 140659046377408 [Note] InnoDB: Using mutexes to ref count buffer pool pages
2016-03-01 22:51:06 140659046377408 [Note] InnoDB: The InnoDB memory heap is disabled
2016-03-01 22:51:06 140659046377408 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2016-03-01 22:51:06 140659046377408 [Note] InnoDB: Memory barrier is not used
2016-03-01 22:51:06 140659046377408 [Note] InnoDB: Compressed tables use zlib 1.2.8
2016-03-01 22:51:06 140659046377408 [Note] InnoDB: Using Linux native AIO
2016-03-01 22:51:06 140659046377408 [Note] InnoDB: Using SSE crc32 instructions
2016-03-01 22:51:06 140659046377408 [Note] InnoDB: Initializing buffer pool,size = 256.0M
2016-03-01 22:51:06 140659046377408 [Note] InnoDB: Completed initialization of buffer pool
2016-03-01 22:51:06 140659046377408 [Note] InnoDB: Highest supported file format is Barracuda.
2016-03-01 22:51:06 140659046377408 [Note] InnoDB: 128 rollback segment(s) are active.
2016-03-01 22:51:06 140659046377408 [Note] InnoDB: Waiting for purge to start
2016-03-01 22:51:06 140659046377408 [Note] InnoDB:  Percona XtraDB (http://www.percona.com) 5.6.28-76.1 started; log sequence number 1616809
2016-03-01 22:51:06 140658262116096 [Note] InnoDB: Dumping buffer pool(s) not yet started
ERROR: 1049  Unknown database 'test'
2016-03-01 22:51:06 140659046377408 [ERROR] Aborting
最佳答案
您可以使用由Wercker准备的现成的MysqL服务器,而不用自行设置.这将确保它在两次调用之间仍然存在.

Check out this document.

猜你在找的Docker相关文章