Linux 环境Django框架安装及项目创建

pip 命令安装方法

如果你还未安装 pip 工具,可查看 http://www.goonls.com/?p=1824

pip install Django -i https://pypi.tuna.tsinghua.edu.cn/simple --trusted-host pypi.tuna.tsinghua.edu.cn
[root@198e6d7f2d48 home]# django-admin startproject web
bash: django-admin: command not found

cp /usr/local/python3.8.3/bin/django-admin /usr/bin/django-admin
django-admin startproject web
python manage.py runserver

[root@198e6d7f2d48 web]# python manage.py runserver
Watching for file changes with StatReloader
Performing system checks...

System check identified no issues (0 silenced).

You have 17 unapplied migration(s). Your project may not work properly until you apply the migrations for app(s): admin, auth, contenttypes, sessions.
Run 'python manage.py migrate' to apply them.

July 15, 2020 - 03:44:52
Django version 3.0.8, using settings 'web.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.

python manage.py migrate

如何使用Docker 快速创建一个mysql服务

#拉取mysql docker 镜像 这里选择mysql5.6版本
#https://hub.docker.com/_/mysql

docker pull mysql:5.6
docker run --name some-mysql -e MYSQL_ROOT_PASSWORD=my-secret-pw -d -p 3310:3306 mysql:5.6
IP:自己服务器IP
PORT:3310
USER:root
PASS:my-secret-pw

这里some-mysql是要分配给容器的名称,my-secret-pw是要为MySQL根用户设置的密码,并且tag是指定所需MySQL版本的标记。请参阅上面的列表以获取相关标签。

我这里使用的是3310端口指向docker容器3306端口,原因:因为我的服务已经安装mysql且占用3306端口,所以新创建的数据库使用3310端口去连接

可能遇到的问题:如果你无法连接数据库,请检查服务器安全策略是否开放对应端口或服务器防火墙限制

远程连接docker的mysql容器 解决 client does not support authentication protocol 问题

进入docker容器

mysql -uroot -p
#第一步
use mysql;
#第二步
alter user 'root'@'%' identified with mysql_native_password by '46564565655';
#第三步
flush privileges;

46564565655 是自己的密码

php 测试题

<?php 
   static $num = 3;
   echo $num;exit;
   static $num=5;
?> 
<?php 
   $num = 3;
   echo $num;exit;
   static $num=5;
?> 
<?php 
function myTest(){
   static $num = 3;
   echo $num;exit;
   static $num=5;

  }
myTest();
?> 
<?php 
function myTest(){
    $num = 3;
   echo $num;exit;
   static $num=5;

  }
myTest();
?>