databases.md 2.0 KB
Newer Older
1
# Setup Database
R
randx 已提交
2

3 4 5 6
GitLab supports the following databases:

* MySQL (preferred)
* PostgreSQL
R
randx 已提交
7 8 9 10


## MySQL

11
    # Install the database packages
R
randx 已提交
12 13
    sudo apt-get install -y mysql-server mysql-client libmysqlclient-dev

14 15 16
    # Install only the necessary gems
    sudo -u gitlab -H bundle install --deployment --without development test postgres 

R
randx 已提交
17 18 19
    # Login to MySQL
    $ mysql -u root -p

20 21 22
    # Create a user for GitLab. (change $password to a real password)
    mysql> CREATE USER 'gitlab'@'localhost' IDENTIFIED BY '$password';

R
randx 已提交
23 24 25
    # Create the GitLab production database
    mysql> CREATE DATABASE IF NOT EXISTS `gitlabhq_production` DEFAULT CHARACTER SET `utf8` COLLATE `utf8_unicode_ci`;

26
    # Grant the GitLab user necessary permissopns on the table.
R
randx 已提交
27 28
    mysql> GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER ON `gitlabhq_production`.* TO 'gitlab'@'localhost';

29 30 31 32 33
    # Quit the database session
    mysql> \q

    # Try connecting to the new database with the new user
    sudo -u gitlab -H mysql -u gitlab -p -D gitlabhq_production
R
randx 已提交
34 35 36

## PostgreSQL

37
    # Install the database packages
M
Mike TUMS 已提交
38
    sudo apt-get install -y postgresql-9.1 postgresql-server-dev-9.1
R
randx 已提交
39

40 41 42 43
    # Install only the necessary gems
    sudo -u gitlab -H bundle install --deployment --without development test mysql

    # Login to PostgreSQL
R
randx 已提交
44 45
    sudo -u postgres psql -d template1

46
    # Create a user for GitLab. (change $password to a real password)
R
randx 已提交
47 48
    template1=# CREATE USER gitlab WITH PASSWORD '$password';

M
Mike TUMS 已提交
49 50
    # Create the GitLab production database & grant all privileges on database
    template1=# CREATE DATABASE gitlabhq_production OWNER gitlab;
R
randx 已提交
51

52
    # Quit the database session
R
randx 已提交
53 54
    template1=# \q

55 56
    # Try connecting to the new database with the new user
    sudo -u gitlab -H psql -d gitlabhq_production
R
randx 已提交
57 58 59



60
# Configure GitLab
R
randx 已提交
61 62 63 64 65

    # Mysql
    sudo -u gitlab cp config/database.yml.mysql config/database.yml

    # PostgreSQL
66
    sudo -u gitlab cp config/database.yml.postgresql config/database.yml
R
randx 已提交
67

68
Make sure to update username/password in config/database.yml.