查看: 166|回复: 1

[Django] 初始化安装步骤

[复制链接]

415

主题

603

帖子

4607

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
4607
发表于 2017-8-2 08:40:49 | 显示全部楼层 |阅读模式
安装Django:
  1. pip install -i https://pypi.douban.com/simple/ django==1.9.8
复制代码
安装mysql:
  1. sudo apt-get install mysql-server
  2. apt-get install mysql-client
  3. sudo apt-get install libmysqlclient-dev
  4. pip install -i https://pypi.douban.com/simple/ mysql-python
复制代码
初始化数据库,修改字符编码集,查看编码集:
  1. show variables like 'char%';
复制代码
编辑如下文件:
  1. vim /etc/mysql/mysql.conf.d/mysqld.cnf
复制代码
如下图处添加如下代码:
  1. character-set-server=utf8
复制代码

2017-08-02_083630.png
然后编辑如下文件:
  1. vim /etc/mysql/conf.d/mysql.cnf
复制代码
添加如下代码:
  1. default-character-set=utf8
复制代码

2017-08-02_083726.png

然后重启mysql:
  1. service mysql restart
复制代码
创建数据库:
  1. create database mxonline;
复制代码
设置授权:
  1. grant all privileges on mxonline.* to 'mxonline'@'localhost' identified by 'aptech1!';
复制代码
  1. grant all privileges on mxonline.* to 'mxonline'@'%' identified by 'aptech1!';
复制代码
初始化django setting配置:
  1. DATABASES = {
  2.     'default': {
  3.         'ENGINE': 'django.db.backends.mysql',
  4.         'NAME': "mxonline",
  5.         'USER': "mxonline",
  6.         'PASSWORD': "aptech1!",
  7.         'HOST': "127.0.0.1"
  8.     }
  9. }
复制代码
同步django默认表:
  1. makemigrations
  2. migrate
复制代码




选一人白头,择一城终老
回复

使用道具 举报

415

主题

603

帖子

4607

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
4607
 楼主| 发表于 2017-8-2 17:04:29 | 显示全部楼层
MAC Mysql My.cnf EX:
  1. # Example MySQL config file for small systems.  
  2. #  
  3. # This is for a system with little memory (<= 64M) where MySQL is only used  
  4. # from time to time and it's important that the mysqld daemon  
  5. # doesn't use much resources.  
  6. #  
  7. # MySQL programs look for option files in a set of  
  8. # locations which depend on the deployment platform.  
  9. # You can copy this option file to one of those  
  10. # locations. For information about these locations, see:  
  11. # http://dev.mysql.com/doc/mysql/en/option-files.html  
  12. #  
  13. # In this file, you can use all long options that a program supports.  
  14. # If you want to know which options a program supports, run the program  
  15. # with the "--help" option.  

  16. # The following options will be passed to all MySQL clients  
  17. [client]  
  18. default-character-set=utf8  
  19. #password   = your_password  
  20. port        = 3306
  21. socket      = /tmp/mysql.sock  

  22. # Here follows entries for some specific programs  

  23. # The MySQL server   
  24. [mysqld]  
  25. default-storage-engine=INNODB  
  26. character-set-server=utf8
  27. collation-server=utf8_general_ci  
  28. port        = 3306
  29. socket      = /tmp/mysql.sock  
  30. skip-external-locking  
  31. key_buffer_size = 16K  
  32. max_allowed_packet = 1M  
  33. table_open_cache = 4
  34. sort_buffer_size = 64K  
  35. read_buffer_size = 256K  
  36. read_rnd_buffer_size = 256K  
  37. net_buffer_length = 2K  
  38. thread_stack = 128K  

  39. # Don't listen on a TCP/IP port at all. This can be a security enhancement,  
  40. # if all processes that need to connect to mysqld run on the same host.  
  41. # All interaction with mysqld must be made via Unix sockets or named pipes.  
  42. # Note that using this option without enabling named pipes on Windows  
  43. # (using the "enable-named-pipe" option) will render mysqld useless!  
  44. #   
  45. #skip-networking  
  46. server-id   = 1

  47. # Uncomment the following if you want to log updates  
  48. #log-bin=mysql-bin  

  49. # binary logging format - mixed recommended  
  50. #binlog_format=mixed  

  51. # Causes updates to non-transactional engines using statement format to be  
  52. # written directly to binary log. Before using this option make sure that  
  53. # there are no dependencies between transactional and non-transactional  
  54. # tables such as in the statement INSERT INTO t_myisam SELECT * FROM  
  55. # t_innodb; otherwise, slaves may diverge from the master.  
  56. #binlog_direct_non_transactional_updates=TRUE  

  57. # Uncomment the following if you are using InnoDB tables  
  58. #innodb_data_home_dir = /usr/local/mysql/data  
  59. #innodb_data_file_path = ibdata1:10M:autoextend  
  60. #innodb_log_group_home_dir = /usr/local/mysql/data  
  61. # You can set .._buffer_pool_size up to 50 - 80 %  
  62. # of RAM but beware of setting memory usage too high  
  63. #innodb_buffer_pool_size = 16M  
  64. #innodb_additional_mem_pool_size = 2M  
  65. # Set .._log_file_size to 25 % of buffer pool size  
  66. #innodb_log_file_size = 5M  
  67. #innodb_log_buffer_size = 8M  
  68. #innodb_flush_log_at_trx_commit = 1
  69. #innodb_lock_wait_timeout = 50

  70. [mysqldump]  
  71. quick  
  72. max_allowed_packet = 16M  

  73. [mysql]  
  74. no-auto-rehash  
  75. # Remove the next comment character if you are not familiar with SQL  
  76. #safe-updates  

  77. [myisamchk]  
  78. key_buffer_size = 8M  
  79. sort_buffer_size = 8M  

  80. [mysqlhotcopy]  
  81. interactive-timeout
复制代码


选一人白头,择一城终老
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 加入我们

本版积分规则

!jz_fbzt! !jz_sgzt! !jz_xgzt! 快速回复 !jz_sctz! !jz_fhlb!
快速回复 返回顶部 返回列表