databases.md 2.02 KB
Newer Older
1
# Setup Database
randx's avatar
randx committed
2

3 4 5 6
GitLab supports the following databases:

* MySQL (preferred)
* PostgreSQL
randx's avatar
randx committed
7 8 9 10


## MySQL

11
    # Install the database packages
randx's avatar
randx committed
12 13
    sudo apt-get install -y mysql-server mysql-client libmysqlclient-dev

14 15 16
    # Pick a database root password (can be anything), type it and press enter
    # Retype the database root password and press enter

Denix's avatar
Denix committed
17 18
    # Secure your installation.
    sudo mysql_secure_installation
19

randx's avatar
randx committed
20
    # Login to MySQL
David's avatar
David committed
21
    mysql -u root -p
randx's avatar
randx committed
22

23 24 25 26 27
    # Type the database root password

    # Create a user for GitLab
    # do not type the 'mysql>', this is part of the prompt
    # change $password in the command below to a real password you pick
28
    mysql> CREATE USER 'git'@'localhost' IDENTIFIED BY '$password';
29

randx's avatar
randx committed
30 31 32
    # Create the GitLab production database
    mysql> CREATE DATABASE IF NOT EXISTS `gitlabhq_production` DEFAULT CHARACTER SET `utf8` COLLATE `utf8_unicode_ci`;

33
    # Grant the GitLab user necessary permissions on the table.
34
    mysql> GRANT SELECT, LOCK TABLES, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER ON `gitlabhq_production`.* TO 'git'@'localhost';
randx's avatar
randx committed
35

36 37 38 39
    # Quit the database session
    mysql> \q

    # Try connecting to the new database with the new user
40
    sudo -u git -H mysql -u git -p -D gitlabhq_production
randx's avatar
randx committed
41

42 43 44 45 46 47 48 49 50 51
    # Type the password you replaced $password with earlier

    # You should now see a 'mysql>' prompt

    # Quit the database session
    mysql> \q

    # You are done installing the database and can go back to the rest of the installation.


randx's avatar
randx committed
52 53
## PostgreSQL

54
    # Install the database packages
55
    sudo apt-get install -y postgresql-9.1 postgresql-client libpq-dev
randx's avatar
randx committed
56

57
    # Login to PostgreSQL
randx's avatar
randx committed
58 59
    sudo -u postgres psql -d template1

60
    # Create a user for GitLab.
61
    template1=# CREATE USER git;
randx's avatar
randx committed
62

Mike TUMS's avatar
Mike TUMS committed
63
    # Create the GitLab production database & grant all privileges on database
Andrew Kumanyaev's avatar
Andrew Kumanyaev committed
64
    template1=# CREATE DATABASE gitlabhq_production OWNER git;
randx's avatar
randx committed
65

66
    # Quit the database session
randx's avatar
randx committed
67 68
    template1=# \q

69
    # Try connecting to the new database with the new user
70
    sudo -u git -H psql -d gitlabhq_production
randx's avatar
randx committed
71