diff --git "a/\346\242\201\346\231\213\351\233\204/20240624\345\216\213\347\274\251\350\247\243\345\216\213\347\243\201\347\233\230\347\256\241\347\220\206.md" "b/\346\242\201\346\231\213\351\233\204/20240624\345\216\213\347\274\251\350\247\243\345\216\213\347\243\201\347\233\230\347\256\241\347\220\206.md" new file mode 100644 index 0000000000000000000000000000000000000000..2a475190d2d1926ea1016dc7da3529ad79e24d0f --- /dev/null +++ "b/\346\242\201\346\231\213\351\233\204/20240624\345\216\213\347\274\251\350\247\243\345\216\213\347\243\201\347\233\230\347\256\241\347\220\206.md" @@ -0,0 +1,12 @@ +## 压缩解压 ++ tar:通常与其他压缩命令一起使用来压缩和解压缩文件和目录。 +-c: 建立压缩档案 +-x:解压 +-t:查看内容 +-r:向压缩归档文件末尾追加文件 +-u:更新原压缩包中的文件 +## 磁盘管理 ++ Linux 磁盘管理常用三个命令为 df、du 和 fdisk。 ++ df:检查文件系统的磁盘空间占用情况 ++ du:Linux du 命令也是查看使用空间的,但是与 df 命令不同的是 Linux du 命令是对文件和目录磁盘使用的空间的查看。 ++ fdisk:是 Linux 的磁盘分区表操作工具。 \ No newline at end of file diff --git "a/\346\242\201\346\231\213\351\233\204/20240701Linux\345\256\211\350\243\205MySQL.md" "b/\346\242\201\346\231\213\351\233\204/20240701Linux\345\256\211\350\243\205MySQL.md" new file mode 100644 index 0000000000000000000000000000000000000000..0a7b5dc12e7d08c9b552bf816a1bec1c18a6771d --- /dev/null +++ "b/\346\242\201\346\231\213\351\233\204/20240701Linux\345\256\211\350\243\205MySQL.md" @@ -0,0 +1,12 @@ +#### Debian 安装mysql 8.0 ++ 1.下载mysql的deb包 + ++ 2.非Linux本机下载 - 下载以后使用scp上传到指定目录 + ++ 3.安装deb包,形成软件源文件 /etc/apt/sources.list.d/mysql.list + ++ 4.更新apt update,安装mysql apt install mysql-server + ++ 5.重启sql服务 + ++ 6.安装完成后,使用如下命令可以本地连接到数据库 mysql -u root -p \ No newline at end of file diff --git "a/\346\242\201\346\231\213\351\233\204/20240702mysql\350\277\234\347\250\213\347\231\273\345\275\225.md" "b/\346\242\201\346\231\213\351\233\204/20240702mysql\350\277\234\347\250\213\347\231\273\345\275\225.md" new file mode 100644 index 0000000000000000000000000000000000000000..717156aa9191059ca9f0fc28f76ffad699b79bc9 --- /dev/null +++ "b/\346\242\201\346\231\213\351\233\204/20240702mysql\350\277\234\347\250\213\347\231\273\345\275\225.md" @@ -0,0 +1,15 @@ +### mysql远程登录 ++ update user set host='%' where user='root'; + ++ grant all on root.* to 'root'@'%'; + +### 增删改查 ++ 创建: create(创建数据库) + ++ 增:insert(插入表数据) + ++ 删:drop、delete(删除表、删除表数据) + ++ 改:update、alter(更改表数据、插入新字段) + ++ 查:select、show、describe/desc(查询表数据、查看所有表、查看表结构) \ No newline at end of file diff --git "a/\346\242\201\346\231\213\351\233\204/20240703postgresql.md" "b/\346\242\201\346\231\213\351\233\204/20240703postgresql.md" new file mode 100644 index 0000000000000000000000000000000000000000..27497d32dab956302bfd00402ca4bfd8ec007296 --- /dev/null +++ "b/\346\242\201\346\231\213\351\233\204/20240703postgresql.md" @@ -0,0 +1,76 @@ +## 安装postgresql + +1. apt install -y postgresql-common + +2. ``` + /usr/share/postgresql-common/pgdg/apt.postgresql.org.sh 点回车 + ``` + +3. apt install postgrepsql + +4. 进入postgresql:su postgres + +5. psql + +6. \l:列出当前所有数据库 \c:连接数据库 \dt:查看数据库 + + + +## 远程登录 + +删除postgres密码:sudo passwd -d postgres + +更改postgres密码:sudo -u postgres passwd + +``` +修改密码 +sudo -u postgres psql +ALTER USER postgres WITH PASSWORD 'postgres'; +``` + +1. vim /etc/postgresql/版本号/main/postgresql.conf + +2. 找到#listen_addresses = 'localhost' 取消注释,改为listen_addresses = '*' + +3. vim /etc/postgresql/16/main/pg_hba.conf + +4. 在文件末尾添加以下行,允许所有IP地址通过密码连接:host all all 0.0.0.0/0 md5 + +5. sudo iptables -A INPUT -p tcp --dport 5432 -j ACCEPT -- 开放5432端口 + +6. 服务器需要设置安全组端口 + +7. ``` + ststemctl status firewalld --- 查看防火墙是运行 + firewall-cmd --add-port=3306/tcp --permanent -- 添加需要开放的端口 + firewall-cmd --reload -- 重新载入添加的端口 + firewall-cmd --query-port=3306/tcp -- 查询端口是否开启 + ``` + + + + + + + +## 创建1000万条数据 + +``` + +标题、内容、作者、出版时间、昵称、头像 +create database abc; +use abc; +create table blog ( +title varchar(255), +content varchar(255), +author varchar(255), +publishedtime timestamp, +nickname varchar(255), +avatar varchar(255) +); + + +EXPLAIN (ANALYZE, TIMING) insert into blog select generate_series(1,10000000),md5(random()::varchar),md5(random()::varchar),clock_timestamp(),md5(random()::varchar),md5(random()::varchar); + +插入时间:63.1s 55529.030 ms +``` \ No newline at end of file diff --git "a/\346\242\201\346\231\213\351\233\204/20240703postgresql\344\275\234\344\270\232.md" "b/\346\242\201\346\231\213\351\233\204/20240703postgresql\344\275\234\344\270\232.md" new file mode 100644 index 0000000000000000000000000000000000000000..28c614d60cc4ad1ba510350c5f8a8fb916b6b230 --- /dev/null +++ "b/\346\242\201\346\231\213\351\233\204/20240703postgresql\344\275\234\344\270\232.md" @@ -0,0 +1,59 @@ +### 写一个自义函数,要求传入一个1到30到正整数,返回指定参数个的随机字符 + +```` + +string_agg:连接字符串 + +``` +create or replace function gen_hanzi(int) +returns text as $$ +declare -- 局部变量 + res text; +begin + if $1 >=1 then + select string_agg(chr(int4(random()*25)+65), '') into res from generate_series(1,$1); + return res; + end if; + return null; +end; +$$ language plpgsql strict; + +select gen_hanzi(3); +``` + +``` +create or replace function random_string(integer) +returns text as +$$ + select upper(array_to_string(array(select substring('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz' FROM (ceil(random()*62))::int FOR 1) FROM generate_series(1, $1)), '')); +$$ +language sql; + +select random_string(5); + + + +```` + + + +### 自定义函数,要求随机返回1到30位的英文字符,最少返回一个,最多长度30 + +``` + +create or replace function random_text1() +returns text as $$ +declare +res text; +begin + select string_agg(chr(int4(random()*25)+65),'') into res from generate_series(1,(select floor(random()*30+1)::int)); + return res; +end; +$$ language plpgsql; + + +select random_text1(); + +``` + +## \ No newline at end of file