diff --git "a/08\346\236\227\350\212\263\345\251\225/2024-07-03MySQL\345\222\214Postgresql\345\237\272\347\241\200\345\221\275\344\273\244.md" "b/08\346\236\227\350\212\263\345\251\225/2024-07-03MySQL\345\222\214Postgresql\345\237\272\347\241\200\345\221\275\344\273\244.md" new file mode 100644 index 0000000000000000000000000000000000000000..31174f204d153a2fb20bc5608ae117e665b7a11f --- /dev/null +++ "b/08\346\236\227\350\212\263\345\251\225/2024-07-03MySQL\345\222\214Postgresql\345\237\272\347\241\200\345\221\275\344\273\244.md" @@ -0,0 +1,38 @@ +### MySQL基础命令 + +```bash +1.默认端口号:3307 +2.登录MySQL数据库:mysql -u root -p +3.退出数据库:exit +4.创建库:create database 库名; +5.使用库:use 库名; +6.查看所有库:show databases; +7.查看所有表:show tables; +8.显示表结构:desc 表名; +9.查看表内容:select * from 表名; +10.创建表:create table 表名; +11.添加值:insert into 表名 (列名) values (值); +12.查看建表时的结构:show create table 表名; +13.删除字段中的值:delete from 表名 where 条件; +14.删除表中字段:delete from 表名 drop column 字段名; +15.删除表:drop table 表名; +16.删除库:drop database 库名; +``` + + + +### Postgresql基础命令 + +```bash +1.默认端口号:5432 +2.登录Postgresql数据库: + su postgres + psql +3.退出数据库:\q +4.列出所有数据库:\l +5.创建库:create database 库名; +6.使用库:\c 库名; +7.查看该某个库中的所有表:\dt +8.查看某个库中某个表结构:\d 表名 +``` + diff --git "a/08\346\236\227\350\212\263\345\251\225/2024-07-04MySQL\347\232\204\350\277\234\347\250\213\350\277\236\346\216\245.md" "b/08\346\236\227\350\212\263\345\251\225/2024-07-04MySQL\347\232\204\350\277\234\347\250\213\350\277\236\346\216\245.md" new file mode 100644 index 0000000000000000000000000000000000000000..909bb9703f53829b5d93c32472ed484e48141d6e --- /dev/null +++ "b/08\346\236\227\350\212\263\345\251\225/2024-07-04MySQL\347\232\204\350\277\234\347\250\213\350\277\236\346\216\245.md" @@ -0,0 +1,29 @@ +### MySQL的远程连接 + +```bash +root@hecs-235925:~# apt install ufw (下载ufw) +root@hecs-235925:~# ufw allow 3307/tcp (允许3307端口) +root@hecs-235925:~# cd /etc/mysql/ +root@hecs-235925:/etc/mysql/# cd mysql.conf.d +root@hecs-235925:/etc/mysql/mysql.conf.d# vim mysql.conf + 进入mysql.conf 在最后一行添加: port = 3307 保存并退出 + 在华为云安全组中添加3307端口 +root@hecs-235925:/etc/mysql/# systemctl restart mysql (重启mysql) +root@hecs-235925:/etc/mysql/# systemctl status mysql (查看mysql状态 状态是running就可以) +root@hecs-235925:/etc/mysql/# ss -tunl (查看有没有3307端口) +root@hecs-235925:~# mysql -u root -p (登录mysql) + mysql> use mysql; + mysql> show tables; + mysql> select user,host from user; + mysql> update user set host='%' where user='root'; + mysql> flush privileges; + mysql> exit + +在Navicat Premium中连接mysql + 连接名:(随意) + 主机:1.94.22.105 + 端口:3307 + 用户名:root + 密码:(root的密码) +``` + diff --git "a/08\346\236\227\350\212\263\345\251\225/2024-07-05Postgresql\350\277\234\347\250\213\350\277\236\346\216\245.md" "b/08\346\236\227\350\212\263\345\251\225/2024-07-05Postgresql\350\277\234\347\250\213\350\277\236\346\216\245.md" new file mode 100644 index 0000000000000000000000000000000000000000..0ff758f7be72bb11940c525f98712b27b6c7ebfe --- /dev/null +++ "b/08\346\236\227\350\212\263\345\251\225/2024-07-05Postgresql\350\277\234\347\250\213\350\277\236\346\216\245.md" @@ -0,0 +1,24 @@ +### Postgresql远程连接 + +```bash +root@hecs-235925:~# cd /etc/postgresql/16/main +root@hecs-235925: /etc/postgresql/16/main# vim postgresql.conf + 配置监听地址和端口,找到listen_addresses,改为 listen_addresses='*'; +root@hecs-235925: /etc/postgresql/16/main# vim pg_hba.conf + 在host all all ::1/128 md5后面加上 + host all all 0.0.0.0/0 md5 +重启服务器 service postgresql restart +华为云在安全组添加5432端口 +root@hecs-235925:~# ufw allow 5432/tcp (允许5432端口) +root@hecs-235925:~# ufw status +root@hecs-235925:~# systemctl restart postgresql +root@hecs-235925:~# systemctl status postgresql + +在Navicat Premium中连接postgresql + 连接名:(随意) + 主机:1.94.22.105 + 端口:5432 + 用户名:postgresql + 密码:(postgresql的登录密码) +``` +