1. 程式人生 > 其它 >數列分塊入門 1-9

數列分塊入門 1-9

一、基本常用命令

1、啟動與停止電腦程序

環境:在windows管理下開啟控制檯;

net start 程序名稱 # 啟動程序;

net stop 程序名稱 # 停止程序;

2、mysql常用命令

1)客戶端登入

mysql -h localhost -u root -p # 客戶端登入;

其中:-h :後面跟上伺服器IP地址

-u :後面是使用者id

-p :後面是密碼

//#客戶端登入:mysql -h localhost -u root -p
C:\Users\EDY>mysql -h localhost -u root -p
Enter password: ****
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.34-log MySQL Community Server (GPL)

Copyright (c) 2000, 2021, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

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

mysql>

2)查詢版本號

select version(); # 查詢版本號

//#查詢版本號:select version(); 
mysql> select version();
+------------+
| version()  |
+------------+
| 5.7.34-log |
+------------+
1 row in set (0.01 sec)

3)檢視基本配置資訊

status # 檢視基本配置資訊

//# 檢視基本配置資訊:status 
mysql> status
--------------
mysql  Ver 14.14 Distrib 5.7.34, for Win64 (x86_64)

Connection id:          3
Current database:
Current user:           root@localhost
SSL:                    Cipher in use is ECDHE-RSA-AES128-GCM-SHA256
Using delimiter:        ;
Server version:         5.7.34-log MySQL Community Server (GPL)
Protocol version:       10
Connection:             localhost via TCP/IP
Server characterset:    latin1
Db     characterset:    latin1
Client characterset:    gbk
Conn.  characterset:    gbk
TCP port:               3306
Uptime:                 7 hours 23 min 47 sec

Threads: 1  Questions: 26  Slow queries: 0  Opens: 111  Flush tables: 1  Open tables: 104  Queries per second avg: 0.000
--------------

4)檢視當前時間

select now(); # 檢視當前時間

//# 檢視當前時間:select now(); 
mysql> select now();
+---------------------+
| now()               |
+---------------------+
| 2022-03-03 18:04:54 |
+---------------------+
1 row in set (0.00 sec)

5)檢視連線數

show variables like '%connections%'; # 檢視連線數

//# 檢視連線數show variables like '%connections%';
mysql> show variables like '%connections%';
+----------------------+-------+
| Variable_name        | Value |
+----------------------+-------+
| max_connections      | 151   |
| max_user_connections | 0     |
+----------------------+-------+
2 rows in set, 1 warning (0.01 sec)

6)查詢超時的關鍵字

show variables like '%timeout%'; # 查詢超時的關鍵字

//# 查詢超時的關鍵字:show variables like '%timeout%';
//connect_timeout:連結
//net_read_timeout:讀
//net_write_timeout:寫
//需要關注的是連結、讀和寫超時三部分

mysql> show variables like '%timeout%';
+-----------------------------+----------+
| Variable_name               | Value    |
+-----------------------------+----------+
| connect_timeout             | 10       |
| delayed_insert_timeout      | 300      |
| have_statement_timeout      | YES      |
| innodb_flush_log_at_timeout | 1        |
| innodb_lock_wait_timeout    | 50       |
| innodb_rollback_on_timeout  | OFF      |
| interactive_timeout         | 28800    |
| lock_wait_timeout           | 31536000 |
| net_read_timeout            | 30       |
| net_write_timeout           | 60       |
| rpl_stop_slave_timeout      | 31536000 |
| slave_net_timeout           | 60       |
| wait_timeout                | 28800    |
+-----------------------------+----------+
13 rows in set, 1 warning (0.01 sec)

二、管理命令

1、資料庫管理命令

1)建立資料庫

create database 資料庫名稱; # 建立資料庫

//# 建立資料庫:create database 資料庫名稱;
mysql> create database anruo;
Query OK, 1 row affected (0.01 sec)

2)檢視已有資料庫

show databases; # 檢視已有資料庫

//# 檢視已有資料庫:show databases;
mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| anruo              |
| indext             |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
6 rows in set (0.00 sec)

3)查詢資料庫在伺服器的儲存路徑

show variables like '%datadir%'; # 查詢資料庫在伺服器的儲存路徑

//# 查詢資料庫在伺服器的儲存路徑:show variables like '%datadir%';
mysql> show variables like '%datadir%';
+---------------+---------------------------------------------+
| Variable_name | Value                                       |
+---------------+---------------------------------------------+
| datadir       | C:\ProgramData\MySQL\MySQL Server 5.7\Data\ |
+---------------+---------------------------------------------+
1 row in set, 1 warning (0.00 sec)

mysql>

4)進入資料庫

use databaseName # 進入資料庫

//# 進入資料庫:use 資料庫名稱
mysql> use anruo
Database changed

5)驗證是否進入到那個資料庫

select database(); #驗證是否進入到那個資料庫

//# 查詢連線到那個資料庫:select database();
mysql> select database();
+------------+
| database() |
+------------+
| anruo      |
+------------+
1 row in set (0.00 sec)

6)檢視MySQL資料庫所有檔案

檢視MySQL資料庫的所有檔案,包括隱藏檔案的方法為:西安查詢到資料庫的儲存路徑,如上圖,然後在本地進入到上述目錄下,進入c盤,複製路徑進行搜尋即可進入到上述目錄,然後就可以檢視到所有的檔案;

7)刪除資料庫

drop database 資料庫名; # 刪除資料庫

//# 查詢連線到那個資料庫:select database(); 
mysql> drop database anruo;
Query OK, 0 rows affected (0.01 sec)

2、表格命令

1)建立表

create table 表的名稱(表的內容,填寫方式:欄位 資料型別); #建立表

//建立資料庫
mysql> create database anruo;
Query OK, 1 row affected (0.00 sec)

//進入指定資料庫
mysql> use anruo
Database changed

//建立表格
mysql> create table wugen(
    -> name varchar(10),
    -> age int,
    -> sex varchar(5),
    -> salary float,
    -> tal int,
    -> birthday datetime
    -> );
Query OK, 0 rows affected (0.04 sec)

//檢視指定表格
mysql> desc wugen;
+----------+-------------+------+-----+---------+-------+
| Field    | Type        | Null | Key | Default | Extra |
+----------+-------------+------+-----+---------+-------+
| name     | varchar(10) | YES  |     | NULL    |       |
| age      | int(11)     | YES  |     | NULL    |       |
| sex      | varchar(5)  | YES  |     | NULL    |       |
| salary   | float       | YES  |     | NULL    |       |
| tal      | int(11)     | YES  |     | NULL    |       |
| birthday | datetime    | YES  |     | NULL    |       |
+----------+-------------+------+-----+---------+-------+
6 rows in set (0.01 sec)

情景一:欄位約束

在資料庫中建立表時,欄位的約束條件:

(1)primary key 表示主鍵,主要是為了排序,就是該欄位的內容是唯一的;

(2)default 是指預設值,當該欄位沒有寫入內容時,寫入指定的內容;

(3)not null 是指不能為空;

(4)unique key 是指不能重複,具有唯一約束性,與primary的區別就是排序沒有primary強大);

如下所示:

//建立表格,帶入約束條件,即:
//primary key表示主鍵,主要是為了排序,就是該欄位的內容是唯一的;
//default是指預設值,當該欄位沒有寫入內容時,寫入指定的內容;
//not null是指不能為空;
//unique key 是指不能重複,具有唯一約束性,與primary的區別就是排序沒有primary強大);

mysql> create table anruo(
    -> id int primary key,
    -> name varchar(10) unique key,
    -> age int not null,
    -> sex varchar(5) default "girl"
    -> );
Query OK, 0 rows affected (0.04 sec)

//檢視當前表格
mysql> desc anruo;
+-------+-------------+------+-----+---------+-------+
| Field | Type        | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+-------+
| id    | int(11)     | NO   | PRI | NULL    |       |
| name  | varchar(10) | YES  | UNI | NULL    |       |
| age   | int(11)     | NO   |     | NULL    |       |
| sex   | varchar(5)  | YES  |     | girl    |       |
+-------+-------------+------+-----+---------+-------+
4 rows in set (0.00 sec)

mysql>

情景二:自增欄位

auto_increment # 自增

//建立自增表格
mysql> create table intal(
    -> id int primary key auto_increment,
    -> name varchar(10)
    -> );
Query OK, 0 rows affected (0.03 sec)

//檢視當前表格
mysql> desc intal;
+-------+-------------+------+-----+---------+----------------+
| Field | Type        | Null | Key | Default | Extra          |
+-------+-------------+------+-----+---------+----------------+
| id    | int(11)     | NO   | PRI | NULL    | auto_increment |
| name  | varchar(10) | YES  |     | NULL    |                |
+-------+-------------+------+-----+---------+----------------+
2 rows in set (0.01 sec)

//插入多條語句
mysql> insert into intal values(01,"zl");
Query OK, 1 row affected (0.01 sec)

//檢視當前表格
mysql> select * from intal;
+----+------+
| id | name |
+----+------+
|  1 | zl   |
+----+------+
1 row in set (0.00 sec)

//插入增值“name”
mysql> insert into intal(name) values("zhangli");
Query OK, 1 row affected (0.00 sec)

mysql> select * from intal;
+----+---------+
| id | name    |
+----+---------+
|  1 | zl      |
|  2 | zhangli |
+----+---------+
2 rows in set (0.00 sec)

2)查看錶格

show tables # 檢視所有表格名稱

desc intal; # 查看錶格內容

select * from 表格名稱; # 查詢更新後的結果資訊

//檢視所有表格
mysql> show tables;
+-----------------+
| Tables_in_anruo |
+-----------------+
| anruo           |
| intal           |
| wugen           |
+-----------------+
3 rows in set (0.00 sec)

//檢視當前表格
mysql> desc intal;
+-------+-------------+------+-----+---------+----------------+
| Field | Type        | Null | Key | Default | Extra          |
+-------+-------------+------+-----+---------+----------------+
| id    | int(11)     | NO   | PRI | NULL    | auto_increment |
| name  | varchar(10) | YES  |     | NULL    |                |
+-------+-------------+------+-----+---------+----------------+
2 rows in set (0.01 sec)

//插入多條語句
mysql> insert into intal values(01,"zl");
Query OK, 1 row affected (0.01 sec)

//檢視當前表格
mysql> select * from intal;
+----+------+
| id | name |
+----+------+
|  1 | zl   |
+----+------+
1 row in set (0.00 sec)

3、獲得表的SQL指令碼

show create table info \G; # 獲得表的SQL指令碼

//# 獲得表的SQL指令碼:show create table info \G; 
mysql> show create table anruo \G;
*************************** 1. row ***************************
       Table: anruo
Create Table: CREATE TABLE `anruo` (
  `id` int(11) NOT NULL,
  `name` varchar(10) DEFAULT NULL,
  `age` int(11) NOT NULL,
  `sex` varchar(5) DEFAULT 'girl',
  PRIMARY KEY (`id`),
  UNIQUE KEY `name` (`name`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1
1 row in set (0.00 sec)

ERROR:
No query specified

mysql>

4、MySQL的DML語句

1)INSERT(插入)

insert into user(使用者資訊); # 插入單條語句

insert into user values # 插入多條語句

insert into userImfo select * from user; # 批量插入表格