Multiple databases in same MySQL server

1.2k views Asked by At

I already have and database in MySQL for my one Django project. I need to make two separate Django projects share the same database.

project1/settings.py:

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'OPTIONS' : {
            'read_default_file': '/etc/mysql/my.cnf',
        },
    }
}

project1/etc/mysql/my.cnf:

!includedir /etc/mysql/conf.d/
!includedir /etc/mysql/mysql.conf.d/

[client]
database = project1
user = project_user
password = Password
port = 3307
default-character-set = utf8

Here, can I have a different database (database = project2) for my second project?

I am willing to use same user and same password.

How can I do that?

1

There are 1 answers

5
aatwork On BEST ANSWER
CREATE DATABASE project2;

You can run the above query from MySQL client console. That will create new database "project2" in MySQL.

And change the value to "database = project2" in your second project's my.cnf. That should work. You just need to have a different my.cnf file for second project. First project path is "project1/etc/mysql/my.cnf" as mentioned above. You should have something similar "project2/etc/mysql/my.cnf" as second project my.cnf path.