Setting up mysql 5.7 environment variables - Access denied for user (Laravel project)

I have gotten to this again:

SQLSTATE[HY000] [2002] Connection refused (SQL: SHOW FULL TABLES WHERE table_type = 'BASE TABLE')

With config

# PHP CircleCI 2.0 configuration file
#
# Check https://circleci.com/docs/2.0/language-php/ for more details
#
version: 2
jobs:
  build:
    docker:
      # specify the version you desire here
      - image: circleci/php:7.2-apache-stretch-node-browsers
        environment:
          MYSQL_ROOT_PASSWORD: password

      # Specify service dependencies here if necessary
      # CircleCI maintains a library of pre-built images
      # documented at https://circleci.com/docs/2.0/circleci-images/
      # - image: circleci/mysql:9.4

    steps:
      - checkout

      - run: sudo apt-get install -y libzip-dev
      - run: sudo docker-php-ext-install zip
      - run: sudo apt-get update
      - run: sudo apt-get install -y zlib1g-dev libicu-dev g++
      - run: sudo docker-php-ext-configure intl
      - run: sudo docker-php-ext-install intl
      - run: sudo docker-php-ext-install pdo_mysql
      - run: sudo apt-get install mysql-server
      - run: sudo apt-get install mysql-client
      - run: sudo debconf-set-selections <<< 'mysql-server mysql-server/root_password password password'
      - run: sudo debconf-set-selections <<< 'mysql-server mysql-server/root_password_again password password'
      - run: sudo apt-get -y install mysql-server

      # Download and cache dependencies
      - restore_cache:
          keys:
          - v1-dependencies-{{ checksum "composer.json" }}
          # fallback to using the latest cache if no exact match is found
          - v1-dependencies-

      - run: composer install -n --prefer-dist

      - save_cache:
          paths:
            - ./vendor
          key: v1-dependencies-{{ checksum "composer.json" }}

      # run tests!
      - run: ./vendor/bin/phpunit

Ahhā€¦ hang onā€¦ Nothing revolutionary. Just should not have had that line run: sudo apt-get install mysql-server before those other lines :smiley:

Also saw thisā€¦Laravel php artisan mysql connection refused

OK, so if you are still not operational, get an SSH session again, and try the stuff you did before. Is the database service running? Try connecting from the console again using the mysql binary.

Edit

Also saw thisā€¦Laravel php artisan mysql connection refused

OK, try changing your hostname to that?

SSH session

circleci@f2a0f9ad8564:~$ sudo service mysql status
[info] MariaDB is stopped..

Hmm, odd - what happens if you try starting it in SSH? I wonder if you need a separate run command to start it explicitly. Also in SSH, have a look at the MySQL server logs to see if there are any clues about start-up problems.

Hmā€¦ I think I will give up on this tonight and continue tomorrowā€¦

I am ending at

SQLSTATE[HY000] [2002] Connection refused (SQL: SHOW FULL TABLES WHERE table_type = 'BASE TABLE')

with config

# PHP CircleCI 2.0 configuration file
#
# Check https://circleci.com/docs/2.0/language-php/ for more details
#
version: 2
jobs:
  build:
    docker:
      # specify the version you desire here
      - image: circleci/php:7.2-apache-stretch-node-browsers
        environment:
          MYSQL_ROOT_PASSWORD: password
          MYSQL_HOST: 127.0.0.1

      # Specify service dependencies here if necessary
      # CircleCI maintains a library of pre-built images
      # documented at https://circleci.com/docs/2.0/circleci-images/
      # - image: circleci/mysql:9.4

    steps:
      - checkout

      - run: sudo apt-get install -y libzip-dev
      - run: sudo docker-php-ext-install zip
      - run: sudo apt-get update
      - run: sudo apt-get install -y zlib1g-dev libicu-dev g++
      - run: sudo docker-php-ext-configure intl
      - run: sudo docker-php-ext-install intl
      - run: sudo docker-php-ext-install pdo_mysql
      - run: sudo apt-get install mysql-client
      - run: sudo debconf-set-selections <<< 'mysql-server mysql-server/root_password password password'
      - run: sudo debconf-set-selections <<< 'mysql-server mysql-server/root_password_again password password'
      - run: sudo apt-get -y install mysql-server

      # Download and cache dependencies
      - restore_cache:
          keys:
          - v1-dependencies-{{ checksum "composer.json" }}
          # fallback to using the latest cache if no exact match is found
          - v1-dependencies-

      - run: composer install -n --prefer-dist

      - save_cache:
          paths:
            - ./vendor
          key: v1-dependencies-{{ checksum "composer.json" }}

      # run tests!
      - run: ./vendor/bin/phpunit

and SSH output

circleci@1bd24fe0213f:~$ sudo service mysql status
[info] MariaDB is stopped..
circleci@1bd24fe0213f:~$ sudo service mysql start
[ ok ] Starting MariaDB database server: mysqld.
circleci@1bd24fe0213f:~$ mysql -u root -p
Enter password:
ERROR 1698 (28000): Access denied for user 'root'@'localhost'
circleci@1bd24fe0213f:~$ Connection to 34.234.204.156 closed by remote host.
Connection to 34.234.204.156 closed.

Not sure where to look for the log files and I feel itā€™s going to take a lot of googling for me :slight_smile: And itā€™s already late.

Thank you so so much for all your help and patience! :slight_smile:

P.S. Probably gotta add that start command as well. Or alternatively try something with the mysql image again.

No worries. Tomorrow, take a look at:

cat /var/log/mysql/error.log

And, sorry if this is obvious, but you are pushing your config changes and forcing a rebuild, right? If you persisted an SSH session across your work this evening, then your server would not have been rebuilt for each change you made to the YAML file.

Finally, also try this:

mysql -u root -p -h 127.0.0.1

I wonder if not specifying the host might try to start it in socket mode, and I think I saw something about that not working in Circle.

committing changes->that starts a build->Iā€™m cancelling it->restarting it with ssh

I can also see the config being used by the build in the app.

Nothing is obvious :slight_smile:

1 Like

Hmhmā€¦

SQLSTATE[HY000] [2002] Connection refused (SQL: SHOW FULL TABLES WHERE table_type = 'BASE TABLE')

SSH

circleci@d9eb397ed90c:~$ sudo service mysql status
[info] MariaDB is stopped..
circleci@d9eb397ed90c:~$ sudo service mysql start
[ ok ] Starting MariaDB database server: mysqld.
circleci@d9eb397ed90c:~$ mysql -u root -p -h 127.0.0.1
Enter password: (entering 'password' here, also tried with empty )
ERROR 1698 (28000): Access denied for user 'root'@'localhost'
circleci@d9eb397ed90c:~$ sudo cat /var/log/mysql/error.log

And I got this log out :sunny:

2018-03-07 23:13:19 140618111685184 [Note] InnoDB: innodb_empty_free_list_algorithm has been changed to legacy because of small buffer pool size. In order to use backoff, increase buffer pool at least up to 20MB.

2018-03-07 23:13:19 140618111685184 [Note] InnoDB: Using mutexes to ref count buffer pool pages
2018-03-07 23:13:19 140618111685184 [Note] InnoDB: The InnoDB memory heap is disabled
2018-03-07 23:13:19 140618111685184 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2018-03-07 23:13:19 140618111685184 [Note] InnoDB: GCC builtin __atomic_thread_fence() is used for memory barrier
2018-03-07 23:13:19 140618111685184 [Note] InnoDB: Compressed tables use zlib 1.2.8
2018-03-07 23:13:19 140618111685184 [Note] InnoDB: Using Linux native AIO
2018-03-07 23:13:19 140618111685184 [Note] InnoDB: Using SSE crc32 instructions
2018-03-07 23:13:19 140618111685184 [Note] InnoDB: Initializing buffer pool, size = 128.0M
2018-03-07 23:13:19 140618111685184 [Note] InnoDB: Completed initialization of buffer pool
2018-03-07 23:13:19 140618111685184 [Note] InnoDB: The first specified data file ./ibdata1 did not exist: a new database to be created!
2018-03-07 23:13:19 140618111685184 [Note] InnoDB: Setting file ./ibdata1 size to 12 MB
2018-03-07 23:13:19 140618111685184 [Note] InnoDB: Setting log file ./ib_logfile101 size to 48 MB
2018-03-07 23:13:19 140618111685184 [Note] InnoDB: Setting log file ./ib_logfile1 size to 48 MB
2018-03-07 23:13:20 140618111685184 [Note] InnoDB: Renaming log file ./ib_logfile101 to ./ib_logfile0
2018-03-07 23:13:20 140618111685184 [Warning] InnoDB: New log files created, LSN=45883
2018-03-07 23:13:20 140618111685184 [Note] InnoDB: Doublewrite buffer not found: creating new
2018-03-07 23:13:20 140618111685184 [Note] InnoDB: Doublewrite buffer created
2018-03-07 23:13:20 140618111685184 [Note] InnoDB: 128 rollback segment(s) are active.
2018-03-07 23:13:20 140618111685184 [Warning] InnoDB: Creating foreign key constraint system tables.
2018-03-07 23:13:20 140618111685184 [Note] InnoDB: Foreign key constraint system tables created
2018-03-07 23:13:20 140618111685184 [Note] InnoDB: Creating tablespace and datafile system tables.
2018-03-07 23:13:20 140618111685184 [Note] InnoDB: Tablespace and datafile system tables created.
2018-03-07 23:13:20 140618111685184 [Note] InnoDB: Waiting for purge to start
2018-03-07 23:13:20 140618111685184 [Note] InnoDB:  Percona XtraDB (http://www.percona.com) 5.6.36-82.1 started; log sequence number 0
2018-03-07 23:13:20 140617447372544 [Note] InnoDB: Dumping buffer pool(s) not yet started
2018-03-07 23:13:23 140245706506816 [Note] InnoDB: innodb_empty_free_list_algorithm has been changed to legacy because of small buffer pool size. In order to use backoff, increase buffer pool at least up to 20MB.

2018-03-07 23:13:23 140245706506816 [Note] InnoDB: Using mutexes to ref count buffer pool pages
2018-03-07 23:13:23 140245706506816 [Note] InnoDB: The InnoDB memory heap is disabled
2018-03-07 23:13:23 140245706506816 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2018-03-07 23:13:23 140245706506816 [Note] InnoDB: GCC builtin __atomic_thread_fence() is used for memory barrier
2018-03-07 23:13:23 140245706506816 [Note] InnoDB: Compressed tables use zlib 1.2.8
2018-03-07 23:13:23 140245706506816 [Note] InnoDB: Using Linux native AIO
2018-03-07 23:13:23 140245706506816 [Note] InnoDB: Using SSE crc32 instructions
2018-03-07 23:13:23 140245706506816 [Note] InnoDB: Initializing buffer pool, size = 128.0M
2018-03-07 23:13:24 140245706506816 [Note] InnoDB: Completed initialization of buffer pool
2018-03-07 23:13:24 140245706506816 [Note] InnoDB: Highest supported file format is Barracuda.
2018-03-07 23:13:24 140245706506816 [Note] InnoDB: 128 rollback segment(s) are active.
2018-03-07 23:13:24 140245706506816 [Note] InnoDB: Waiting for purge to start
2018-03-07 23:13:24 140245706506816 [Note] InnoDB:  Percona XtraDB (http://www.percona.com) 5.6.36-82.1 started; log sequence number 1616799
2018-03-07 23:13:24 140245039314688 [Note] InnoDB: Dumping buffer pool(s) not yet started
2018-03-07 23:13:27 139768133558848 [Note] InnoDB: innodb_empty_free_list_algorithm has been changed to legacy because of small buffer pool size. In order to use backoff, increase buffer pool at least up to 20MB.

2018-03-07 23:13:27 139768133558848 [Note] InnoDB: Using mutexes to ref count buffer pool pages
2018-03-07 23:13:27 139768133558848 [Note] InnoDB: The InnoDB memory heap is disabled
2018-03-07 23:13:27 139768133558848 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2018-03-07 23:13:27 139768133558848 [Note] InnoDB: GCC builtin __atomic_thread_fence() is used for memory barrier
2018-03-07 23:13:27 139768133558848 [Note] InnoDB: Compressed tables use zlib 1.2.8
2018-03-07 23:13:27 139768133558848 [Note] InnoDB: Using Linux native AIO
2018-03-07 23:13:27 139768133558848 [Note] InnoDB: Using SSE crc32 instructions
2018-03-07 23:13:27 139768133558848 [Note] InnoDB: Initializing buffer pool, size = 128.0M
2018-03-07 23:13:28 139768133558848 [Note] InnoDB: Completed initialization of buffer pool
2018-03-07 23:13:28 139768133558848 [Note] InnoDB: Highest supported file format is Barracuda.
2018-03-07 23:13:28 139768133558848 [Note] InnoDB: 128 rollback segment(s) are active.
2018-03-07 23:13:28 139768133558848 [Note] InnoDB: Waiting for purge to start
2018-03-07 23:13:28 139768133558848 [Note] InnoDB: Waiting for purge to start
2018-03-07 23:13:29 139768133558848 [Note] InnoDB:  Percona XtraDB (http://www.percona.com) 5.6.36-82.1 started; log sequence number 1616809
2018-03-07 23:13:29 139767467472640 [Note] InnoDB: Dumping buffer pool(s) not yet started
2018-03-07 23:13:32 139680482292288 [Note] InnoDB: innodb_empty_free_list_algorithm has been changed to legacy because of small buffer pool size. In order to use backoff, increase buffer pool at least up to 20MB.

2018-03-07 23:13:32 139680482292288 [Note] InnoDB: Using mutexes to ref count buffer pool pages
2018-03-07 23:13:32 139680482292288 [Note] InnoDB: The InnoDB memory heap is disabled
2018-03-07 23:13:32 139680482292288 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2018-03-07 23:13:32 139680482292288 [Note] InnoDB: GCC builtin __atomic_thread_fence() is used for memory barrier
2018-03-07 23:13:32 139680482292288 [Note] InnoDB: Compressed tables use zlib 1.2.8
2018-03-07 23:13:32 139680482292288 [Note] InnoDB: Using Linux native AIO
2018-03-07 23:13:32 139680482292288 [Note] InnoDB: Using SSE crc32 instructions
2018-03-07 23:13:32 139680482292288 [Note] InnoDB: Initializing buffer pool, size = 128.0M
2018-03-07 23:13:32 139680482292288 [Note] InnoDB: Completed initialization of buffer pool
2018-03-07 23:13:32 139680482292288 [Note] InnoDB: Highest supported file format is Barracuda.
2018-03-07 23:13:32 139680482292288 [Note] InnoDB: 128 rollback segment(s) are active.
2018-03-07 23:13:32 139680482292288 [Note] InnoDB: Waiting for purge to start
2018-03-07 23:13:32 139680482292288 [Note] InnoDB:  Percona XtraDB (http://www.percona.com) 5.6.36-82.1 started; log sequence number 1616819
2018-03-07 23:13:32 139680482292288 [Note] Plugin 'FEEDBACK' is disabled.
2018-03-07 23:13:32 139679823296256 [Note] InnoDB: Dumping buffer pool(s) not yet started

I got intrigued by this problem, so have fixed it. :smiley_cat: Will ping the solutions tomorrow, it was a bit multi-pronged. Ping me here if I forget.

Oh really!? What did you do?? :open_mouth:

So the solutions were:

  • As you found, server needs to be manually started (Maria is different to MySQL in this regard)
  • The default MySQL root password is already created, itā€™s empty, so resetting it is not required - red herring from me, sorry!
  • To run things that use MySQL root you need to run as machine root (I suspect another Maria difference) so it feels better to create a non-root MySQL user
  • The PHP MySQL driver was missing a socket config. It may be possible to force it to connect via TCP, but once itā€™s working, itā€™s best to leave well alone :smile_cat:

Iā€™ll post my config below.

Hereā€™s my test file, connect.php (the non-zero exit code will cause a Circle failure if it fails):

<?php
$servername = "localhost";
$username = "myuser";
$password = "password";

try {
    $conn = new PDO("mysql:host=$servername", $username, $password);
    // set the PDO error mode to exception
    $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    echo "Connected successfully\n";
}
catch(PDOException $e)
{
    echo "Connection failed: " . $e->getMessage() . "\n";
    die(1);
}

And here is the Circle config. Iā€™ve wrapped up each section and named it:

version: 2
jobs:
  build:
    docker:
      - image: circleci/php:7.2-apache-stretch-node-browsers
        environment:
          MYSQL_ROOT_PASSWORD: password
          MYSQL_HOST: 127.0.0.1
    steps:
      - checkout
      - run:
          name: Install things we need
          command: |
            sudo apt-get update
            sudo apt-get install -y libzip-dev
            sudo apt-get install -y zlib1g-dev libicu-dev g++
            sudo apt-get install mysql-client
            sudo apt-get -y install mysql-server
      - run:
          name: Install PHP exts
          command: |
            sudo docker-php-ext-install zip
            sudo docker-php-ext-configure intl
            sudo docker-php-ext-install intl
            sudo docker-php-ext-install pdo_mysql
      - run:
          name: Fix MySQL socket config
          command: |
            sudo sh -c "echo 'pdo_mysql.default_socket=/var/run/mysqld/mysqld.sock' > /usr/local/etc/php/conf.d/pdo.ini"
      - run:
          name: Start database server
          command: |
            sudo service mysql start
            sleep 2
            ps aux | grep mysql
      - run:
          name: Create non-admin user
          command: |
            sudo mysql -u root -e "CREATE user myuser IDENTIFIED BY 'password';"
      - run:
          name: Run tests
          command: |
            php connect.php

The SSH feature is a life-saver!

Yes, sounds like something I would never have figured out by myself! :slight_smile: Thank you!

However, itā€™s still not working for me. (surprise) :slight_smile:

Also, looking backā€¦it was stupid that I said the databases were created on run of phpunit - it only runs the migrations, but I need the databases to be there. So I guess I will need to create two mysql database schemas during the config (or something) because that is what my tests use.

But what I still donā€™t understand is where the environment variables Iā€™m setting in the CircleCI app come in to play, and how are they different form the variables in the config file:

image
(these are the environment variables that should be used during testing)
(sorry for the image but itā€™s the best I can do to show where theyā€™re located)

vs

      - image: circleci/php:7.2-apache-stretch-node-browsers
        environment:
          MYSQL_ROOT_PASSWORD: password
          MYSQL_HOST: 127.0.0.1

P.S. Iā€™ve updated my config file to:

# PHP CircleCI 2.0 configuration file
#
# Check https://circleci.com/docs/2.0/language-php/ for more details
#
version: 2
jobs:
  build:
    docker:
      # specify the version you desire here
      - image: circleci/php:7.2-apache-stretch-node-browsers
        environment:
          MYSQL_ROOT_PASSWORD: password
          MYSQL_HOST: 127.0.0.1

      # Specify service dependencies here if necessary
      # CircleCI maintains a library of pre-built images
      # documented at https://circleci.com/docs/2.0/circleci-images/
      # - image: circleci/mysql:9.4

    steps:
      - checkout
      - run:
          name: Install things we need
          command: |
            sudo apt-get update
            sudo apt-get install -y libzip-dev
            sudo apt-get install -y zlib1g-dev libicu-dev g++
            sudo apt-get install mysql-client
            sudo apt-get -y install mysql-server
      - run:
          name: Install PHP exts
          command: |
            sudo docker-php-ext-install zip
            sudo docker-php-ext-configure intl
            sudo docker-php-ext-install intl
            sudo docker-php-ext-install pdo_mysql
      - run:
          name: Fix MySQL socket config
          command: |
            sudo sh -c "echo 'pdo_mysql.default_socket=/var/run/mysqld/mysqld.sock' > /usr/local/etc/php/conf.d/pdo.ini"
      - run:
          name: Start database server
          command: |
            sudo service mysql start
            sleep 2
            ps aux | grep mysql
      - run:
          name: Create non-admin user
          command: |
            sudo mysql -u root -e "CREATE user myuser IDENTIFIED BY 'password';"

      # Download and cache dependencies
      - restore_cache:
          keys:
          - v1-dependencies-{{ checksum "composer.json" }}
          # fallback to using the latest cache if no exact match is found
          - v1-dependencies-

      - run: composer install -n --prefer-dist

      - save_cache:
          paths:
            - ./vendor
          key: v1-dependencies-{{ checksum "composer.json" }}

      # run tests!

      - run:
          name: Run tests
          command: |
            ./vendor/bin/phpunit

I may not be able to help much more today, bit pressed for time - however some quick thoughts:

  • If you want to set up a database schema, just put all your user/table/index/etc creation in a SQL script init.sql and then add a new step sudo mysql -u root < init.sql
  • Why do you need the env vars for database settings to be used? The tests surely donā€™t care what host the database is running on, right? I mean, you probably can use them (PHP can read them easily) but I wonder if you can skip some of this.
  • Will try with the file and creating the schemas.

  • I think I need those variables. During testing the application is establishing connections with 2 different databases. The names of those connections are initially set in Laravelā€™s .env file as DB_CONNECTION='connection1' DB_CONNECTION_TENANT='connection2', and then theyā€™re loaded in laravel config and read from config during testing. And that .env file is what Iā€™m trying to re-create in the CircleCI app environment settings. Not sure if thatā€™s how it worksā€¦

Env files are a non-live device to hold settings, popular to help spin up on a dev environment easily. I think itā€™s OK to use them in testing/staging as well. In fact, I would suggest an env file is a better storage of your testing variables than CircleCIā€™s web interface, which will be more fiddly (this will ensure it is ignored in live etc).

What you could do is commit these files to your repo:

ci-tests/.env
ci-tests/init.sql

You can then use the SQL file in your schema build, and the first one can be copied to the project root, where Laravel should use it automatically. Make sure all your env values are low-value (i.e. donā€™t recycle any of your live ones) for security reasons.

You can then delete any env vars from the CircleCi web interface. Thatā€™s useful for high security stuff (e.g. deployment keys) but otherwise itā€™s not as convenient as keeping your settings in a file.

I like that suggestion with the files.

In the meantime, I just now tried to create the user/database while ssh-ed, and got another error after doing so and running phpunitā€¦

Illuminate\Database\QueryException: SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is 767 bytes (SQL: alter table `users` add unique `users_email_unique`(`email`))

Could be considered a good sign since at least it has access! As I understand the error is due to a difference in the character set between mysql and mariadbā€¦ https://laravel-news.com/laravel-5-4-key-too-long-error

Should probably use mysql instead :thinking: But I actually thought that was what it installed with mysql-server. Apparently notā€¦

circleci@f99de81c03d2:~$ sudo mysql
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 203
Server version: 10.1.26-MariaDB-0+deb9u1 Debian 9.1

Copyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> SHOW VARIABLES LIKE 'version';
+---------------+--------------------------+
| Variable_name | Value                    |
+---------------+--------------------------+
| version       | 10.1.26-MariaDB-0+deb9u1 |
+---------------+--------------------------+
1 row in set (0.00 sec)

MariaDB [(none)]>

P.S Do I have to cd to my project folder when executing mysql commands or it doesnā€™t matter. :thinking:

That sounds like progress, yes!

MariaDB is/was meant to be a drop-in replacement for MySQL, and it looks like the distro youā€™re using has switched to it. So, for them, if you ask for MySQL server, you get MariaDB server :smiling_imp:. I hear itā€™s faster in some cases, so itā€™s probably a good thing in general.

You can insist on MySQL if you really want to, but your link suggests that MariaDB is acceptable to Laravel, since it only needs a small tweak.

Hi,

Cost me as well quite much time to figure it out but here:

version: 2
jobs:
    build:
        docker:
            # specify the version you desire here
            - image: circleci/php:5.6.33-apache-jessie-node-browsers
              environment:
                  # Define these information to be used later in script
                  DB_CONNECTION: mysql
                  DB_HOST: 127.0.0.1
                  DB_PORT: 3306
                  DB_DATABASE: circle_test
                  DB_USERNAME: root
                  DB_PASSWORD: enFn8dsmQBi4gkcP

            # Specify service dependencies here if necessary
            # CircleCI maintains a library of pre-built images
            # documented at https://circleci.com/docs/2.0/circleci-images/
            - image: circleci/mysql:5.6
              environment: 
                  # THESE 2 VARIABLES ARE REQUIRED!!!!
                  MYSQL_ROOT_HOST: "%"
                  MYSQL_ROOT_PASSWORD: enFn8dsmQBi4gkcP

            working_directory: ~/<YOUR_REPOSITORY>

            steps: 
                ## Checkout code from git branche and put it in folder /home/circleci/<YOUR_REPOSITORY>    
                - checkout
                ## End Checkout
  
                ## MySQL Setup      
                - run:
                    name: Install Dockerize
                    command: |
                        wget https://github.com/jwilder/dockerize/releases/download/$DOCKERIZE_VERSION/dockerize-linux-amd64-$DOCKERIZE_VERSION.tar.gz && sudo tar -C /usr/local/bin -xzvf dockerize-linux-amd64-$DOCKERIZE_VERSION.tar.gz && rm dockerize-linux-amd64-$DOCKERIZE_VERSION.tar.gz
                    environment:
                        DOCKERIZE_VERSION: v0.6.0
          
                - run:
                    name: Wait for MySQL to be ready
                    command: | 
                        dockerize -wait tcp://localhost:3306 -timeout 1m
        
                - run: 
                    name: Install MySQL client
                    command: | 
                        sudo apt install mysql-client
   
                - run:
                    name: Install Demo Database
                    command: | 
                        mysql -h$DB_HOST -u$DB_USERNAME -p$DB_PASSWORD $DB_DATABASE < <PATH TO YOUR DATABASE FILE> #Example: /home/circleci/<YOUR REPOSITORY>/<YOUR DATABASE FILE>
                ## End MySQL Setup

Hope that can help!

Hi,
Yah didnā€™t have much time yesterday.
This has been done and really hope my answer can help (took me quite 15min just to write that yml file with editor).
Maybe (not related with the topic at all), but we can improve the editor. Here is what I did so maybe you can reproduce:

  • Windows machine
  • Notepad++ (edit config.yml file)
  • copy/paste
    All the top is not properly formatted (because of 4 characters indent I guess)

To write the content properly formatted:

  • copy line by line and use space to indent properly (quite time consuming)

Anyway that is just a suggestion to make content even better as I am pretty sure CircleCI can help bring better quality in development for many companies (espacially the growing ones who would like to provide their clients better quality)

Thanks guys and great job!

2 Likes