步骤记录
1.申请服务器(白嫖两个月)
略
xshell是最方便的
刚创建云服务器就开始测试一些自己知道的命令
ls
cd
clear
python
python3
touch
cat
rm
...
apt-get
然后要安装tree,发现报错(忘了是是啥了,反正查到要更新才行)
sudo apt-get update
sudo apt-get install tree
tree
ln(link)
简单复现了快捷方式的创建,软链接和硬链接
(软就是纯指向,像快捷方式,删除就删除快捷方式文件;
硬就是映射磁盘位置,硬链接数量会存在文件信息中,有点像share指针,删除硬链接同时会减少该文件硬链接数量)
软链接加-s
(soft)
ln [-s] [被链接文件] [生成文件]
ln -s /home/ming/ test_ln
ln /home/ming/ test_ln
ps(process)
a:(all)当前系统所有用户的进程
u:查看进程所有者及其他一些信息
x:显示没有控制终端的进程 – 不能与用户进行交互的进程【输入、输出】
显示当前用户下所有进程 ps aux
ps aux | grep xxx
利用管道|
左边结果输入到右边通过grep(无需”“)筛选
kill
查看信号编号
kill -l
杀死进程
kill -SIGKILL 89899【PID-进程标识号】
这里可以多开几个中断看进程ps aux | grep bash
,然后kill一个看看
不知道kill自己是什么效果
addusr
sudo addusr ming
密码设置为ming326033
Linux搭建ftp服务器
sudo apt-get install vsftpd
sudo vim /etc/vsftpd.conf # 按视频里设置就行
service vsftpd restart
自己新开终端登录一下自己
ftp 172.26.222.209#自己可使用内网ip
#输入ming这个用户的用户名密码即可成功登陆
尝试使用windows实名登陆ftp
需要云服务器设置安全组(见视频)
其实就是放开入的21端口(另一个端口范围不知道干嘛的)
然后就可以了
C:\Users\15518>ftp 39.103.171.252
连接到 39.103.171.252。
220 (vsFTPd 3.0.3)
200 Always in UTF8 mode.
用户(39.103.171.252:(none)): ming
331 Please specify the password.
密码:
230 Login successful.
ftp> quit
221 Goodbye.
中间有尝试自己查看自己的外网ip,卡死(据说是端口被占,估计又是安全组的问题)
sudo apt-get install curl
curl ifconfig.me
匿名登陆:
用户名固定anonymous,密码空
可在配置文件中指定anon_root=/home/ming/MyFtp
来设置匿名用户访问文件夹,匿名用户不能向上级访问!!
其中需要修改文件权限来使匿名用户可以操作某些文件chomd
NFS服务器
253 sudo apt-get install nfs-kernel-server 254 cd .. 255 cd home/ming/ 256 ls 257 mkdir MyNfs 258 vim /etc/exports 259 sudo service nfs-kernel-server restart 260 cd MyNfs/ 261 touch 1.txt 262 vim 1.txt
这里vim /etc/exports
用来配置nfs
其中/home/ming/MyNfs *(rw,sync)
表示文件夹 ip段(权限【读写,同步(内存中的会立即同步)】)
windows配置nfs
如图,这样才能识别mount命令
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-Bc8UJBv4-1624353714910)(assets/image-20210608165801459.png)]
C:\Users\15518>mount -h'mount' 不是内部或外部命令,也不是可运行的程序或批处理文件。C:\Users\15518>mount本地 远程 属性-------------------------------------------------------------------------------C:\Users\15518>mount \\39.103.171.252\home\ming\MyNfs x:网络错误 - 53有关详细信息,请键入“NET HELPMSG 53”。C:\Users\15518>net helpmsg 53找不到网络路径。C:\Users\15518>
这留个尾巴
ssh服务器
sudo apt-get install openssh-server安装(服务器肯定已经装好了呀)
windows登陆
C:\Users\15518>ssh ming@39.103.171.252The authenticity of host '39.103.171.252 (39.103.171.252)' can't be established.ECDSA key fingerprint is SHA256:/BetboMf8xcxHRPZwpl7tVPnpKds6gdUGBknFyB3SUw.Are you sure you want to continue connecting (yes/no)? yesWarning: Permanently added '39.103.171.252' (ECDSA) to the list of known hosts.ming@39.103.171.252's password:Welcome to Ubuntu 18.04.5 LTS (GNU/Linux 4.15.0-143-generic x86_64) * Documentation: https://help.ubuntu.com * Management: https://landscape.canonical.com * Support: https://ubuntu.com/advantage * Canonical Livepatch is available for installation. - Reduce system reboots and improve kernel security. Activate at: https://ubuntu.com/livepatchNew release '20.04.2 LTS' available.Run 'do-release-upgrade' to upgrade to it.The programs included with the Ubuntu system are free software;the exact distribution terms for each program are described in theindividual files in /usr/share/doc/*/copyright.Welcome to Ubuntu 18.04.5 LTS (GNU/Linux 4.15.0-143-generic x86_64) * Documentation: https://help.ubuntu.com * Management: https://landscape.canonical.com * Support: https://ubuntu.com/advantage * Canonical Livepatch is available for installation. - Reduce system reboots and improve kernel security. Activate at: https://ubuntu.com/livepatchNew release '20.04.2 LTS' available.Run 'do-release-upgrade' to upgrade to it.The programs included with the Ubuntu system are free software;the exact distribution terms for each program are described in theindividual files in /usr/share/doc/*/copyright.Ubuntu comes with ABSOLUTELY NO WARRANTY, to the extent permitted byapplicable law.Welcome to Alibaba Cloud Elastic Compute Service !ming@iZ8vb44rvj11y7u33l5yhsZ:~$ lsMyFtp MyNfsming@iZ8vb44rvj11y7u33l5yhsZ:~$ cd MyNfs/ming@iZ8vb44rvj11y7u33l5yhsZ:~/MyNfs$ ls1.txtming@iZ8vb44rvj11y7u33l5yhsZ:~/MyNfs$ ls -ltotal 4-rw-r--r-- 1 root root 11 Jun 8 16:49 1.txtming@iZ8vb44rvj11y7u33l5yhsZ:~/MyNfs$ exitlogoutConnection to 39.103.171.252 closed.C:\Users\15518>
scp
== super copy
无需搭建ftp服务器进行文件拷贝(下载)
man
命令进行查询手册,比如:(所以man man也是可以的)
man lsLS(1) User Commands LS(1)NAME ls - list directory contentsSYNOPSIS ls [OPTION]... [FILE]...DESCRIPTION List information about the FILEs (the current directory by default). Sort entries alphabeti‐ cally if none of -cftuvSUX nor --sort is specified. Mandatory arguments to long options are mandatory for short options too. -a, --all do not ignore entries starting with ....
alias
【单词意思:别名】封装内容,比如ls封装了ls --color=
auto
root@iZ8vb44rvj11y7u33l5yhsZ:~# alias lsalias ls='ls --color=auto'
echo
打印到终端
root@iZ8vb44rvj11y7u33l5yhsZ:~# echo PATHPATHroot@iZ8vb44rvj11y7u33l5yhsZ:~# echo $PATH/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin
$表示取后面那个东西【PATH】的值
。。。
vim/vi
MySQL
install
sudo apt-get install mysql-serversudo apt-get install mysql-client
verification
client
service mysql start # no error means client install ok
server
root@iZ8vb44rvj11y7u33l5yhsZ:~# mysql -uroot -pEnter password: 【mysql】Welcome to the MySQL monitor. Commands end with ; or \g.Your MySQL connection id is 2Server version: 5.7.34-0ubuntu0.18.04.1 (Ubuntu)Copyright (c) 2000, 2021, Oracle and/or its affiliates.Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.mysql> ^DByeroot@iZ8vb44rvj11y7u33l5yhsZ:~#
start \ stop
sudo service mysql statussudo service mysql stopsudo service mysql start sudo service mysql restart
configure
vim /etc/mysql/mysql.conf.d/mysqld.cnf
Login
mysql -u【用户名】 -p【密码】
print time now
mysql> select now();
+---------------------+
| now() |
+---------------------+
| 2021-06-23 14:24:02 |
+---------------------+
1 row in set (0.00 sec)
logout
【ctrl+d】
some sql sentences
about database
# 单行注释方法
show databases; # view all databases
create database goods charset=utf8; # create a database called “goods” encoding type is “usf-8”
use goods; # use database called “goods”
select database(); # view which database is being using
drop database goods; # delete goods
about table
show tables;
create table 【表名】(字段名称 数据类型 约束条件,字段名称 数据类型 约束条件,。。。);
alter table 表名 modify 列名 类型 约束; # change column’s type
desc 表名; # view strctrue of a table
drop 表名; # delete table
table example
mysql> use goods;
Database changed
mysql> show tables;
Empty set (0.00 sec)
mysql> create table info(
-> id int unsigned primary key not null auto_increment,
-> name char(10) not null,
-> age int);
Query OK, 0 rows affected (0.03 sec)
mysql> show tables;
+-----------------+
| Tables_in_goods |
+-----------------+
| info |
+-----------------+
1 row in set (0.00 sec)
mysql> desc info
-> ;
+-------+------------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------+------------------+------+-----+---------+----------------+
| id | int(10) unsigned | NO | PRI | NULL | auto_increment |
| name | char(10) | NO | | NULL | |
| age | int(11) | YES | | NULL | |
+-------+------------------+------+-----+---------+----------------+
3 rows in set (0.01 sec)
mysql> alter table info modify name varchar(200) not null;
Query OK, 0 rows affected (0.09 sec)
Records: 0 Duplicates: 0 Warnings: 0
mysql> desc info
-> ;
+-------+------------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------+------------------+------+-----+---------+----------------+
| id | int(10) unsigned | NO | PRI | NULL | auto_increment |
| name | varchar(200) | NO | | NULL | |
| age | int(11) | YES | | NULL | |
+-------+------------------+------+-----+---------+----------------+
3 rows in set (0.00 sec)
mysql> drop table info;
Query OK, 0 rows affected (0.02 sec)
CRUD
crud是指在做计算处理时的增加(Create)、检索(Retrieve)、更新(Update)和删除(Delete)几个单词的首字母简写
首先是建立一个测试用表
mysql> create table students( id int unsigned not null primary key auto_increment, name varchar(50) not null, age int(11), gender enum('男','女') default '男');
Query OK, 0 rows affected (0.04 sec)
mysql> desc students;
+--------+-------------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+--------+-------------------+------+-----+---------+----------------+
| id | int(10) unsigned | NO | PRI | NULL | auto_increment |
| name | varchar(50) | NO | | NULL | |
| age | int(11) | YES | | NULL | |
| gender | enum('男','女') | YES | | 男 | |
+--------+-------------------+------+-----+---------+----------------+
4 rows in set (0.01 sec)
然后开始操作
mysql> insert into students value(0,'小明',18,'男');
Query OK, 1 row affected (0.00 sec)
mysql> select * from students;
+----+--------+------+--------+
| id | name | age | gender |
+----+--------+------+--------+
| 1 | 小明 | 18 | 男 |
+----+--------+------+--------+
1 row in set (0.00 sec)
mysql> mysql> insert into students(name) values('小王');
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'valudH values('小王')' at line 1
mysql> insert into students(name) values('小王');
Query OK, 1 row affected (0.00 sec)
mysql> select * from students;
+----+--------+------+--------+
| id | name | age | gender |
+----+--------+------+--------+
| 1 | 小明 | 18 | 男 |
| 2 | 小王 | NULL | 男 |
+----+--------+------+--------+
2 rows in set (0.00 sec)
mysql> insert into students values(0,'Lily',16,'女'),(0,'HanMM',12,'女');
Query OK, 2 rows affected (0.01 sec)
Records: 2 Duplicates: 0 Warnings: 0
mysql> select * from students;
+----+--------+------+--------+
| id | name | age | gender |
+----+--------+------+--------+
| 1 | 小明 | 18 | 男 |
| 2 | 小王 | NULL | 男 |
| 3 | Lily | 16 | 女 |
| 4 | HanMM | 12 | 女 |
+----+--------+------+--------+
4 rows in set (0.00 sec)
mysql> insert into students(name) values('李磊'),('小王'),('大头儿子');
Query OK, 3 rows affected (0.00 sec)
Records: 3 Duplicates: 0 Warnings: 0
mysql> select * from students;
+----+--------------+------+--------+
| id | name | age | gender |
+----+--------------+------+--------+
| 1 | 小明 | 18 | 男 |
| 2 | 小王 | NULL | 男 |
| 3 | Lily | 16 | 女 |
| 4 | HanMM | 12 | 女 |
| 5 | 李磊 | NULL | 男 |
| 6 | 小王 | NULL | 男 |
| 7 | 大头儿子 | NULL | 男 |
+----+--------------+------+--------+
7 rows in set (0.00 sec)
retrieve
mysql> select * from students;
+----+--------------+------+--------+
| id | name | age | gender |
+----+--------------+------+--------+
| 1 | 小明 | 18 | 男 |
| 2 | 小王 | NULL | 男 |
| 3 | Lily | 16 | 女 |
| 4 | HanMM | 12 | 女 |
| 5 | 李磊 | NULL | 男 |
| 6 | 小王 | NULL | 男 |
| 7 | 大头儿子 | NULL | 男 |
+----+--------------+------+--------+
7 rows in set (0.00 sec)
mysql> select name,age from students;
+--------------+------+
| name | age |
+--------------+------+
| 小明 | 18 |
| 小王 | NULL |
| Lily | 16 |
| HanMM | 12 |
| 李磊 | NULL |
| 小王 | NULL |
| 大头儿子 | NULL |
+--------------+------+
7 rows in set (0.00 sec)
update
mysql> update students set age=22,name='hm' where id=4;
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> select * from students;
+----+--------------+------+--------+
| id | name | age | gender |
+----+--------------+------+--------+
| 1 | 小明 | 18 | 男 |
| 2 | 小王 | NULL | 男 |
| 3 | Lily | 16 | 女 |
| 4 | hm | 22 | 女 |
| 5 | 李磊 | NULL | 男 |
| 6 | 小王 | NULL | 男 |
| 7 | 大头儿子 | NULL | 男 |
+----+--------------+------+--------+
7 rows in set (0.00 sec)
delete
mysql> delete from students where id=7;
Query OK, 1 row affected (0.01 sec)
mysql> select * from students;
+----+--------+------+--------+
| id | name | age | gender |
+----+--------+------+--------+
| 1 | 小明 | 18 | 男 |
| 2 | 小王 | NULL | 男 |
| 3 | Lily | 16 | 女 |
| 4 | hm | 22 | 女 |
| 5 | 李磊 | NULL | 男 |
| 6 | 小王 | NULL | 男 |
+----+--------+------+--------+
6 rows in set (0.00 sec)
backup & export
mysqldump -uroot goods > /home/ming/data.sql
resume & import
root@iZ8vb44rvj11y7u33l5yhsZ:~# cd /home/ming/
root@iZ8vb44rvj11y7u33l5yhsZ:/home/ming# ls
data.sql MyFtp MyNfs
root@iZ8vb44rvj11y7u33l5yhsZ:/home/ming# mysql -uroot -pmysql
mysql> use goods;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> drop table students;
Query OK, 0 rows affected (0.02 sec)
mysql> show tables;
Empty set (0.00 sec)
mysql> source data.sql;
。。。
。。。
mysql> show tables;
+-----------------+
| Tables_in_goods |
+-----------------+
| students |
+-----------------+
1 row in set (0.00 sec)
mysql> select * from students;
+----+--------+------+--------+
| id | name | age | gender |
+----+--------+------+--------+
| 1 | 小明 | 18 | 男 |
| 2 | 小王 | NULL | 男 |
| 3 | Lily | 16 | 女 |
| 4 | hm | 22 | 女 |
| 5 | 李磊 | NULL | 男 |
| 6 | 小王 | NULL | 男 |
+----+--------+------+--------+
6 rows in set (0.00 sec)
pymysql
preparations
- 修改安全组配置,开放3306端口
- 参考https://blog.csdn.net/hello404/article/details/82149597,修改密码的某个格式。。没太看懂
import pymysql
connc = pymysql.Connect(
user='root',
password='mysql',
database='goods',
port=3306,
charset='utf8'
)
cur = connc.cursor()
sql = 'select * from students;'
cur.execute(sql)
result = cur.fetchall()
print(result)
cur.close()
root@iZ8vb44rvj11y7u33l5yhsZ:/home/ming/git/MySQL_learning# python3 pymysql_test.py
((1, '小明', 18, '男'), (2, '小王', None, '男'), (3, 'Lily', 16, '女'), (4, 'hm', 22, '女'), (5, '李磊', None, '男'), (6, '小王', None, '男'))