-
Notifications
You must be signed in to change notification settings - Fork 13
/
Before You Run the Project.doc
66 lines (46 loc) · 3.22 KB
/
Before You Run the Project.doc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
Step 1: Downloading and Setting Up MySQL
You can skip this step if you already have MySQL set up on your computer.
First, we will download and set up MySQL using . Make sure to save the temporary root password they give you! Once MySQL is installed, we will set up a launch daemon that allows MySQL to start up on system/terminal launch.
After you finish installing, double check that your server is running. If not, you can turn it on through that service.msc from run.
Step 2: Finishing Up Installation
Try running mysql in terminal. You might get an error like “command not found”. If so, in terminal, configure your computer’s $PATH so it recognizes mysql as an executable:
$ export PATH=$PATH:/path/to/your/mysql/bin
Step 3: Creating MySQL Users
NOTE: in this tutorial, we are altering the root user because it is assumed you do not have any other local users on your MySQL server. If you do, change the usernames accordingly
Now we are ready to use MySQL! Enter
$ mysql -u root –p
Log in using your root password. If this is your first time logging in, use the password that you saved in step 1. Now, if you want to change the root password to something of your own preference, in the MySQL shell, enter
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'your_new_password';
Now, you have your root user set up and can log into it using your own password.
If you want to create your own user, enter
mysql> CREATE USER 'your_new_username'@'localhost' IDENTIFIED BY 'new_password';
mysql> GRANT ALL PRIVILEGES ON * . * TO 'your_new_username'@'localhost';
mysql> FLUSH PRIVILEGES;
the * . * allows the user to have all access to the databases and tables in the server. For more fine-toothed assignment of priviledges, check out the MySQL documentation.
Step 4: Creating the Project Database
In order to use MySQL with our project, we will need a Python 3 database connector library compatible with Django. So, we will install the database connector, mysqlclient.
pip install mysqlclient
Then, to create the database for your project:
mysql> CREATE DATABASE your_project_name CHARACTER SET UTF8;
mysql> GRANT ALL PRIVILEGES ON your_project_name.* TO your_username@localhost;
mysql> FLUSH PRIVILEGES;
mysql> QUIT
Step 5: Changing Django App Settings
Now, in your terminal, navigate to the root directory of your Django application.
Finally, in your settings.py file in your app, change the DATABASES section to the following:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'your_project_name',
'USER': 'root',
'PASSWORD': 'your_root_password',
'HOST': 'your_host_address',
'PORT': 'your_port',
}
}
A reminder that your_project_name should be the same name as the database you created in MySQL in Step 2. your_password is the same password that you use to log into MySQL. The HOST and PORT values can be optional if you are simply hosting your webapp locally, but if you are running MySQL in a virtual server or a separate server then fill in your host address and port accordingly.
Step 6: Make Migrations
$ python manage.py makemigrations
$ python manage.py migrate
Once done we are now connected to our mysql database;
enter : python manage.py runserver