Skip to content

Instantly share code, notes, and snippets.

@YourFriendCaspian
Created September 2, 2017 05:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save YourFriendCaspian/0556721c395e21e169c9b51529b7d66d to your computer and use it in GitHub Desktop.
Save YourFriendCaspian/0556721c395e21e169c9b51529b7d66d to your computer and use it in GitHub Desktop.
Install Mysql with Python and Django Debian/Derivatives - Translated
#Install Mysql with Python and Django Debian/Derivatives
#To install we need to have some dependencies in the system for now we will show on
#Debian and Derivatives.
#But first install updates and MySQL
```
$ sudo apt-get update
$ sudo apt-get upgrade
```
# ** NOTE: **
#Each System has its commands for updating, if your machine is not derived from Debian ** look for them **
##Install MySQL
```
$ sudo apt-get install mysql-server mysql-client
Passwd for 'root' user: <password>
```
#At the end we execute this command to give more security to our BD
```
$ mysql_secure_installation
```
#Check carefully the changes that will be made, the first question is the passwd for root,
#IF you want to keep or change it, and continue with other security questions.
##Create a database and a user for the DB
#Now we will create the DB that will be connected to DJango and a User with Passwd to access it.
#There are two ways to do this:
```
echo "CREATE DATABASE <DATABASENAME>;" | mysql -u root -p
echo "CREATE USER '<DATABASEUSER>'@'localhost' IDENTIFIED BY '<PASSWORD>';" | mysql -u root -p
echo "GRANT ALL PRIVILEGES ON <DATABASENAME>.* TO '<DATABASEUSER>'@'localhost';" | mysql -u root -p
echo "FLUSH PRIVILEGES;" | mysql -u root -p
```
#So they should put their passwd of mysql in each line or
#they can also do it of the following way
```
$ mysql -u root -p
```
#Enter your passwd and then do the following.
```
CREATE DATABASE <DATABASENAME>;
CREATE USER '<DATABASEUSER>'@localhost IDENTIFIED BY '<PASSWORD>';
GRANT ALL PRIVILEGES ON <DATABASENAME>.* TO '<DATABASEUSER>'@localhost;
FLUSH PRIVILEGES;
exit
```
#We Check Dependencies
#There are only a few dependencies but you have to be sure
```
$ sudo apt-get install libmysqlclient-dev python-dev
```
#So far it's all just proceed to install pip in our virtual environment or globally
```
$ sudo -H pip install mysql-python
```
#As you can see now you can create DB and Users for each Django Project
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment