Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
553ac33e
Commit
553ac33e
authored
Sep 14, 2020
by
Suzanne Selhorn
Committed by
Russell Dickenson
Sep 14, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Docs: Edited for style and to clarify how the variables work
parent
408a48e5
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
82 additions
and
81 deletions
+82
-81
doc/ci/services/mysql.md
doc/ci/services/mysql.md
+82
-81
No files found.
doc/ci/services/mysql.md
View file @
553ac33e
...
@@ -7,122 +7,123 @@ type: reference
...
@@ -7,122 +7,123 @@ type: reference
# Using MySQL
# Using MySQL
As many applications depend on MySQL as their database, you will eventually
Many applications depend on MySQL as their database, and you may
need it in order for your tests to run. Below you are guided how to do this
need it for your tests to run.
with the Docker and Shell executors of GitLab Runner.
## Use MySQL with the Docker executor
## Use MySQL with the Docker executor
If you are using
[
GitLab Runner
](
../runners/README.md
)
with the Docker executor
If you want to use a MySQL container, you can use
[
GitLab Runner
](
../runners/README.md
)
with the Docker executor.
you basically have everything set up already.
First, in your
`.gitlab-ci.yml`
add:
1.
[
Create variables
](
../variables/README.md#create-a-custom-variable-in-the-ui
)
for your
MySQL database and password by going to
**Settings > CI/CD**
, expanding
**Variables**
,
and clicking
**Add Variable**
.
```
yaml
This example uses
`$MYSQL_DB`
and
`$MYSQL_PASS`
as the keys.
services
:
-
mysql:latest
variables
:
1.
To specify a MySQL image, add the following to your
`.gitlab-ci.yml`
file:
# Configure mysql environment variables (https://hub.docker.com/_/mysql/)
MYSQL_DATABASE
:
"
<your_mysql_database>"
```
yaml
MYSQL_ROOT_PASSWORD
:
"
<your_mysql_password>"
services
:
```
-
mysql:latest
```
NOTE:
**Note:**
-
You can use any Docker image available on
[
Docker Hub
](
https://hub.docker.com/_/mysql/
)
.
The
`MYSQL_DATABASE`
and
`MYSQL_ROOT_PASSWORD`
variables can't be set in the GitLab UI.
For example, to use MySQL 5.5, use
`mysql:5.5`
.
To set them, assign them to a variable
[
in the UI
](
../variables/README.md#create-a-custom-variable-in-the-ui
)
,
-
The
`mysql`
image can accept environment variables. For more information, view
and then assign that variable to the
the
[
Docker Hub documentation
](
https://hub.docker.com/_/mysql/
)
.
`MYSQL_DATABASE`
and
`MYSQL_ROOT_PASSWORD`
variables in your
`.gitlab-ci.yml`
.
And then configure your application to use the database, for examp
le:
1.
To include the database name and password, add the following to your
`.gitlab-ci.yml`
fi
le:
```
yaml
```
yaml
Host
:
mysql
variables
:
User
:
root
# Configure mysql environment variables (https://hub.docker.com/_/mysql/)
Password
:
<your_mysql_password>
MYSQL_DATABASE
:
$MYSQL_DB
Database
:
<your_mysql_database>
MYSQL_ROOT_PASSWORD
:
$MYSQL_PASS
```
```
If you are wondering why we used
`mysql`
for the
`Host`
, read more at
The MySQL container uses
`MYSQL_DATABASE`
and
`MYSQL_ROOT_PASSWORD`
to connect to the database.
[
How services are linked to the job
](
../docker/using_docker_images.md#how-services-are-linked-to-the-job
)
.
Pass these values by using variables (
`$MYSQL_DB`
and
`$MYSQL_PASS`
),
[
rather than calling them directly
](
https://gitlab.com/gitlab-org/gitlab/-/issues/30178
)
.
You can also use any other Docker image available on
[
Docker Hub
](
https://hub.docker.com/_/mysql/
)
.
1.
Configure your application to use the database, for example:
For example, to use MySQL 5.5 the service becomes
`mysql:5.5`
.
The
`mysql`
image can accept some environment variables. For more details
```
yaml
check the documentation on
[
Docker Hub
](
https://hub.docker.com/_/mysql/
)
.
Host
:
mysql
User
:
runner
Password
:
<your_mysql_password>
Database
:
<your_mysql_database>
```
## Use MySQL with the Shell executor
## Use MySQL with the Shell executor
You can also use MySQL on manually
configured servers that are using
You can also use MySQL on manually
-configured servers that use
GitLab Runner with the Shell executor.
GitLab Runner with the Shell executor.
First i
nstall the MySQL server:
1.
I
nstall the MySQL server:
```
shell
```
shell
sudo
apt-get
install
-y
mysql-server mysql-client libmysqlclient-dev
sudo
apt-get
install
-y
mysql-server mysql-client libmysqlclient-dev
```
```
Pick a MySQL root password (can be anything),
and type it twice when asked.
1.
Choose a MySQL root password
and type it twice when asked.
*
Note: As a security measure you can run
`mysql_secure_installation`
to
NOTE:
**Note:**
remove anonymous users, drop the test database and disable remote logins with
As a security measure, you can run
`mysql_secure_installation`
to
the root user.
*
remove anonymous users, drop the test database, and disable remote logins by
the root user.
The next step is to create a user, so log
in to MySQL as root:
1.
Create a user by logging
in to MySQL as root:
```
shell
```
shell
mysql
-u
root
-p
mysql
-u
root
-p
```
```
Then create a user (in our case
`runner`
) which
will be used by your
1.
Create a user (in this case,
`runner`
) that
will be used by your
application. Change
`$password`
in the command below to a real
strong password.
application. Change
`$password`
in the command to a
strong password.
*Note: Do not type `mysql>`, this is part of the MySQL prompt.*
At the
`mysql>`
prompt, type:
```
shel
l
```
sq
l
mysql>
CREATE USER
'runner'
@
'localhost'
IDENTIFIED BY
'$password'
;
CREATE
USER
'runner'
@
'localhost'
IDENTIFIED
BY
'$password'
;
```
```
Create the database:
1.
Create the database:
```
shell
```
sql
mysql> CREATE DATABASE IF NOT EXISTS
`
<your_mysql_database>
`
DEFAULT CHARACTER SET
`
utf8
`
COLLATE
`
utf8_unicode_ci
`
;
CREATE
DATABASE
IF
NOT
EXISTS
`<your_mysql_database>`
DEFAULT
CHARACTER
SET
`utf8`
\
```
COLLATE
`utf8_unicode_ci`
;
```
Grant the necessary permissions on the database:
1.
Grant the necessary permissions on the database:
```
shel
l
```
sq
l
mysql>
GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, CREATE TEMPORARY TABLES, DROP, INDEX, ALTER, LOCK TABLES ON
`
<your_mysql_database>
`
.
*
TO
'runner'
@
'localhost'
;
GRANT
SELECT
,
INSERT
,
UPDATE
,
DELETE
,
CREATE
,
CREATE
TEMPORARY
TABLES
,
DROP
,
INDEX
,
ALTER
,
LOCK
TABLES
ON
`<your_mysql_database>`
.
*
TO
'runner'
@
'localhost'
;
```
```
If all went well you can now
quit the database session:
1.
If all went well, you can
quit the database session:
```
shell
```
shell
mysql>
\q
\q
```
```
Now, try to connect to the newly
created database to check that everything is
1.
Connect to the newly-
created database to check that everything is
in place:
in place:
```
shell
```
shell
mysql
-u
runner
-p
-D
<your_mysql_database>
mysql
-u
runner
-p
-D
<your_mysql_database>
```
```
As a final step, c
onfigure your application to use the database, for example:
1.
C
onfigure your application to use the database, for example:
```
shell
```
shell
Host: localhost
Host: localhost
User: runner
User: runner
Password:
$password
Password:
$password
Database: <your_mysql_database>
Database: <your_mysql_database>
```
```
## Example project
## Example project
We have set up an
[
Example MySQL Project
](
https://gitlab.com/gitlab-examples/mysql
)
for your
To view a MySQL example, create a fork of this
[
sample project
](
https://gitlab.com/gitlab-examples/mysql
)
.
convenience that runs on
[
GitLab.com
](
https://gitlab.com
)
using our publicly
This project uses publicly-available
[
shared runners
](
../runners/README.md
)
on
[
GitLab.com
](
https://gitlab.com
)
.
available
[
shared runners
](
../runners/README.md
)
.
Update the README.md file, commit your changes, and view the CI/CD pipeline to see it in action.
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 job will begin.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment