Ive been using Django with sqlite3 on my localhost for awhile, and I understand how to use sqlite decently well (I went through as much "learn SQL the hard way" as Zed Shaw has available online. So I understand how to create a database, manipulate it with SQL code etc.
I'm trying to set up mysql to run on my localhost and then run it with django. I've tried to read as much documentation as possible but the documentations or "How to" appear different everywhere I look.
_1. I downloaded the MySQL dmg
_2. I installed both of the packages that come with it (Mac Mavericks)
_3. ...followed some different command line instructions in the documentation...
_4. Did the following on my command line:
Nicholass-MacBook-Air:~ NickStefan$ cd /usr/local/mysql
Nicholass-MacBook-Air:mysql NickStefan$ sudo ./bin/mysqld_safe
140311 18:40:06 mysqld_safe Logging to '/usr/local/mysql-5.6.16-osx10.7-x86_64/data/Nicholass-MacBook-Air.local.err'.
140311 18:40:06 mysqld_safe A mysqld process already exists
_5. So I guess that means I already got the mysql server running. However, I still don't understand how I actually use the mysql in a similar local fashion that I did with sqlite3.
_6. next I looked for _mysql:
Nicholass-MacBook-Air:mysql NickStefan$ dscl .list/Users|grep mysql
Nicholass-MacBook-Air:mysql NickStefan$ sudo dscl .
> cd Groups
/Groups > list . PrimaryGroupID
...
_mysql 74
_7. How do I create a mysql database file that I can plug into my django settings on localhost? This is what I have so far in my settings.py:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': ????????????????????,
'USER': '_mysql',
'PASSWORD': '',
'HOST': 'localhost',
'PORT': '3360',
}
}
FULL ANSWER: (so far)
edit my .bash_profile (hidden system file that affects command line start up) to have these additional lines:
alias mysql=/usr/local/mysql/bin/mysql
alias mysqladmin=/usr/local/mysql/bin/mysqladmin
enter into mysql as the root user with (enter blank at the prompting for a password):
mysql -u root -p
create a new user, create the database, grant access:
CREATE USER 'nick'@'localhost' IDENTIFIED BY 'mypass';
CREATE DATABASE mydb;
GRANT ALL ON mydb.* TO 'nick'@'localhost';
settings.py:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'mydb'),
'USER': 'nick',
'PASSWORD': 'mypass',
'HOST': 'localhost',
'PORT': '3360',
}
}
Add this to .bash_profile
export PATH=$PATH:/usr/local/mysql/bin
export DYLD_LIBRARY_PATH=/usr/local/mysql/lib:$DYLD_LIBRARY_PATH
Re-launch command line and:
pip install mysql-python
finally it worked to run:
python manage.py schemamigration myapp --initial
python manage.py syncdb
./manage.py migrate