Commit 47e81da8 authored by Achilleas Pipinellis's avatar Achilleas Pipinellis

Clean up mysql CI example

parent 06b86de9
## Using MySQL # Using MySQL
It's possible to use MySQL database test your apps during builds. As many applications depend on MySQL as their database, you will eventually
need it in order for your tests to run. Below you are guided how to do this
with the Docker and Shell executors of GitLab Runner.
### Use MySQL with Docker executor ## Use MySQL with the Docker executor
If you are using our Docker integration you basically have everything already. If you are using [GitLab Runner](../runners/README.md) with the Docker executor
you basically have everything set up already.
1. Add this to your `.gitlab-ci.yml`: First, in your `.gitlab-ci.yml` add:
services: ```yaml
- mysql services:
- mysql
variables: variables:
# Configure mysql service (https://hub.docker.com/_/mysql/) # Configure mysql environment variables (https://hub.docker.com/_/mysql/)
MYSQL_DATABASE: hello_world_test MYSQL_DATABASE: el_duderino
MYSQL_ROOT_PASSWORD: mysql MYSQL_ROOT_PASSWORD: mysql_strong_password
```
2. Configure your application to use the database: And then configure your application to use the database, for example:
Host: mysql ```yaml
User: root Host: localhost
Password: mysql User: root
Database: hello_world_test Password: mysql_strong_password
Database: el_duderino
```
3. You can also use any other available on [DockerHub](https://hub.docker.com/_/mysql/). For example: `mysql:5.5`. You can also use any other docker image available on [Docker Hub][hub-mysql].
For example, to use MySQL 5.5 the service becomes `mysql:5.5`.
Example: https://gitlab.com/gitlab-examples/mysql/blob/master/.gitlab-ci.yml The `mysql` image can accept some environment variables. For more details
check the documentation on [Docker Hub][hub-mysql].
### Use MySQL with Shell executor ## Use MySQL with the Shell executor
It's possible to use MySQL on manually configured servers that are using GitLab Runner with Shell executor. You can also use MySQL on manually configured servers that are using
GitLab Runner with the Shell executor.
1. First install the MySQL server: First install the MySQL server:
sudo apt-get install -y mysql-server mysql-client libmysqlclient-dev
# Pick a MySQL root password (can be anything), type it and press enter ```bash
# Retype the MySQL root password and press enter sudo apt-get install -y mysql-server mysql-client libmysqlclient-dev
```
2. Create an user: Pick a MySQL root password (can be anything), and type it twice when asked.
mysql -u root -p *Note: As a security measure you can run `mysql_secure_installation` to
remove anonymous users, drop the test database and disable remote logins with
the root user.*
# Create a user which will be used by your apps The next step is to create a user, so login to MySQL as root:
# do not type the 'mysql>', this is part of the prompt
# change $password in the command below to a real password you pick
mysql> CREATE USER 'runner'@'localhost' IDENTIFIED BY '$password';
# Ensure you can use the InnoDB engine which is necessary to support long indexes ```bash
# If this fails, check your MySQL config files (e.g. `/etc/mysql/*.cnf`, `/etc/mysql/conf.d/*`) for the setting "innodb = off" mysql -u root -p
mysql> SET storage_engine=INNODB; ```
# Create the database Then create a user (in our case `runner`) which will be used by your
mysql> CREATE DATABASE IF NOT EXISTS `hello_world_test` DEFAULT CHARACTER SET `utf8` COLLATE `utf8_unicode_ci`; application. Change `$password` in the command below to a real strong password.
# Grant necessary permissions on the database *Note: Do not type `mysql>`, this is part of the MySQL prompt.*
mysql> GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, CREATE TEMPORARY TABLES, DROP, INDEX, ALTER, LOCK TABLES ON `hello_world_test`.* TO 'runner'@'localhost';
# Quit the database session ```bash
mysql> \q mysql> CREATE USER 'runner'@'localhost' IDENTIFIED BY '$password';
```
3. Try to connect to database: Create the database:
sudo -u gitlab-runner -H mysql -u runner -p -D hello_world_test ```bash
mysql> CREATE DATABASE IF NOT EXISTS `el_duderino` DEFAULT CHARACTER SET `utf8` COLLATE `utf8_unicode_ci`;
```
4. Configure your application to use the database: Grant the necessary permissions on the database:
Host: localhost ```bash
User: runner mysql> GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, CREATE TEMPORARY TABLES, DROP, INDEX, ALTER, LOCK TABLES ON `el_duderino`.* TO 'runner'@'localhost';
Password: $password ```
Database: hello_world_test
If all went well you can now quit the database session:
```bash
mysql> \q
```
Now, try to connect to the newly created database to check that everything is
in place:
```bash
mysql -u runner -p -D el_duderino
```
As a final step, configure your application to use the database, for example:
```bash
Host: localhost
User: runner
Password: $password
Database: el_duderino
```
## Example project
We have set up an [Example MySQL Project][mysql-example-repo] for your
convenience that runs on [GitLab.com](https://gitlab.com) using our publicly
available [shared runners](../runners/README.md).
Want to hack on it? Simply fork it, commit and push your changes. Within a few
moments the changes will be picked by a public runner and the build will begin.
[hub-mysql]: https://hub.docker.com/_/mysql/
[mysql-example-repo]: https://gitlab.com/gitlab-examples/mysql
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment