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
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 And itās already late.
Thank you so so much for all your help and patience!
P.S. Probably gotta add that start command as well. Or alternatively try something with the mysql image again.
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.
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
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
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
Yes, sounds like something I would never have figured out by myself! Thank you!
However, itās still not working for me. (surprise)
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:
(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)
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.
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.
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`))
Should probably use mysql instead 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.
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 . 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.
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
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)