I would like to start using Django with MYSQL, instead of sqlite all the time, however my only experience using MSQL is through XAMPP, manipulating databases through phpmyadmin. I would really like to keep this gui interaction with mysql and not have to do everything through command line.
Can you start and manage a MYSQL database using xampp/phpmyadmin, and then use django for the web development side only using Django'sn development server?
Or do you have to always start new databases through command line, and if so how is it done, bearing in mind I only ever use mysql through xampp/phpmyadmin?
I know how to link and manage a database through django, I just dont know how to start a mysql one through it, and I dont really want to have to loose the mysql gui that comes with xampp/phpmyadmin. all help is greatly appreciated.
By default, Django provides database access to sqlite3. Here we are going to connect Mysql database with Django. We need to install XAMPP server to handle this process.
phpMyAdmin is a free software tool written in PHP that is intended to handle the administration of a MySQL or MariaDB database server. You can use phpMyAdmin to perform most administration tasks, including creating a database, running queries, and adding user accounts.
Django officially supports the following databases: PostgreSQL. MariaDB. MySQL.
What is the difference between PHPMyAdmin and MySQL? MySQL is the database management system, or a database server. phpMyAdmin is the web application written primarily in PHP. It's used for managing MySQL database.
You can definitely manage Mysql through the XAMPP interface. Try setting the DB_HOST in settings.py to "localhost". If it doesn't work, try "127.0.0.1". This is typically caused by the python-mysql module expecting the mysql unix socket to be in another place than it is. Actually, I'm unsure if the mysql server uses a unix socket on Windows. Anyway, one of both should work :) You can use the credentials you use to login with phpmyAdmin also for Django. Many consider it bad style to use root for non-administration tasks (and I agree), but for starters and on your development machine it isn't too big of an issue. phpMyAdmin should work out of the box with your django-managed databases.
My database settings.py block for mysql looks something like this:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql', # Add 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
'NAME': 'DBNAME', # Or path to database file if using sqlite3.
'USER': 'USER', # Not used with sqlite3.
'PASSWORD': 'PASSWORD', # Not used with sqlite3.
'HOST': '', # Set to empty string for localhost. Not used with sqlite3.
'PORT': '', # Set to empty string for default. Not used with sqlite3.
}
}
This is for django 1.2 and above. Replace DBNAME, USER and PASSWORD with the respective values and try '127.0.0.1' as HOST if you run into problems. Obviously, you'd need to run 'manage.py syncdb' as you did with sqlite before you can use it.
I'd highly recommend checking out postgresql! It comes with a Sqlserver-Management-System-like Database Browser that runs on your desktop, rather than a web based front end. Now you don't need to worry about configuring PHP alongside Django. Postgresql will probably be harder to install than MySql on XAMPP, but I believe that you can get a lot out of doing so.
Postgresql is also a lot better (IMO) than MySQL, and is the recommended database to use with Django according to a lot of the people close to Django.
That said, I currently use Oracle, so you probably shouldn't listen to me. :)
You can easily manage your databases with phpMyAdmin. All what Django needs is permission and access information for your database. Once those are set up (granting permissions in phpMyAdmin and adding the access information in Django's settings.py), you would issue a manage.py syncdb
for example and you're done.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With