主頁 >  其他 > Mariadb基礎

Mariadb基礎

2020-10-22 03:07:46 其他

Mariadb基礎

關系型資料庫介紹

資料結構模型

  • 資料結構模型主要有:
    • 層次模型
    • 網狀模型
    • 關系模型
      • 二維關系:row(行),column(列)
  • 資料庫管理系統:DBMS(DataBase Management System)
  • 關系型資料庫管理系統:RDBMS(Relational DataBase Management System)

注: 資料庫管理系統是由DateBase服務+DateBase+table+row、column組成,這些東西可以存在多個,而不是只能存在一個


RDBMS專業名詞

  • 常見的關系型資料庫管理系統

    • MySQL:MySQL,MariaDB,Percona-Server
    • PostgreSQL:簡稱為pgsql
    • Oracle
    • MSSQL:Windows平臺的資料庫
  • SQL:Structure Query Language,結構化查詢語言

  • 約束:constraint,向資料表提供的資料要遵守的限制

    • 主鍵約束:一個或多個欄位的組合,填入的資料必須能在本表中唯一標識本行,且必須提供資料,不能為空(NOT NULL),
      • 一個表中只能存在一個
    • 惟一鍵約束:一個或多個欄位的組合,填入的資料必須能在本表中唯一標識本行,允許為空(NULL)
      • 一個表可以存在多個
    • 外鍵約束:一個表中的某欄位可填入資料取決于另一個表的主鍵已有的資料
    • 檢查性約束
  • 索引:將表中的一個或多個欄位中的資料復制一份另存,并且這些資料需要按特定次序排序存盤


關系型資料庫的常見組件

  • 資料庫:database
  • 表:table,由row和列column組成
  • 索引:index
  • 視圖:view
  • 用戶:user
  • 權限:privilege
  • 存盤程序:procedure
  • 存盤函式:function
  • 觸發器:trigger
  • 事件調度器:event scheduler

SQL陳述句

  • SQL陳述句分為三類
    • DDL:Data Defination Language,資料定義語言
    • DML:Data Manipulation Language,資料操縱語言
    • DCL:Data Control Language,資料控制語言
SQL陳述句型別對應操作
DDLCREATE:創建
DROP:洗掉
ALTER:修改
DMLINSERT:向表中插入資料
DELETE:洗掉表中資料
UPDATE:更新表中資料
SELECT:查詢表中資料
DCLGRANT:授權
REVOKE:移除授權

MariaDB安裝與配置

MariaDB安裝

  • MariaDB和MySQL操作語法是通用的,但是現在MySQL是收費的,所以這里我們安裝MariaDB
  • MariaDB安裝的方式有三種:
    • 源代碼:編譯安裝
    • 二進制格式的程式包:展開至特定路徑,并經過簡單配置后即可使用
    • 程式包管理器管理的程式包
//在Redhat 8中本地源中已經存在mariadb安裝包,所以可以直接使用yum命令安裝
[root@server ~]# yum -y install mariadb mariadb-common mariadb-devel mariadb-server
  • 在Redhat 7 中要安裝MySQL
#配置mysql的yum源
wget -O /usr/src/mysql57-community-release-el7-10.noarch.rpm \
http://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm
rpm -Uvh /usr/src/mysql57-community-release-el7-10.noarch.rpm

#安裝mysql5.7
yum -y install mysql-community-server mysql-community-client  \
mysql-community-common mysql-community-devel

Mariadb配置

//啟動資料庫
[root@server ~]# systemctl enable --now mariadb

//確保3306埠已經處于監聽狀態
[root@server ~]# ss -antl|grep 3306
LISTEN   0         80                        *:3306                   *:*       

//登錄mariadb資料庫
[root@server ~]# mysql -uroot
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 8
Server version: 10.3.17-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> 

//修改Mariadb登錄密碼
MariaDB [(none)]> set password = password('redhat123+');

//重新使用密碼登,以下兩種方法都可以登錄
[root@server ~]# mysql -uroot -p'redhat123+'
[root@server ~]# mysql -uroot -p 
Enter password: 


Mariadb的程式組成

  • 客戶端
    • mysql:CLI互動式客戶端程式
    • mysql_secure_installation:安全初始化
    • mysqldump:mysql備份工具
    • mysqladmin:mysql備份工具
  • 服務端
    • Mariadb

Mariadb工具使用

  • 語法:mysql [OPTIONS] [database]

  • 常用選項:

    • -uUSERNAME #指定用戶名,默認為root
    • -hHOST #指定服務器主機,默認為localhost,推薦使用ip地址
    • -pPASSWORD #指定用戶的密碼
    [root@server ~]# mysql -uroot -p'redhat123+' -h127.0.0.1 
    Welcome to the MariaDB monitor.  Commands end with ; or \g.
    Your MariaDB connection id is 11
    Server version: 10.3.17-MariaDB MariaDB Server
    
    Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
    
    Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
    
    MariaDB [(none)]> 
    
    • -P# #指定資料庫監聽的埠,這里的#需用實際的埠號代替,如-P3307
    • -V #查看當前使用的mysql版本
    [root@server ~]# mysql -V
    mysql  Ver 15.1 Distrib 10.3.17-MariaDB, for Linux (x86_64) using readline 5.1
    
    • -e #不登錄mysql執行sql陳述句后退出,常用于腳本
    [root@server ~]# mysql -uroot -p'redhat123+' -e 'SHOW DATABASES;'
    +--------------------+
    | Database           |
    +--------------------+
    | information_schema |
    | mysql              |
    | performance_schema |
    +--------------------+
    

服務端監聽的兩種socket地址

socket說明
IP socket默認監聽在tcp的3306埠,支持遠程通信
Unix socket監聽在sock檔案上(/tmp/mysql.sock,/var/lib/mysql/mysql.sock)
僅支持本地通信
server地址只能是:localhost,127.0.0.1

Mariadb資料庫操作

DDL操作

資料庫操作

  • 創建資料庫
//語法:CREATE DATABASE [IF NOT EXISTS] 'DB_NAME';
MariaDB [(none)]> CREATE DATABASE IF NOT EXISTS CWT;                       #如果CWT資料庫不存在則創建CWT資料庫,這樣做的好處是,如果要創建的資料庫存在也不會報錯
Query OK, 1 row affected (0.000 sec)

MariaDB [(none)]> SHOW DATABASES;
+--------------------+
| Database           |
+--------------------+
| CWT                |
| information_schema |
| mysql              |
| performance_schema |
+--------------------+
4 rows in set (0.000 sec)
  • 洗掉資料庫
//語法:DROP DATABASE [IF EXISTS] 'DB_NAME';
MariaDB [(none)]> DROP DATABASE IF EXISTS CWT;						      #如果CWT資料庫存在則洗掉它,這樣做的好處是,如果要洗掉的資料庫不存在也不會報錯
Query OK, 0 rows affected (0.001 sec)

MariaDB [(none)]> SHOW DATABASES;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
+--------------------+
3 rows in set (0.000 sec)

表操作

  • 創建表
//語法:CREATE TABLE table_name (col1 datatype 修飾符,col2 datatype 修飾符) ENGINE='存盤引擎型別';
MariaDB [(none)]> CREATE DATABASE XX_DATA;
Query OK, 1 row affected (0.000 sec)

MariaDB [(none)]> SHOW DATABASES;
+--------------------+
| Database           |
+--------------------+
| XX_DATA            |
| information_schema |
| mysql              |
| performance_schema |
+--------------------+
4 rows in set (0.000 sec)

//進入資料庫
MariaDB [(none)]> USE XX_DATA
Database changed
MariaDB [XX_DATA]> SHOW TABLES;

//創建表
MariaDB [XX_DATA]> CREATE TABLE xx(id int not null,name varchar(10),age tinyint);
Query OK, 0 rows affected (0.004 sec)

//查看表
MariaDB [XX_DATA]> SHOW TABLES;
+-------------------+
| Tables_in_XX_DATA |
+-------------------+
| xx                |
+-------------------+
1 row in set (0.001 sec)
  • 洗掉表
MariaDB [XX_DATA]> DROP TABLE xx;
Query OK, 0 rows affected (0.003 sec)

MariaDB [XX_DATA]> SHOW TABLES;
Empty set (0.000 sec)

用戶操作

  • mysql用戶帳號由兩部分組成,如'USERNAME'@'HOST',表示此USERNAME只能從此HOST上遠程登錄,HOST的值可以為:
    • IP地址,如:192.168.86.132
    • 通配符
      • %:匹配任意長度的任意字符,常用于設定允許從任何主機登錄
      • _:匹配任意單個字符

注: HOST應該為客戶端的IP地址

//創建用于登錄資料庫的用戶
語法:CREATE USER 'username'@'host' [IDENTIFIED BY 'password'];
MariaDB [(none)]> CREATE USER 'tom'@'192.168.86.132' IDENTIFIED BY 'redhat456+';
Query OK, 0 rows affected (0.000 sec)

//使用新創建的用戶和密碼在客戶端上登錄
[root@client ~]# mysql -utom -p'redhat456+' -h192.168.86.129
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 16
Server version: 10.3.17-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> 

//洗掉資料庫用戶
語法:DROP USER 'username'@'host'; 
MariaDB [(none)]> DROP USER 'tom'@'192.168.86.132';
Query OK, 0 rows affected (0.000 sec)

查看命令SHOW

  • 查看支持的所有字符集(支持的語言)
MariaDB [(none)]> SHOW CHARACTER SET;
+----------+-----------------------------+---------------------+--------+
| Charset  | Description                 | Default collation   | Maxlen |
+----------+-----------------------------+---------------------+--------+
| big5     | Big5 Traditional Chinese    | big5_chinese_ci     |      2 |
| dec8     | DEC West European           | dec8_swedish_ci     |      1 |
| cp850    | DOS West European           | cp850_general_ci    |      1 |
| hp8      | HP West European            | hp8_english_ci      |      1 |
...
  • 查看當前資料庫支持的所有存盤引擎
MariaDB [(none)]> SHOW ENGINES;
+--------------------+---------+----------------------------------------------------------------------------------+--------------+------+------------+
| Engine             | Support | Comment                                                                          | Transactions | XA   | Savepoints |
+--------------------+---------+----------------------------------------------------------------------------------+--------------+------+------------+
| MEMORY             | YES     | Hash based, stored in memory, useful for temporary tables                        | NO           | NO   | NO         |
| MRG_MyISAM         | YES     | Collection of identical MyISAM tables                   ...          

//上面那種方法輸出的內容比較難以閱讀,所以推薦使用以下這種方式
MariaDB [(none)]> SHOW ENGINES\G
*************************** 1. row ***************************
      Engine: MEMORY
     Support: YES
     Comment: Hash based, stored in memory, useful for temporary tables
Transactions: NO
          XA: NO
  Savepoints: NO
*************************** 2. row ***************************
      Engine: MRG_MyISAM
     Support: YES
     Comment: Collection of identical MyISAM tables
Transactions: NO
          XA: NO
  Savepoints: NO
...
  • 查看資料庫資訊
MariaDB [(none)]> SHOW DATABASES;
+--------------------+
| Database           |
+--------------------+
| XX_DATA            |
| information_schema |
| mysql              |
| performance_schema |
+--------------------+
4 rows in set (0.116 sec)

//不進入某資料庫而列出其包含的所有表
MariaDB [(none)]> SHOW TABLES FROM XX_DATA;
Empty set (0.000 sec)
  • 查看表結構
//語法:DESC [db_name.]table_name;
MariaDB [(none)]> DESC XX_DATA.xx;
+-------+-------------+------+-----+---------+-------+
| Field | Type        | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+-------+
| id    | int(11)     | NO   |     | NULL    |       |
| name  | varchar(15) | YES  |     | NULL    |       |
| age   | tinyint(4)  | YES  |     | NULL    |       |
+-------+-------------+------+-----+---------+-------+

//如果已經進入的資料庫,則只需要DESC xx;就能查看表結構了
  • 查看某表的創建命令
//語法:CREATE TABLE table_name;
MariaDB [XX_DATA]> SHOW CREATE TABLE xx;
...
| Table | Create Table                                                                                                                                           |
+-------+--------------------------------------------------------------------------------------------------------------------------------------------------------+
| xx    | CREATE TABLE `xx` (
  `id` int(11) NOT NULL,
  `name` varchar(15) DEFAULT NULL,
  `age` tinyint(4) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1 |
...
  • 查看某表的狀態
//語法:SHOW TABLE STATUS LIKE 'table_name'\G
MariaDB [XX_DATA]> SHOW TABLE STATUS LIKE 'xx'\G			#支持通配符,如:SHOW TABLE STATUS LIKE 'xx%'\G
*************************** 1. row ***************************
            Name: xx
          Engine: InnoDB
         Version: 10
      Row_format: Dynamic
            Rows: 0
  Avg_row_length: 0
     Data_length: 16384
 Max_data_length: 0
...
  • 添加欄位
MariaDB [XX_DATA]> DESC xx;
+-------+-------------+------+-----+---------+-------+
| Field | Type        | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+-------+
| id    | int(11)     | NO   |     | NULL    |       |
| name  | varchar(15) | YES  |     | NULL    |       |
| age   | tinyint(4)  | YES  |     | NULL    |       |
+-------+-------------+------+-----+---------+-------+
3 rows in set (0.000 sec)

MariaDB [XX_DATA]> ALTER TABLE xx ADD score float;
Query OK, 0 rows affected (0.002 sec)
Records: 0  Duplicates: 0  Warnings: 0

MariaDB [XX_DATA]> DESC xx;
+-------+-------------+------+-----+---------+-------+
| Field | Type        | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+-------+
| id    | int(11)     | NO   |     | NULL    |       |
| name  | varchar(15) | YES  |     | NULL    |       |
| age   | tinyint(4)  | YES  |     | NULL    |       |
| score | float       | YES  |     | NULL    |       |
+-------+-------------+------+-----+---------+-------+
4 rows in set (0.000 sec)
  • 洗掉欄位
MariaDB [XX_DATA]> DESC xx;
+-------+-------------+------+-----+---------+-------+
| Field | Type        | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+-------+
| id    | int(11)     | NO   |     | NULL    |       |
| name  | varchar(15) | YES  |     | NULL    |       |
| age   | tinyint(4)  | YES  |     | NULL    |       |
| score | float       | YES  |     | NULL    |       |
+-------+-------------+------+-----+---------+-------+
4 rows in set (0.000 sec)

MariaDB [XX_DATA]> ALTER TABLE xx DROP score;
Query OK, 0 rows affected (0.134 sec)
Records: 0  Duplicates: 0  Warnings: 0

MariaDB [XX_DATA]> DESC xx;
+-------+-------------+------+-----+---------+-------+
| Field | Type        | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+-------+
| id    | int(11)     | NO   |     | NULL    |       |
| name  | varchar(15) | YES  |     | NULL    |       |
| age   | tinyint(4)  | YES  |     | NULL    |       |
+-------+-------------+------+-----+---------+-------+
3 rows in set (0.001 sec)
  • 修改欄位
MariaDB [XX_DATA]> DESC xx;
+-------+-------------+------+-----+---------+-------+
| Field | Type        | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+-------+
| id    | int(11)     | NO   |     | NULL    |       |
| name  | varchar(15) | YES  |     | NULL    |       |
| age   | tinyint(4)  | YES  |     | NULL    |       |
+-------+-------------+------+-----+---------+-------+
3 rows in set (0.001 sec)

MariaDB [XX_DATA]> ALTER TABLE xx MODIFY age tinyint not null;
Query OK, 0 rows affected (0.007 sec)
Records: 0  Duplicates: 0  Warnings: 0

MariaDB [XX_DATA]> DESC xx;
+-------+-------------+------+-----+---------+-------+
| Field | Type        | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+-------+
| id    | int(11)     | NO   |     | NULL    |       |
| name  | varchar(15) | YES  |     | NULL    |       |
| age   | tinyint(4)  | NO   |     | NULL    |       |
+-------+-------------+------+-----+---------+-------+
3 rows in set (0.000 sec)

獲取幫助

  • 獲取命令使用幫助
//語法:HELP keyword;
MariaDB [XX_DATA]> HELP CREATE TABLE
Name: 'CREATE TABLE'
Description:
Syntax:
CREATE [TEMPORARY] TABLE [IF NOT EXISTS] tbl_name
    (create_definition,...)
    [table_options]
    [partition_options]
...

DML操作

  • DML操作包括增(INSERT)、刪(DELETE)、改(UPDATE)、查(SELECT),均屬針對表的操作,

INSERT陳述句

//語法:INSERT [INTO] table_name [(column_name,...)] {VALUES | VALUE} (value1,...),(...),...

MariaDB [XX_DATA]> DESC xx;
+-------+-------------+------+-----+---------+-------+
| Field | Type        | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+-------+
| id    | int(11)     | NO   |     | NULL    |       |
| name  | varchar(15) | YES  |     | NULL    |       |
| age   | tinyint(4)  | NO   |     | NULL    |       |
+-------+-------------+------+-----+---------+-------+
3 rows in set (0.001 sec)

//插入一條資料
MariaDB [XX_DATA]> INSERT INTO xx VALUE(1,'cwt',18);
Query OK, 1 row affected (0.001 sec)

//插入多條資料
MariaDB [XX_DATA]> INSERT INTO xx VALUES (2,'tom',20),(3,'xx',25),(4,'lisi',20);
Query OK, 3 rows affected (0.001 sec)
Records: 3  Duplicates: 0  Warnings: 0

SELECT陳述句

  • 欄位column表示法
表示符含義
*所有欄位
as欄位別名
  • 條件判斷陳述句WHERE
操作型別常用運算子
運算子>,<,>=,<=,=,!=
BETWEEN column# AND column#:在兩個欄位之間
LIKE:模糊匹配
RLIKE:基于正則運算式進行模式匹配
IS NOT NULL:非空
IS NULL:空
條件邏輯操作AND:與
OR:或
NOT:非
  • ORDER BY:排序,默認為升序(ASC)
ORDER BY 陳述句意義
ORDER BY ‘column_name’根據column_name進行升序排序
ORDER BY ‘column_name’ DESC根據column_name進行降序排序
ORDER BY ’column_name’ LIMIT 2根據column_name進行升序排序,并只取前2個結果
ORDER BY ‘column_name’ LIMIT 1,2根據column_name進行升序排序,并且略過第1個結果取后面的2個結果
//語法:SELECT column1,column2,... FROM table_name [WHERE clause] [ORDER BY 'column_name' [DESC]] [LIMIT [m,]n];

//查看表中的所有資料
MariaDB [cwt]> SELECT * FROM student;
+----+-------------+------+
| id | name        | age  |
+----+-------------+------+
|  1 | tom         |   20 |
|  2 | jerry       |   23 |
|  3 | wangqing    |   25 |
|  4 | sean        |   28 |
|  5 | zhangshan   |   26 |
|  6 | zhaangshan  |   20 |
|  7 | lisi        |   50 |
|  8 | chenshou    |   10 |
|  9 | wangwu      |  100 |
| 10 | qiuyi       |   15 |
| 11 | qiuxiaotian |   20 |
+----+-------------+------+

//查看表中指定的欄位的資料
MariaDB [cwt]> SELECT name FROM student;
+-------------+
| name        |
+-------------+
| tom         |
| jerry       |
| wangqing    |
| sean        |
| zhangshan   |
| zhaangshan  |
| lisi        |
| chenshou    |
| wangwu      |
| qiuyi       |
| qiuxiaotian |
+-------------+

//定義別名
MariaDB [cwt]> SELECT id AS a,name AS b,age AS c FROM student;
+----+-------------+------+
| a  | b           | c    |
+----+-------------+------+
|  1 | tom         |   20 |
|  2 | jerry       |   23 |
|  3 | wangqing    |   25 |
|  4 | sean        |   28 |
...

//查找年齡大于20的資料
MariaDB [cwt]> SELECT * FROM student WHERE age > 20;
+----+-----------+------+
| id | name      | age  |
+----+-----------+------+
|  2 | jerry     |   23 |
|  3 | wangqing  |   25 |
|  4 | sean      |   28 |
|  5 | zhangshan |   26 |
|  7 | lisi      |   50 |
|  9 | wangwu    |  100 |
+----+-----------+------+

//查找年齡在20到30歲之間的資料
MariaDB [cwt]> SELECT * FROM student WHERE age BETWEEN 20 AND 30;
+----+-------------+------+
| id | name        | age  |
+----+-------------+------+
|  1 | tom         |   20 |
|  2 | jerry       |   23 |
|  3 | wangqing    |   25 |
|  4 | sean        |   28 |
|  5 | zhangshan   |   26 |
|  6 | zhaangshan  |   20 |
| 11 | qiuxiaotian |   20 |
+----+-------------+------+

//查找名字以n結尾的資料
MariaDB [cwt]> SELECT * FROM student WHERE name LIKE '%n';
+----+-------------+------+
| id | name        | age  |
+----+-------------+------+
|  4 | sean        |   28 |
|  5 | zhangshan   |   26 |
|  6 | zhaangshan  |   20 |
| 11 | qiuxiaotian |   20 |
+----+-------------+------+

//使用正則運算式進行匹配
MariaDB [cwt]> SELECT * FROM student WHERE name RLIKE '^z.*';
+----+------------+------+
| id | name       | age  |
+----+------------+------+
|  5 | zhangshan  |   26 |
|  6 | zhaangshan |   20 |
+----+------------+------+

//匹配年齡為空的資料
MariaDB [cwt]> SELECT * FROM student WHERE age is NULL;
+----+------+------+
| id | name | age  |
+----+------+------+
| 12 | cwt  | NULL |
+----+------+------+

//以age欄位進行升序排序,去除age為NULL的行
MariaDB [cwt]> SELECT * FROM student WHERE age is NOT NULL ORDER BY age;
+----+-------------+------+
| id | name        | age  |
+----+-------------+------+
|  8 | chenshou    |   10 |
| 10 | qiuyi       |   15 |
|  1 | tom         |   20 |
|  6 | zhaangshan  |   20 |
...

//以age欄位進行降序排序,去除age為NULL的行
MariaDB [cwt]> SELECT * FROM student WHERE age is NOT NULL ORDER BY age DESC;
+----+-------------+------+
| id | name        | age  |
+----+-------------+------+
|  9 | wangwu      |  100 |
|  7 | lisi        |   50 |
|  4 | sean        |   28 |
|  5 | zhangshan   |   26 |
|  3 | wangqing    |   25 |
...

//以age欄位進行排序,并取前3個結果
MariaDB [cwt]> SELECT * FROM student WHERE age is NOT NULL ORDER BY age LIMIT 2;
+----+----------+------+
| id | name     | age  |
+----+----------+------+
|  8 | chenshou |   10 |
| 10 | qiuyi    |   15 |

//以age欄位進行排序,并忽略結果的第一個資料取后面的兩個資料
MariaDB [cwt]> SELECT * FROM student WHERE age is NOT NULL ORDER BY age LIMIT 1,2;
+----+-------------+------+
| id | name        | age  |
+----+-------------+------+
| 10 | qiuyi       |   15 |
| 11 | qiuxiaotian |   20 |
+----+-------------+------+

GROUP BY陳述句

  • 將結果集中的資料行根據選擇列的值進行邏輯分組,以便能匯總表內容的子集,實作對每個組而不是對整個結果集進行整合
//語法GROUP BY {col_name | expr | position} [ASC|DESC]

MariaDB [cwt]> SELECT * FROM info;
+----+-----------+------------+--------+
| id | name      | department | salary |
+----+-----------+------------+--------+
|  1 | zhangshan | sales      |   5000 |
|  2 | wangwu    | dev        |  20000 |
|  3 | lisi      | sales      |  15000 |
|  4 | cwt       | dev        |  15000 |
|  5 | tom       | operation  |  25000 |
|  6 | jerry     | operation  |  20000 |
+----+-----------+------------+--------+

//取出表中每個部門中工資最高的人
MariaDB [cwt]> SELECT name,department,MAX(salary) as salary FROM info GROUP BY department;
+-----------+------------+--------+
| name      | department | salary |
+-----------+------------+--------+
| wangwu    | dev        |  20000 |
| tom       | operation  |  25000 |
| zhangshan | sales      |  15000 |
+-----------+------------+--------+

UPDATE陳述句

//語法:UPDATE table_name SET column1 = new_value1[,column2 = new_value2,...] [WHERE clause] [ORDER BY 'column_name' [DESC]] [LIMIT [m,]n];

MariaDB [XX_DATA]> SELECT * FROM xx;
+----+------+-----+
| id | name | age |
+----+------+-----+
|  1 | cwt  |  18 |
|  2 | tom  |  20 |
|  3 | xx   |  25 |
|  4 | lisi |  20 |
+----+------+-----+
4 rows in set (0.000 sec)

MariaDB [XX_DATA]> UPDATE xx SET age = 21 where name = 'cwt';
Query OK, 1 row affected (0.001 sec)
Rows matched: 1  Changed: 1  Warnings: 0

MariaDB [XX_DATA]> SELECT * FROM xx;
+----+------+-----+
| id | name | age |
+----+------+-----+
|  1 | cwt  |  21 |
|  2 | tom  |  20 |
|  3 | xx   |  25 |
|  4 | lisi |  20 |
+----+------+-----+
4 rows in set (0.000 sec)

DELETE陳述句

//語法:DELETE FROM table_name [WHERE clause] [ORDER BY 'column_name' [DESC]] [LIMIT [m,]n];

MariaDB [XX_DATA]> SELECT * FROM xx;
+----+------+-----+
| id | name | age |
+----+------+-----+
|  1 | cwt  |  21 |
|  2 | tom  |  20 |
|  3 | xx   |  25 |
|  4 | lisi |  20 |
+----+------+-----+
4 rows in set (0.000 sec)

//洗掉表中的某一條記錄
MariaDB [XX_DATA]> DELETE FROM xx where name = 'xx';
Query OK, 1 row affected (0.002 sec)

MariaDB [XX_DATA]> SELECT * FROM xx;
+----+------+-----+
| id | name | age |
+----+------+-----+
|  1 | cwt  |  21 |
|  2 | tom  |  20 |
|  4 | lisi |  20 |
+----+------+-----+
3 rows in set (0.000 sec)

//洗掉整張表的內容,但會保留表本身
MariaDB [XX_DATA]> DELETE FROM xx;
Query OK, 3 rows affected (0.001 sec)

MariaDB [XX_DATA]> SELECT * FROM xx;
Empty set (0.000 sec)

MariaDB [XX_DATA]> SHOW TABLES;
+-------------------+
| Tables_in_XX_DATA |
+-------------------+
| xx                |
+-------------------+
1 row in set (0.000 sec)

TRUNCATE陳述句

  • TRUNCATE與DELETE的區別:
陳述句特點
DELETEDELETE洗掉表內容時僅洗掉內容,但會保留表結構
DELETE陳述句每次洗掉一行,并在事務日志中為所洗掉的每行記錄一項
可以通過回滾事務日志恢復資料
非常占用空間
TRUNCATE洗掉表中所有資料,且無法恢復
表結構、約束和索引等保持不變,新添加的行計數值重置為初始值
執行速度比DELETE快,且使用的系統和事務日志資源少
通過釋放存盤表資料所用的資料頁來洗掉資料,并且只在事務日志中記錄頁的釋放
對于有外鍵約束參考的表,不能使用TRUNCATE TABLE洗掉資料
不能用于加入了索引視圖的表
//語法:TRUNCATE table_name;

DCL操作

創建授權GRANT

  • 權限型別(priv_type)
權限型別作用
ALL所有權限
SELECT讀取內容的權限
INSERT插入內容的權限
UPDATE更新內容的權限
DELETE洗掉內容的權限
  • 指定要操作的物件db_name.table_name
表示方式意義
*.*所有庫的所有表
db_name指定庫的所有表
db_name.table_name指定庫的指定表

注: WITH GRANT OPTION:被授權的用戶可將自己的權限副本轉贈給其他用戶(復制自己的權限給另外一個用戶),不建議使用,

//語法:GRANT priv_type,... ON [object_type] db_name.table_name TO 'username'@'host' [IDENTIFIED BY 'password'] [WITH GRANT OPTION];

MariaDB [(none)]> SHOW DATABASES;
+--------------------+
| Database           |
+--------------------+
| XX_DATA            |
| information_schema |
| mysql              |
| performance_schema |
+--------------------+
4 rows in set (0.000 sec)


//授權tom用戶在192.168.86.132上遠程登錄資料庫,且對XX_DATA資料庫有SELECT權限
MariaDB [(none)]> GRANT SELECT ON XX_DATA.* TO 'tom'@'192.168.86.132' IDENTIFIED BY 'redhat456+';
Query OK, 0 rows affected (0.000 sec)

//重讀授權表
MariaDB [(none)]> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.000 sec)

//遠程登錄資料庫,并測驗權限是否正確設定
[root@client ~]# mysql -utom -p'redhat456+' -h192.168.86.129
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 18
Server version: 10.3.17-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> SHOW DATABASES;
+--------------------+
| Database           |
+--------------------+
| XX_DATA            |
| information_schema |
+--------------------+
2 rows in set (0.00 sec)

MariaDB [(none)]> USE XX_DATA
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
MariaDB [XX_DATA]> CREATE TABLE cwt(id int not null);
ERROR 1142 (42000): CREATE command denied to user 'tom'@'192.168.86.132' for table 'cwt'

查看授權

  • 查看當前登錄用戶的授權資訊
MariaDB [(none)]> SHOW GRANTS;
+----------------------------------------------------------------------------------------------------------------------------------------+
| Grants for root@localhost                                                                                                              |
+----------------------------------------------------------------------------------------------------------------------------------------+
| GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' IDENTIFIED BY PASSWORD '*AACA4ED26B7AFC0A081A787B8C607B4262252DE5' WITH GRANT OPTION |
| GRANT PROXY ON ''@'%' TO 'root'@'localhost' WITH GRANT OPTION                           
...
  • 查看指定用戶的授權資訊
MariaDB [(none)]> SHOW GRANTS FOR 'tom'@'192.168.86.132';
+-----------------------------------------------------------------------------------------------------------------+
| Grants for tom@192.168.86.132                                                                                   |
+-----------------------------------------------------------------------------------------------------------------+
| GRANT USAGE ON *.* TO 'tom'@'192.168.86.132' IDENTIFIED BY PASSWORD '*0AF6C9DF2CBB59D18182D5C4AFD2E069F93F7DA3' |
| GRANT SELECT ON `XX_DATA`.* TO 'tom'@'192.168.86.132'                                   
...

取消授權REVOKE

//語法:REVOKE priv_type,... ON db_name.table_name FROM 'username'@'host';

MariaDB [(none)]> REVOKE SELECT ON XX_DATA.* FROM 'tom'@'192.168.86.132';
Query OK, 0 rows affected (0.000 sec)


//重讀授權表
MariaDB [(none)]> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.000 sec)


MariaDB [(none)]> SHOW GRANTS FOR tom@192.168.86.132;
+-----------------------------------------------------------------------------------------------------------------+
| Grants for tom@192.168.86.132                                                                                   |
+-----------------------------------------------------------------------------------------------------------------+
| GRANT USAGE ON *.* TO 'tom'@'192.168.86.132' IDENTIFIED BY PASSWORD '*0AF6C9DF2CBB59D18182D5C4AFD2E069F93F7DA3' |
  • mysql服務行程啟動時會讀取mysql庫中的所有授權表至記憶體中:
    • GRANT或REVOKE等執行權限操作會保存于表中,mysql的服務行程會自動重讀授權表,并更新至記憶體中
    • 對于不能夠或不能及時重讀授權表的命令,可手動讓mysql的服務行程重讀授權表
//重讀授權表
MariaDB [(none)]> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.000 sec)

內連接、左連接以及右連接

  • 示例表說明:
MariaDB [cwt]> SELECT * FROM info;
+----+-----------+------------+--------+
| id | name      | department | salary |
+----+-----------+------------+--------+
|  1 | zhangshan | sales      |   5000 |
|  2 | wangwu    | dev        |  20000 |
|  3 | lisi      | sales      |  15000 |
|  4 | cwt       | dev        |  15000 |
|  5 | tom       | operation  |  25000 |
|  6 | jerry     | operation  |  20000 |
+----+-----------+------------+--------+
6 rows in set (0.000 sec)

MariaDB [cwt]> SELECT * FROM age_info;
+----+------+
| id | age  |
+----+------+
|  1 |   30 |
|  2 |   20 |
|  3 |   45 |
|  4 |   30 |
|  5 |   25 |
|  6 |   23 |
|  7 |   28 |
|  8 |   30 |
|  9 |   25 |
| 10 |   23 |
| 11 |   28 |
| 12 |   30 |
+----+------+
12 rows in set (0.000 sec)

MariaDB [cwt]> SELECT * FROM job_number;
+----+----+
| id | jn |
+----+----+
|  1 |  1 |
|  2 |  3 |
|  3 |  5 |
|  4 |  6 |
|  5 |  9 |
+----+----+

內連接

  • 組合兩個表中的記錄,回傳關聯欄位相符的記錄,也就是回傳兩張表中都包含的內容
MariaDB [cwt]> SELECT * FROM info as a INNER JOIN age_info as b ON a.id = b.id INNER JOIN job_number as c ON a.id = c.jn;
+----+-----------+------------+--------+----+------+----+----+
| id | name      | department | salary | id | age  | id | jn |
+----+-----------+------------+--------+----+------+----+----+
|  1 | zhangshan | sales      |   5000 |  1 |   30 |  1 |  1 |
|  3 | lisi      | sales      |  15000 |  3 |   45 |  2 |  3 |
|  5 | tom       | operation  |  25000 |  5 |   25 |  3 |  5 |
|  6 | jerry     | operation  |  20000 |  6 |   23 |  4 |  6 |
+----+-----------+------------+--------+----+------+----+----+

左連接

  • left join 是left outer join的簡寫,它的全稱是左外連接,是外連接中的一種, 左(外)連接,左表(a_table)的記錄將會全部表示出來,而右表(b_table)只會顯示符合搜索條件的記錄,右表記錄不足的地方均為NULL,
MariaDB [cwt]> SELECT * FROM info as a LEFT JOIN age_info as b ON a.id = b.id LEFT JOIN job_number as c ON a.id = c.jn;
+----+-----------+------------+--------+------+------+------+------+
| id | name      | department | salary | id   | age  | id   | jn   |
+----+-----------+------------+--------+------+------+------+------+
|  1 | zhangshan | sales      |   5000 |    1 |   30 |    1 |    1 |
|  3 | lisi      | sales      |  15000 |    3 |   45 |    2 |    3 |
|  5 | tom       | operation  |  25000 |    5 |   25 |    3 |    5 |
|  6 | jerry     | operation  |  20000 |    6 |   23 |    4 |    6 |
|  2 | wangwu    | dev        |  20000 |    2 |   20 | NULL | NULL |
|  4 | cwt       | dev        |  15000 |    4 |   30 | NULL | NULL |
+----+-----------+------------+--------+------+------+------+------+

右連接

  • right join是right outer join的簡寫,它的全稱是右外連接,是外連接中的一種,與左(外)連接相反,右(外)連接,左表(a_table)只會顯示符合搜索條件的記錄,而右表(b_table)的記錄將會全部表示出來,左表記錄不足的地方均為NULL,
MariaDB [cwt]> SELECT * FROM info as a RIGHT JOIN age_info as b ON a.id = b.id RIGHT JOIN job_number as c ON a.id = c.jn;
+------+-----------+------------+--------+------+------+----+----+
| id   | name      | department | salary | id   | age  | id | jn |
+------+-----------+------------+--------+------+------+----+----+
|    1 | zhangshan | sales      |   5000 |    1 |   30 |  1 |  1 |
|    3 | lisi      | sales      |  15000 |    3 |   45 |  2 |  3 |
|    5 | tom       | operation  |  25000 |    5 |   25 |  3 |  5 |
|    6 | jerry     | operation  |  20000 |    6 |   23 |  4 |  6 |
| NULL | NULL      | NULL       |   NULL | NULL | NULL |  5 |  9 |
+------+-----------+------------+--------+------+------+----+----+

  • 查詢多張表,組合結果
MariaDB [cwt]> SELECT * FROM info;
+----+-----------+------------+--------+
| id | name      | department | salary |
+----+-----------+------------+--------+
|  1 | zhangshan | sales      |   5000 |
|  2 | wangwu    | dev        |  20000 |
|  3 | lisi      | sales      |  15000 |
|  4 | cwt       | dev        |  15000 |
|  5 | tom       | operation  |  25000 |
|  6 | jerry     | operation  |  20000 |
+----+-----------+------------+--------+
6 rows in set (0.000 sec)

MariaDB [cwt]> SELECT * FROM age_info;
+----+------+
| id | age  |
+----+------+
|  1 |   30 |
|  2 |   20 |
|  3 |   45 |
|  4 |   30 |
|  5 |   25 |
|  6 |   23 |
|  7 |   28 |
|  8 |   30 |
+----+------+

MariaDB [cwt]> SELECT * FROM info,age_info WHERE info.name = 'cwt' AND info.id = age_info.id;
+----+------+------------+--------+----+------+
| id | name | department | salary | id | age  |
+----+------+------------+--------+----+------+
|  4 | cwt  | dev        |  15000 |  4 |   30 |
+----+------+------------+--------+----+------+
1 row in set (0.001 sec)

//指定欄位
MariaDB [cwt]> SELECT info.name,age_info.age FROM info,age_info WHERE info.name = 'cwt' AND info.id = age_info.id;
+------+------+
| name | age  |
+------+------+
| cwt  |   30 |
+------+------+

示例

  • 創建一個資料庫,并創建一張表student,該表包含三個欄位(id,name,age),表結構如下:
mysql> desc student;
+-------+--------------+------+-----+---------+----------------+
| Field | Type         | Null | Key | Default | Extra          |
+-------+--------------+------+-----+---------+----------------+
| id    | int(11)      | NO   | PRI | NULL    | auto_increment |
| name  | varchar(100) | NO   |     | NULL    |                |
| age   | tinyint(4)   | YES  |     | NULL    |                |
+-------+--------------+------+-----+---------+----------------+
3 rows in set (0.01 sec)
  • 決議
MariaDB [(none)]> CREATE DATABASE cwt;
Query OK, 1 row affected (0.000 sec)

MariaDB [(none)]> SHOW DATABASES;
+--------------------+
| Database           |
+--------------------+
| cwt                |
| information_schema |
| mysql              |
| performance_schema |
+--------------------+
4 rows in set (0.001 sec)


MariaDB [(none)]> USE cwt;
Database changed

MariaDB [cwt]> CREATE TABLE student(id int PRIMARY KEY auto_increment NOT NULL,name VARCHAR(100) NOT NULL,age tinyint);
Query OK, 0 rows affected (0.326 sec)

MariaDB [cwt]> desc student;
+-------+--------------+------+-----+---------+----------------+
| Field | Type         | Null | Key | Default | Extra          |
+-------+--------------+------+-----+---------+----------------+
| id    | int(11)      | NO   | PRI | NULL    | auto_increment |
| name  | varchar(100) | NO   |     | NULL    |                |
| age   | tinyint(4)   | YES  |     | NULL    |                |
+-------+--------------+------+-----+---------+----------------+
3 rows in set (0.003 sec)


  • 查看下該新建的表有無內容(用select陳述句)
MariaDB [cwt]> SELECT * FROM student;
Empty set (0.000 sec)

  • 在新建的student表中插入資料(用insert陳述句),結果應如下所示:
+----+-------------+------+
| id | name        | age  |
+----+-------------+------+
|  1 | tom         |   20 |
|  2 | jerry       |   23 |
|  3 | wangqing    |   25 |
|  4 | sean        |   28 |
|  5 | zhangshan   |   26 |
|  6 | zhangshan   |   20 |
|  7 | lisi        | NULL |
|  8 | chenshuo    |   10 |
|  9 | wangwu      |    3 |
| 10 | qiuyi       |   15 |
| 11 | qiuxiaotian |   20 |
+----+-------------+------+
  • 決議
MariaDB [cwt]> insert student(name,age) values('tom',20),('jerry',23),('wangqing',25),('sean',28),('zhangshan',26),('zhangshan',20),('lisi',NULL),('chenshou',10),('wangqu',3),('qiuyi',15),('qiuxiaotian',20);

MariaDB [cwt]> SELECT * FROM student;
+----+-------------+------+
| id | name        | age  |
+----+-------------+------+
|  1 | tom         |   20 |
|  2 | jerry       |   23 |
|  3 | wangqing    |   25 |
|  4 | sean        |   28 |
|  5 | zhangshan   |   26 |
|  6 | zhangshan   |   20 |
|  7 | lisi        | NULL |
|  8 | chenshou    |   10 |
|  9 | wangwu      |    3 |
| 10 | qiuyi       |   15 |
| 11 | qiuxiaotian |   20 |
+----+-------------+------+
11 rows in set (0.000 sec)

  • 修改lisi的年齡為50
MariaDB [cwt]> UPDATE student set age = 50 where name = 'lisi';
Query OK, 1 row affected (0.001 sec)
Rows matched: 1  Changed: 1  Warnings: 0

MariaDB [cwt]> SELECT * FROM student;
+----+-------------+------+
| id | name        | age  |
+----+-------------+------+
|  1 | tom         |   20 |
|  2 | jerry       |   23 |
|  3 | wangqing    |   25 |
|  4 | sean        |   28 |
|  5 | zhangshan   |   26 |
|  6 | zhangshan   |   20 |
|  7 | lisi        |   50 |
|  8 | chenshou    |   10 |
|  9 | wangwu      |    3 |
| 10 | qiuyi       |   15 |
| 11 | qiuxiaotian |   20 |
+----+-------------+------+
11 rows in set (0.000 sec)

  • 以age欄位降序排序
MariaDB [cwt]> SELECT * FROM student ORDER BY age DESC;
+----+-------------+------+
| id | name        | age  |
+----+-------------+------+
| 29 | lisi        |   50 |
| 26 | sean        |   28 |
| 27 | zhangshan   |   26 |
| 25 | wangqing    |   25 |
| 24 | jerry       |   23 |
| 23 | tom         |   20 |
| 28 | zhangshan   |   20 |
| 33 | qiuxiaotian |   20 |
| 32 | qiuyi       |   15 |
| 30 | chenshou    |   10 |
| 31 | wangqu      |    3 |
+----+-------------+------+

  • 查詢student表中年齡最小的3位同學跳過前2位
MariaDB [cwt]> SELECT * FROM student ORDER BY age LIMIT 2,3;
+----+-------------+------+
| id | name        | age  |
+----+-------------+------+
| 32 | qiuyi       |   15 |
| 23 | tom         |   20 |
| 33 | qiuxiaotian |   20 |
+----+-------------+------+

  • 查詢student表中年齡最大的4位同學
MariaDB [cwt]> SELECT * FROM student ORDER BY age DESC LIMIT 4;
+----+-----------+------+
| id | name      | age  |
+----+-----------+------+
| 29 | lisi      |   50 |
| 26 | sean      |   28 |
| 27 | zhangshan |   26 |
| 25 | wangqing  |   25 |
+----+-----------+------+

  • 查詢student表中名字叫zhangshan的記錄
MariaDB [cwt]> SELECT * FROM student WHERE name = 'zhangshan';
+----+-----------+------+
| id | name      | age  |
+----+-----------+------+
|  5 | zhangshan |   26 |
|  6 | zhangshan |   20 |
+----+-----------+------+
2 rows in set (0.000 sec)

  • 查詢student表中名字叫zhangshan且年齡大于20歲的記錄
MariaDB [cwt]> SELECT * FROM student WHERE name = 'zhangshan' AND age > 20;
+----+-----------+------+
| id | name      | age  |
+----+-----------+------+
|  5 | zhangshan |   26 |
+----+-----------+------+
1 row in set (0.000 sec)

  • 查詢student表中年齡在23到30之間的記錄
MariaDB [cwt]> SELECT * FROM student WHERE age BETWEEN 23 and 30;
+----+-----------+------+
| id | name      | age  |
+----+-----------+------+
|  2 | jerry     |   23 |
|  3 | wangqing  |   25 |
|  4 | sean      |   28 |
|  5 | zhangshan |   26 |
+----+-----------+------+
4 rows in set (0.000 sec)

  • 修改wangwu的年齡為100
MariaDB [cwt]> UPDATE student set age = 100 where name = 'wangwu';
Query OK, 1 row affected (0.002 sec)
Rows matched: 1  Changed: 1  Warnings: 0

MariaDB [cwt]> SELECT * FROM student WHERE name = 'wangwu';
+----+--------+------+
| id | name   | age  |
+----+--------+------+
|  9 | wangwu |  100 |
+----+--------+------+
1 row in set (0.000 sec)

  • 洗掉student中名字叫zhangshan且年齡小于等于20的記錄
MariaDB [cwt]> DELETE FROM student WHERE name = 'zhangshan' AND age <= 20;
Query OK, 1 row affected (0.001 sec)

MariaDB [cwt]> SELECT * FROM student;
+----+-------------+------+
| id | name        | age  |
+----+-------------+------+
|  1 | tom         |   20 |
|  2 | jerry       |   23 |
|  3 | wangqing    |   25 |
|  4 | sean        |   28 |
|  5 | zhangshan   |   26 |
|  7 | lisi        |   50 |
|  8 | chenshou    |   10 |
|  9 | wangwu      |  100 |
| 10 | qiuyi       |   15 |
| 11 | qiuxiaotian |   20 |
+----+-------------+------+
10 rows in set (0.000 sec)

轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/184954.html

標籤:其他

上一篇:PL/SQL入門,非常詳細的筆記

下一篇:Oracle表空間

標籤雲
其他(157675) Python(38076) JavaScript(25376) Java(17977) C(15215) 區塊鏈(8255) C#(7972) AI(7469) 爪哇(7425) MySQL(7132) html(6777) 基礎類(6313) sql(6102) 熊猫(6058) PHP(5869) 数组(5741) R(5409) Linux(5327) 反应(5209) 腳本語言(PerlPython)(5129) 非技術區(4971) Android(4554) 数据框(4311) css(4259) 节点.js(4032) C語言(3288) json(3245) 列表(3129) 扑(3119) C++語言(3117) 安卓(2998) 打字稿(2995) VBA(2789) Java相關(2746) 疑難問題(2699) 细绳(2522) 單片機工控(2479) iOS(2429) ASP.NET(2402) MongoDB(2323) 麻木的(2285) 正则表达式(2254) 字典(2211) 循环(2198) 迅速(2185) 擅长(2169) 镖(2155) 功能(1967) .NET技术(1958) Web開發(1951) python-3.x(1918) HtmlCss(1915) 弹簧靴(1913) C++(1909) xml(1889) PostgreSQL(1872) .NETCore(1853) 谷歌表格(1846) Unity3D(1843) for循环(1842)

熱門瀏覽
  • 網閘典型架構簡述

    網閘架構一般分為兩種:三主機的三系統架構網閘和雙主機的2+1架構網閘。 三主機架構分別為內端機、外端機和仲裁機。三機無論從軟體和硬體上均各自獨立。首先從硬體上來看,三機都用各自獨立的主板、記憶體及存盤設備。從軟體上來看,三機有各自獨立的作業系統。這樣能達到完全的三機獨立。對于“2+1”系統,“2”分為 ......

    uj5u.com 2020-09-10 02:00:44 more
  • 如何從xshell上傳檔案到centos linux虛擬機里

    如何從xshell上傳檔案到centos linux虛擬機里及:虛擬機CentOs下執行 yum -y install lrzsz命令,出現錯誤:鏡像無法找到軟體包 前言 一、安裝lrzsz步驟 二、上傳檔案 三、遇到的問題及解決方案 總結 前言 提示:其實很簡單,往虛擬機上安裝一個上傳檔案的工具 ......

    uj5u.com 2020-09-10 02:00:47 more
  • 一、SQLMAP入門

    一、SQLMAP入門 1、判斷是否存在注入 sqlmap.py -u 網址/id=1 id=1不可缺少。當注入點后面的引數大于兩個時。需要加雙引號, sqlmap.py -u "網址/id=1&uid=1" 2、判斷文本中的請求是否存在注入 從文本中加載http請求,SQLMAP可以從一個文本檔案中 ......

    uj5u.com 2020-09-10 02:00:50 more
  • Metasploit 簡單使用教程

    metasploit 簡單使用教程 浩先生, 2020-08-28 16:18:25 分類專欄: kail 網路安全 linux 文章標簽: linux資訊安全 編輯 著作權 metasploit 使用教程 前言 一、Metasploit是什么? 二、準備作業 三、具體步驟 前言 Msfconsole ......

    uj5u.com 2020-09-10 02:00:53 more
  • 游戲逆向之驅動層與用戶層通訊

    驅動層代碼: #pragma once #include <ntifs.h> #define add_code CTL_CODE(FILE_DEVICE_UNKNOWN,0x800,METHOD_BUFFERED,FILE_ANY_ACCESS) /* 更多游戲逆向視頻www.yxfzedu.com ......

    uj5u.com 2020-09-10 02:00:56 more
  • 北斗電力時鐘(北斗授時服務器)讓網路資料更精準

    北斗電力時鐘(北斗授時服務器)讓網路資料更精準 北斗電力時鐘(北斗授時服務器)讓網路資料更精準 京準電子科技官微——ahjzsz 近幾年,資訊技術的得了快速發展,互聯網在逐漸普及,其在人們生活和生產中都得到了廣泛應用,并且取得了不錯的應用效果。計算機網路資訊在電力系統中的應用,一方面使電力系統的運行 ......

    uj5u.com 2020-09-10 02:01:03 more
  • 【CTF】CTFHub 技能樹 彩蛋 writeup

    ?碎碎念 CTFHub:https://www.ctfhub.com/ 筆者入門CTF時時剛開始刷的是bugku的舊平臺,后來才有了CTFHub。 感覺不論是網頁UI設計,還是題目質量,賽事跟蹤,工具軟體都做得很不錯。 而且因為獨到的金幣制度的確讓人有一種想去刷題賺金幣的感覺。 個人還是非常喜歡這個 ......

    uj5u.com 2020-09-10 02:04:05 more
  • 02windows基礎操作

    我學到了一下幾點 Windows系統目錄結構與滲透的作用 常見Windows的服務詳解 Windows埠詳解 常用的Windows注冊表詳解 hacker DOS命令詳解(net user / type /md /rd/ dir /cd /net use copy、批處理 等) 利用dos命令制作 ......

    uj5u.com 2020-09-10 02:04:18 more
  • 03.Linux基礎操作

    我學到了以下幾點 01Linux系統介紹02系統安裝,密碼啊破解03Linux常用命令04LAMP 01LINUX windows: win03 8 12 16 19 配置不繁瑣 Linux:redhat,centos(紅帽社區版),Ubuntu server,suse unix:金融機構,證券,銀 ......

    uj5u.com 2020-09-10 02:04:30 more
  • 05HTML

    01HTML介紹 02頭部標簽講解03基礎標簽講解04表單標簽講解 HTML前段語言 js1.了解代碼2.根據代碼 懂得挖掘漏洞 (POST注入/XSS漏洞上傳)3.黑帽seo 白帽seo 客戶網站被黑帽植入劫持代碼如何處理4.熟悉html表單 <html><head><title>TDK標題,描述 ......

    uj5u.com 2020-09-10 02:04:36 more
最新发布
  • 2023年最新微信小程式抓包教程

    01 開門見山 隔一個月發一篇文章,不過分。 首先回顧一下《微信系結手機號資料庫被脫庫事件》,我也是第一時間得知了這個訊息,然后跟蹤了整件事情的經過。下面是這起事件的相關截圖以及近日流出的一萬條資料樣本: 個人認為這件事也沒什么,還不如關注一下之前45億快遞資料查詢渠道疑似在近日復活的訊息。 訊息是 ......

    uj5u.com 2023-04-20 08:48:24 more
  • web3 產品介紹:metamask 錢包 使用最多的瀏覽器插件錢包

    Metamask錢包是一種基于區塊鏈技術的數字貨幣錢包,它允許用戶在安全、便捷的環境下管理自己的加密資產。Metamask錢包是以太坊生態系統中最流行的錢包之一,它具有易于使用、安全性高和功能強大等優點。 本文將詳細介紹Metamask錢包的功能和使用方法。 一、 Metamask錢包的功能 數字資 ......

    uj5u.com 2023-04-20 08:47:46 more
  • vulnhub_Earth

    前言 靶機地址->>>vulnhub_Earth 攻擊機ip:192.168.20.121 靶機ip:192.168.20.122 參考文章 https://www.cnblogs.com/Jing-X/archive/2022/04/03/16097695.html https://www.cnb ......

    uj5u.com 2023-04-20 07:46:20 more
  • 從4k到42k,軟體測驗工程師的漲薪史,給我看哭了

    清明節一過,盲猜大家已經無心上班,在數著日子準備過五一,但一想到銀行卡里的余額……瞬間心情就不美麗了。最近,2023年高校畢業生就業調查顯示,本科畢業月平均起薪為5825元。調查一出,便有很多同學表示自己又被平均了。看著這一資料,不免讓人想到前不久中國青年報的一項調查:近六成大學生認為畢業10年內會 ......

    uj5u.com 2023-04-20 07:44:00 more
  • 最新版本 Stable Diffusion 開源 AI 繪畫工具之中文自動提詞篇

    🎈 標簽生成器 由于輸入正向提示詞 prompt 和反向提示詞 negative prompt 都是使用英文,所以對學習母語的我們非常不友好 使用網址:https://tinygeeker.github.io/p/ai-prompt-generator 這個網址是為了讓大家在使用 AI 繪畫的時候 ......

    uj5u.com 2023-04-20 07:43:36 more
  • 漫談前端自動化測驗演進之路及測驗工具分析

    隨著前端技術的不斷發展和應用程式的日益復雜,前端自動化測驗也在不斷演進。隨著 Web 應用程式變得越來越復雜,自動化測驗的需求也越來越高。如今,自動化測驗已經成為 Web 應用程式開發程序中不可或缺的一部分,它們可以幫助開發人員更快地發現和修復錯誤,提高應用程式的性能和可靠性。 ......

    uj5u.com 2023-04-20 07:43:16 more
  • CANN開發實踐:4個DVPP記憶體問題的典型案例解讀

    摘要:由于DVPP媒體資料處理功能對存放輸入、輸出資料的記憶體有更高的要求(例如,記憶體首地址128位元組對齊),因此需呼叫專用的記憶體申請介面,那么本期就分享幾個關于DVPP記憶體問題的典型案例,并給出原因分析及解決方法。 本文分享自華為云社區《FAQ_DVPP記憶體問題案例》,作者:昇騰CANN。 DVPP ......

    uj5u.com 2023-04-20 07:43:03 more
  • msf學習

    msf學習 以kali自帶的msf為例 一、msf核心模塊與功能 msf模塊都放在/usr/share/metasploit-framework/modules目錄下 1、auxiliary 輔助模塊,輔助滲透(埠掃描、登錄密碼爆破、漏洞驗證等) 2、encoders 編碼器模塊,主要包含各種編碼 ......

    uj5u.com 2023-04-20 07:42:59 more
  • Halcon軟體安裝與界面簡介

    1. 下載Halcon17版本到到本地 2. 雙擊安裝包后 3. 步驟如下 1.2 Halcon軟體安裝 界面分為四大塊 1. Halcon的五個助手 1) 影像采集助手:與相機連接,設定相機引數,采集影像 2) 標定助手:九點標定或是其它的標定,生成標定檔案及內參外參,可以將像素單位轉換為長度單位 ......

    uj5u.com 2023-04-20 07:42:17 more
  • 在MacOS下使用Unity3D開發游戲

    第一次發博客,先發一下我的游戲開發環境吧。 去年2月份買了一臺MacBookPro2021 M1pro(以下簡稱mbp),這一年來一直在用mbp開發游戲。我大致分享一下我的開發工具以及使用體驗。 1、Unity 官網鏈接: https://unity.cn/releases 我一般使用的Apple ......

    uj5u.com 2023-04-20 07:40:19 more