8000 update Readme.md, change to use Mysql database · python012/guest@9d71a94 · GitHub
[go: up one dir, main page]

Skip to content

Commit 9d71a94

Browse files
committed
update Readme.md, change to use Mysql database
1 parent 4920135 commit 9d71a94

File tree

4 files changed

+31
-4
lines changed

4 files changed

+31
-4
lines changed

README.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,16 @@ Installed apps:
99
Commands:
1010

1111
- `python3 manage.py runserver` or `python3 manage.py runserver 127.0.0.1:8001` to launch the site.
12-
- `python3 manage.py shell` to enable Django shell console
12+
- `python3 manage.py shell` to enable Django shell console
13+
14+
How to install mysql in Ubuntu 16.04 and enable remote-access:
15+
16+
1. `sudo apt-get install mysql-server`, `sudo apt isntall mysql-client`, `sudo apt install libmysqlclient-dev`.
17+
2. Use `sudo netstat -tap | grep mysql` to check whether mysql is running, open mysql console using `mysql -uroot -p`.
18+
3. To enable remote-access, `sudo vi /etc/mysql/mysql.conf.d/mysqld.cnf` and comment the line of `bind-address = 127.0.0.1`.
19+
4. Open mysql console again, execute `grant all on *.* to root@'%' identified by 'ROOT-PASSWORD' with grant option;` and `flush privileges;`.
20+
5. Quit mysql console and restart mysql service by `service mysql restart`.
21+
22+
Setup:
23+
24+
- Mysql service is required, IP address, user name and password need be configured in guest/settings.py as part of DATABASES configuraiton.

guest/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import pymysql
2+
3+
4+
pymysql.install_as_MySQLdb()

guest/settings.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,18 @@
7676

7777
DATABASES = {
7878
'default': {
79-
'ENGINE': 'django.db.backends.sqlite3',
80-
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
79+
# 'ENGINE': 'django.db.backends.sqlite3',
80+
# 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
81+
'ENGINE': 'django.db.backends.mysql',
82+
'HOST': '', # not set for secruity reason
83+
'PORT': '3306',
84+
'NAME': 'guest',
85+
'USER': '', # not set for secruity reason
86+
'PASSWORD': '', # not set for secruity reason
87+
'OPTIONS': {
88+
'init_command': "SET sql_mode='STRICT_TRANS_TABLES'",
89+
},
90+
8191
}
8292
}
8393

requirements.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
django==1.10.3
1+
django==1.10.3
2+
pymysql==0.8.1

0 commit comments

Comments
 (0)
0