- 一、Ubuntu服务器版下载
- 二、制作启动U盘,RAW写入
- 三、笔记本真机安装Ubuntu20.04服务器版
- 3.1 设置笔记本U盘启动,插入启动U盘
- 3.2 检查安装文件完整性,需要一两分钟
- 3.3 选择语言
- 3.4 确认语言和布局
- 3.5 确认网络连接
- 3.6 输入代理地址,默认空着就行
- 3.7 确认服务器地址,默认就行
- 3.8 设置磁盘,默认就行
- 3.9 再次确认磁盘分区,默认就行
- 3.10 输入用户名、电脑名和密码
- 3.11 安装OpenSSH服务器
- 3.12 其他功能软件列表,都不选
- 3.13 正在安装
- 3.14 安装完成,重启
- 3.15 输入用户名,密码
- 3.16 启动成功
- 四、SecureCRT远程操作服务器
- 4.1 启动远程工具SecureCRT
- 4.2 新建连接
- 4.3 确认连接
- 4.4 输入用户名密码
- 4.5 连接失败
- 4.6 重新新建一个连接,不输主机名,直接输入用户名即可
- 4.7 以后都是通过SecureCRT远程操作服务器
- 五、安装net-tools
- 5.1 执行 ifconfig -a 出错,提示安装net-tools
- 5.2 执行:sudo apt install net-tools,输入密码
- 5.3 再次执行 ifconfig -a 成功
- 六、更新Ubuntu服务器版
- 6.1 查看可更新内容
- 6.2 更新源
- 6.3 安装源
- 七、安装Mysql8
- 7.1 添加MySQL Apt存储库
- 7.1.1 wget 下载存储库软件包
- 7.1.2 dpkg 命令安装下载好的 MySQL 存储库软件包
- 7.2 安装MySQL 8服务器
- 7.2.1 从所有已配置的存储库(包括新添加的 MySQL 8存储库)中下载最新的软件包信息
- 7.2.2 安装 MySQL 8 社区服务器、客户端和数据库公用文件
- 7.3 运行安全的 MySQL 8.0服务器
- 7.4 通过Systemd管理MySQL 8
- 八、远程连接Mysql8
- 8.1 mysql -u root -p 输入密码
- 8.2 查看数据库
- 8.3 使用mysql库
- 8.4 查看mysql的数据表
- 8.5 查看user表的信息
- 8.6 创建用户
- 8.7 新用户授权
- 8.8 刷新权限
- 8.9 修改远程连接用户的加密规则
- 8.10 查看新增用户
- 8.11 退出后使用新用户登录成功
- 8.12 Navicat root用户无法登录
- 8.13 Navicat 新建用户登录成功
- 九、Django的SQLite数据库导入MySQL
- 9.1 失败的历程
- 9.1.1 确认Django项目settings.py中的数据库连接
- 9.1.2 虚拟环境中导出json数据
- 9.1.3 Django的数据库配置改为MySQL
- 9.1.4 安装pymysql模块
- 9.1.5 修改settings.py同目录下的__init__.py
- 9.1.6 修改 query = query.decode(errors='replace')
- 9.1.7 stream_or_string = stream_or_string.decode()
- 9.1.8 json数据导入MySQL8
- 依然不成功哦!!! 总之是没有成功!!!
- 9.2 成功的方法
- 9.2.1 Navicat for SQLite导出
- 9.2.2 Navicat for MySQL创建数据库hos
- 9.2.3 Navicat for MySQL导入
- 9.2.4 修改Django默认数据库连接
- 9.2.5 修改MIS默认数据库连接
- 十、迁移方法二
- 10.1 删除原有迁移文件
- 10.2 进入虚拟环境
- 10.3 python manage.py makemigrations
- 10.4 python manage.py migrate
- 10.5 Navicat导入向导逐个导入
视频讲解:
【Python百日基础系列】Ubuntu20+Mysql8
一、Ubuntu服务器版下载-
官网下载:https://ubuntu.com/download/server
-
阿里云下载:http://pub.mirrors.aliyun.com/ubuntu-releases/20.04/
因为是笔记本真机安装,没法截图,所以这部分图片都是手机拍摄笔记本屏幕,效果可能差点,请理解。
3.1 设置笔记本U盘启动,插入启动U盘回车继续
原因是新建连接时输入了主机名,但是确认密码时改成了用户名
顺便改个黑白主题,是不是更有服务器味?
apt list --upgradable
sudo apt-get update
sudo apt-get upgrade
七、安装Mysql8 7.1 添加MySQL Apt存储库目前已经有了现成可用于安装 MySQL Server、客户端和其它组件的 APT 存储库,我们需要先将 MySQL 存储库添加到 Ubuntu 的软件包源列表中:
7.1.1 wget 下载存储库软件包wget -c https://dev.mysql.com/get/mysql-apt-config_0.8.20-1_all.deb
sudo dpkg -i mysql-apt-config_0.8.20-1_all.deb
在软件包安装过程中,系统会提示您选择 MySQL 服务器版本和其他组件,例如群集、共享客户端库或配置要安装 MySQL 的工作台。
默认 MySQL 服务器版本 mysql-8.0 的源将被自动选中,我们只需最终确定就可以完成发行包的配置和安装。
选定OK后
sudo apt update
sudo apt-get install mysql-server
提示为Mysql数据库的root用户设置一个强壮的密码
确认密码
MySQL 服务器认证插件的配置,推荐使用默认的强密码保护策略
@:~$ sudo apt-get install mysql-server Reading package lists... Done Building dependency tree Reading state information... Done The following additional packages will be installed: libmecab2 mecab-ipadic mecab-ipadic-utf8 mecab-utils mysql-client mysql-common mysql-community-client mysql-community-client-core mysql-community-client-plugins mysql-community-server mysql-community-server-core The following NEW packages will be installed: libmecab2 mecab-ipadic mecab-ipadic-utf8 mecab-utils mysql-client mysql-common mysql-community-client mysql-community-client-core mysql-community-client-plugins mysql-community-server mysql-community-server-core mysql-server 0 upgraded, 12 newly installed, 0 to remove and 0 not upgraded. Need to get 34.1 MB of archives. After this operation, 285 MB of additional disk space will be used. Do you want to continue? [Y/n] y Get:1 http://repo.mysql.com/apt/ubuntu focal/mysql-8.0 amd64 mysql-common amd64 8.0.27-1ubuntu20.04 [68.7 kB] Get:2 http://cn.archive.ubuntu.com/ubuntu focal/main amd64 libmecab2 amd64 0.996-10build1 [233 kB] Get:3 http://repo.mysql.com/apt/ubuntu focal/mysql-8.0 amd64 mysql-community-client-plugins amd64 8.0.27-1ubuntu20.04 [1,226 kB] Get:4 http://repo.mysql.com/apt/ubuntu focal/mysql-8.0 amd64 mysql-community-client-core amd64 8.0.27-1ubuntu20.04 [1,779 kB] Get:5 http://repo.mysql.com/apt/ubuntu focal/mysql-8.0 amd64 mysql-community-client amd64 8.0.27-1ubuntu20.04 [2,932 kB] Get:6 http://cn.archive.ubuntu.com/ubuntu focal/main amd64 mecab-utils amd64 0.996-10build1 [4,912 B] Get:7 http://cn.archive.ubuntu.com/ubuntu focal/main amd64 mecab-ipadic all 2.7.0-20070801+main-2.1 [6,714 kB] Get:8 http://repo.mysql.com/apt/ubuntu focal/mysql-8.0 amd64 mysql-client amd64 8.0.27-1ubuntu20.04 [65.0 kB] Get:9 http://repo.mysql.com/apt/ubuntu focal/mysql-8.0 amd64 mysql-community-server-core amd64 8.0.27-1ubuntu20.04 [20.9 MB] Get:10 http://cn.archive.ubuntu.com/ubuntu focal/main amd64 mecab-ipadic-utf8 all 2.7.0-20070801+main-2.1 [4,380 B] Get:11 http://repo.mysql.com/apt/ubuntu focal/mysql-8.0 amd64 mysql-community-server amd64 8.0.27-1ubuntu20.04 [76.2 kB] Get:12 http://repo.mysql.com/apt/ubuntu focal/mysql-8.0 amd64 mysql-server amd64 8.0.27-1ubuntu20.04 [65.0 kB] Fetched 34.1 MB in 17s (2,024 kB/s) Preconfiguring packages ... electing previously unselected package mysql-common. (Reading database ... 71678 files and directories currently installed.) Preparing to unpack .../00-mysql-common_8.0.27-1ubuntu20.04_amd64.deb ... Unpacking mysql-common (8.0.27-1ubuntu20.04) ... Selecting previously unselected package mysql-community-client-plugins. Preparing to unpack .../01-mysql-community-client-plugins_8.0.27-1ubuntu20.04_amd64.deb ... Unpacking mysql-community-client-plugins (8.0.27-1ubuntu20.04) ... Selecting previously unselected package mysql-community-client-core. Preparing to unpack .../02-mysql-community-client-core_8.0.27-1ubuntu20.04_amd64.deb ... Unpacking mysql-community-client-core (8.0.27-1ubuntu20.04) ... Selecting previously unselected package mysql-community-client. Preparing to unpack .../03-mysql-community-client_8.0.27-1ubuntu20.04_amd64.deb ... Unpacking mysql-community-client (8.0.27-1ubuntu20.04) ... Selecting previously unselected package mysql-client. Preparing to unpack .../04-mysql-client_8.0.27-1ubuntu20.04_amd64.deb ... Unpacking mysql-client (8.0.27-1ubuntu20.04) ... Selecting previously unselected package libmecab2:amd64. Preparing to unpack .../05-libmecab2_0.996-10build1_amd64.deb ... Unpacking libmecab2:amd64 (0.996-10build1) ... Selecting previously unselected package mysql-community-server-core. Preparing to unpack .../06-mysql-community-server-core_8.0.27-1ubuntu20.04_amd64.deb ... Unpacking mysql-community-server-core (8.0.27-1ubuntu20.04) ... Selecting previously unselected package mysql-community-server. Preparing to unpack .../07-mysql-community-server_8.0.27-1ubuntu20.04_amd64.deb ... Unpacking mysql-community-server (8.0.27-1ubuntu20.04) ... Selecting previously unselected package mecab-utils. Preparing to unpack .../08-mecab-utils_0.996-10build1_amd64.deb ... Unpacking mecab-utils (0.996-10build1) ... Selecting previously unselected package mecab-ipadic. Preparing to unpack .../09-mecab-ipadic_2.7.0-20070801+main-2.1_all.deb ... Unpacking mecab-ipadic (2.7.0-20070801+main-2.1) ... Selecting previously unselected package mecab-ipadic-utf8. Preparing to unpack .../10-mecab-ipadic-utf8_2.7.0-20070801+main-2.1_all.deb ... Unpacking mecab-ipadic-utf8 (2.7.0-20070801+main-2.1) ... Selecting previously unselected package mysql-server. Preparing to unpack .../11-mysql-server_8.0.27-1ubuntu20.04_amd64.deb ... Unpacking mysql-server (8.0.27-1ubuntu20.04) ... Setting up libmecab2:amd64 (0.996-10build1) ... Setting up mysql-common (8.0.27-1ubuntu20.04) ... update-alternatives: using /etc/mysql/my.cnf.fallback to provide /etc/mysql/my.cnf (my.cnf) in auto mode Setting up mysql-community-server-core (8.0.27-1ubuntu20.04) ... Setting up mecab-utils (0.996-10build1) ... Setting up mysql-community-client-plugins (8.0.27-1ubuntu20.04) ... Setting up mecab-ipadic (2.7.0-20070801+main-2.1) ... Compiling IPA dictionary for Mecab. This takes long time... reading /usr/share/mecab/dic/ipadic/unk.def ... 40 emitting double-array: 100% |###########################################| /usr/share/mecab/dic/ipadic/model.def is not found. skipped. reading /usr/share/mecab/dic/ipadic/Adj.csv ... 27210 reading /usr/share/mecab/dic/ipadic/Noun.adjv.csv ... 3328 reading /usr/share/mecab/dic/ipadic/Postp.csv ... 146 reading /usr/share/mecab/dic/ipadic/Noun.proper.csv ... 27328 reading /usr/share/mecab/dic/ipadic/Auxil.csv ... 199 reading /usr/share/mecab/dic/ipadic/Postp-col.csv ... 91 reading /usr/share/mecab/dic/ipadic/Symbol.csv ... 208 reading /usr/share/mecab/dic/ipadic/Filler.csv ... 19 reading /usr/share/mecab/dic/ipadic/Verb.csv ... 130750 reading /usr/share/mecab/dic/ipadic/Noun.name.csv ... 34202 reading /usr/share/mecab/dic/ipadic/Adverb.csv ... 3032 reading /usr/share/mecab/dic/ipadic/Noun.org.csv ... 16668 reading /usr/share/mecab/dic/ipadic/Prefix.csv ... 221 reading /usr/share/mecab/dic/ipadic/Adnominal.csv ... 135 reading /usr/share/mecab/dic/ipadic/Noun.number.csv ... 42 reading /usr/share/mecab/dic/ipadic/Noun.adverbal.csv ... 795 reading /usr/share/mecab/dic/ipadic/Interjection.csv ... 252 reading /usr/share/mecab/dic/ipadic/Noun.verbal.csv ... 12146 reading /usr/share/mecab/dic/ipadic/Noun.place.csv ... 72999 reading /usr/share/mecab/dic/ipadic/Suffix.csv ... 1393 reading /usr/share/mecab/dic/ipadic/Noun.csv ... 60477 reading /usr/share/mecab/dic/ipadic/Others.csv ... 2 reading /usr/share/mecab/dic/ipadic/Noun.demonst.csv ... 120 reading /usr/share/mecab/dic/ipadic/Noun.others.csv ... 151 reading /usr/share/mecab/dic/ipadic/Noun.nai.csv ... 42 reading /usr/share/mecab/dic/ipadic/Conjunction.csv ... 171 emitting double-array: 100% |###########################################| reading /usr/share/mecab/dic/ipadic/matrix.def ... 1316x1316 emitting matrix : 100% |###########################################| done! update-alternatives: using /var/lib/mecab/dic/ipadic to provide /var/lib/mecab/dic/debian (mecab-dictionary) in auto mode Setting up mysql-community-client-core (8.0.27-1ubuntu20.04) ... Setting up mecab-ipadic-utf8 (2.7.0-20070801+main-2.1) ... Compiling IPA dictionary for Mecab. This takes long time... reading /usr/share/mecab/dic/ipadic/unk.def ... 40 emitting double-array: 100% |###########################################| /usr/share/mecab/dic/ipadic/model.def is not found. skipped. reading /usr/share/mecab/dic/ipadic/Adj.csv ... 27210 reading /usr/share/mecab/dic/ipadic/Noun.adjv.csv ... 3328 reading /usr/share/mecab/dic/ipadic/Postp.csv ... 146 reading /usr/share/mecab/dic/ipadic/Noun.proper.csv ... 27328 reading /usr/share/mecab/dic/ipadic/Auxil.csv ... 199 reading /usr/share/mecab/dic/ipadic/Postp-col.csv ... 91 reading /usr/share/mecab/dic/ipadic/Symbol.csv ... 208 reading /usr/share/mecab/dic/ipadic/Filler.csv ... 19 reading /usr/share/mecab/dic/ipadic/Verb.csv ... 130750 reading /usr/share/mecab/dic/ipadic/Noun.name.csv ... 34202 reading /usr/share/mecab/dic/ipadic/Adverb.csv ... 3032 reading /usr/share/mecab/dic/ipadic/Noun.org.csv ... 16668 reading /usr/share/mecab/dic/ipadic/Prefix.csv ... 221 reading /usr/share/mecab/dic/ipadic/Adnominal.csv ... 135 reading /usr/share/mecab/dic/ipadic/Noun.number.csv ... 42 reading /usr/share/mecab/dic/ipadic/Noun.adverbal.csv ... 795 reading /usr/share/mecab/dic/ipadic/Interjection.csv ... 252 reading /usr/share/mecab/dic/ipadic/Noun.verbal.csv ... 12146 reading /usr/share/mecab/dic/ipadic/Noun.place.csv ... 72999 reading /usr/share/mecab/dic/ipadic/Suffix.csv ... 1393 reading /usr/share/mecab/dic/ipadic/Noun.csv ... 60477 reading /usr/share/mecab/dic/ipadic/Others.csv ... 2 reading /usr/share/mecab/dic/ipadic/Noun.demonst.csv ... 120 reading /usr/share/mecab/dic/ipadic/Noun.others.csv ... 151 reading /usr/share/mecab/dic/ipadic/Noun.nai.csv ... 42 reading /usr/share/mecab/dic/ipadic/Conjunction.csv ... 171 emitting double-array: 100% |###########################################| reading /usr/share/mecab/dic/ipadic/matrix.def ... 1316x1316 emitting matrix : 100% |###########################################| done! update-alternatives: using /var/lib/mecab/dic/ipadic-utf8 to provide /var/lib/mecab/dic/debian (mecab-dictionary) in auto mode Setting up mysql-community-client (8.0.27-1ubuntu20.04) ... Setting up mysql-client (8.0.27-1ubuntu20.04) ... Setting up mysql-community-server (8.0.27-1ubuntu20.04) ... update-alternatives: using /etc/mysql/mysql.cnf to provide /etc/mysql/my.cnf (my.cnf) in auto mode Created symlink /etc/systemd/system/multi-user.target.wants/mysql.service → /lib/systemd/system/mysql.service. Setting up mysql-server (8.0.27-1ubuntu20.04) ... Processing triggers for man-db (2.9.1-1) ... Processing triggers for libc-bin (2.31-0ubuntu9.2) ...7.3 运行安全的 MySQL 8.0服务器
默认安装的 MySQL 服务器都是不太安全的,为了提供基本的安全保障,请运行二进制安装包中附带的安全脚本进行一些基本配置。(执行脚本时需要验证安装过程中已配置的 root 密码,然后选择是否使用 VALIDATE PASSWORD 插件。)
脚本执行后可以更改之前设置的 root 密码,然后执行 y 来解决如下安全问题:
Remove anonymous users? : y(删除匿名用户)
Disallow root login remotely?: y(禁止root远程登录)
Remove test database and access to it? : y(删除测试数据库)
Reload privilege tables now? : y(立即重新加载特权表)
sudo mysql_secure_installation
@:~$ sudo mysql_secure_installation Securing the MySQL server deployment. Enter password for user root: VALIDATE PASSWORD COMPonENT can be used to test passwords and improve security. It checks the strength of password and allows the users to set only those passwords which are secure enough. Would you like to setup VALIDATE PASSWORD component? Press y|Y for Yes, any other key for No: y There are three levels of password validation policy: LOW Length >= 8 MEDIUM Length >= 8, numeric, mixed case, and special characters STRONG Length >= 8, numeric, mixed case, special characters and dictionary file Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: Using existing password for root. Estimated strength of the password: 50 Change the password for root ? ((Press y|Y for Yes, any other key for No) : ... skipping. By default, a MySQL installation has an anonymous user, allowing anyone to log into MySQL without having to have a user account created for them. This is intended only for testing, and to make the installation go a bit smoother. You should remove them before moving into a production environment. Remove anonymous users? (Press y|Y for Yes, any other key for No) : y Success. Normally, root should only be allowed to connect from 'localhost'. This ensures that someone cannot guess at the root password from the network. Disallow root login remotely? (Press y|Y for Yes, any other key for No) : y Success. By default, MySQL comes with a database named 'test' that anyone can access. This is also intended only for testing, and should be removed before moving into a production environment. Remove test database and access to it? (Press y|Y for Yes, any other key for No) : y - Dropping test database... Success. - Removing privileges on test database... Success. Reloading the privilege tables will ensure that all changes made so far will take effect immediately. Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y Success. All done!7.4 通过Systemd管理MySQL 8
在 Ubuntu 系统中,通常安装好的服务都是被配置为自动启动的,您可以使用如下命令检查 MySQL 服务器是否已启动并正在运行。
sudo systemctl status mysql
如果没有自动启动,可以用如下命令手动启用并将 MySQL 8 配置为随系统启动时启动:
sudo systemctl status mysql sudo systemctl enable mysql八、远程连接Mysql8 8.1 mysql -u root -p 输入密码 8.2 查看数据库
show databases;8.3 使用mysql库
use mysql;8.4 查看mysql的数据表
show tables;8.5 查看user表的信息
select host, user, authentication_string, plugin from user;8.6 创建用户
create user username@'%' identified by 'password';8.7 新用户授权
grant all privileges on *.* to username@'%' with grant option;8.8 刷新权限
flush privileges;8.9 修改远程连接用户的加密规则
ALTER USER 'username'@'%' IDENTIFIED WITH mysql_native_password BY 'password';8.10 查看新增用户
select host, user, authentication_string, plugin from user;8.11 退出后使用新用户登录成功 8.12 Navicat root用户无法登录 8.13 Navicat 新建用户登录成功 九、Django的SQLite数据库导入MySQL 9.1 失败的历程 9.1.1 确认Django项目settings.py中的数据库连接
DATAbaseS = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(base_DIR, 'db.sqlite3'),
}
}
9.1.2 虚拟环境中导出json数据
python manage.py dumpdata > data.json
DATAbaseS = {
'default': {
'ENGINE': 'django.db.backends.mysql', # mysql 驱动
'NAME': '', # 数据库名
'USER': '', # 用户名
'PASSWORD': '', # 密码
'HOST': '', # 访问的地址(localhost|127.0.0.1|'') 都代表本机
'PORT': '3306', # 端口号 mysql默认端口是3306
}
}
9.1.4 安装pymysql模块
pip install pymysql -i https://mirror.baidu.com/pypi/simple9.1.5 修改settings.py同目录下的__init__.py
import pymysql pymysql.install_as_MySQLdb()9.1.6 修改 query = query.decode(errors=‘replace’)
E:salary_envlibsite-packagesdjangodbbackendsmysqloperations.py
第146行,decode改为encode
E:salary_envlibsite-packagesdjangocoreserializersjson.py
第66行,decode改为encode
python manage.py loaddata data.json依然不成功哦!!! 总之是没有成功!!! 9.2 成功的方法 9.2.1 Navicat for SQLite导出
Navicat for SQLite导出所有表为数据库dbf格式
Navicat for MySQL将导出的dbf格式的数据库文件逐一导入新建的hos库中
DATAbaseS = {
'default': {
'ENGINE': 'django.db.backends.mysql', # mysql 驱动
'NAME': '', # 数据库名
'USER': '', # 用户名
'PASSWORD': '', # 密码
'HOST': '', # 访问的地址(localhost|127.0.0.1|'') 都代表本机
'PORT': '3306', # 端口号 mysql默认端口是3306
}
}
9.2.5 修改MIS默认数据库连接
import pymysql conn = pymysql.connect(host="192.168.x.x", port=3306, user="xxxx", passwd="xxxx", db="xxxx")十、迁移方法二 10.1 删除原有迁移文件
删除Django项目下migrations目录下所有迁移文件,仅保留__init__.py包文件
10.2 进入虚拟环境 10.3 python manage.py makemigrations 10.4 python manage.py migrate 10.5 Navicat导入向导逐个导入


