title: How to setup connection to MySql database with gitlab CI/CD
body: <p>I'm trying to set up automatic testing of django project using CI/CD gitlab. The problem is, I can't connect to the Mysql database in any way.</p>
  <p><strong>gitlab-ci.yml</strong></p>
  
  <pre class="lang-yaml prettyprint-override"><code>services:
    - mysql:5.7
  
  variables:
        MYSQL_DATABASE: &quot;db_name&quot;
        MYSQL_ROOT_PASSWORD: &quot;dbpass&quot;
        MYSQL_USER: &quot;username&quot;
        MYSQL_PASSWORD: &quot;dbpass&quot;
        
  
  stages:
    - test
  
  test:
    stage: test
    before_script:
    - apt update -qy &amp;&amp; apt-get install -qqy --no-install-recommends default-mysql-client
    - mysql --user=$MYSQL_USER --password=$MYSQL_PASSWORD --database=$MYSQL_DATABASE --host=$MYSQL_HOST --execute=&quot;SHOW DATABASES; ALTER USER '$MYSQL_USER'@'%' IDENTIFIED WITH mysql_native_password BY '$MYSQL_PASSWORD'&quot;
    script:
    - apt update -qy
    - apt install python3 python3-pip virtualenvwrapper -qy
    - virtualenv --python=python3 venv/
    - source venv/bin/activate
    - pwd
    - pip install -r requirement.txt
    - python manage.py test apps
  </code></pre>
  <p>With this file configuration, I get  error</p>
  
  <pre class="lang-none prettyprint-override"><code> ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
  </code></pre>
  <p>What have I tried to do</p>
  <p>add to  <code>mysql</code> script tcp connection unstead socket</p>
  
  <pre class="lang-bash prettyprint-override"><code>mysql --protocol=TCP --user=$MYSQL_USER --password=$MYSQL_PASSWORD --database=$MYSQL_DATABASE --host=$MYSQL_HOST --execute=&quot;SHOW DATABASES; ALTER USER '$MYSQL_USER'@'%' IDENTIFIED WITH mysql_native_password BY '$MYSQL_PASSWORD'&quot;
  </code></pre>
  <p>And in this case I got</p>
  
  <pre class="lang-none prettyprint-override"><code>ERROR 2002 (HY000): Can't connect to MySQL server on 'localhost' (99)
  </code></pre>
  <p>How do I set up properly?</p>