91超碰碰碰碰久久久久久综合_超碰av人澡人澡人澡人澡人掠_国产黄大片在线观看画质优化_txt小说免费全本

溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

mysql語句的基本操作

發布時間:2020-08-03 04:05:02 來源:網絡 閱讀:369 作者:sky9890 欄目:數據庫

實踐練習環境:直接在生產環境中操作

OS:CentOS6.8

具體操作流程如下:

Last login: Wed Aug 10 08:07:15 2016 from ********
歡迎登錄*************CentOS服務器!
[sky@sky9896 ~]$ mysql -u root -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 114094
Server version: 5.5.49-cll-lve MySQL Community Server (GPL) by Atomicorp

Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.

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> create database a  #創建數據庫a
    -> ;
Query OK, 1 row affected (0.08 sec)

mysql> show databases;  #顯示所有數據庫
+--------------------+
| Database           |
+--------------------+
| information_schema |
| a                  |
| back20150625ultrax |
| cacti              |
| cacti20151220      |
| cacti20160104      |
| feifeicms          |
| mysql              |
| performance_schema |
| phpcom             |
| study              |
| syslog             |
| test               |
| test1              |
| tt                 |
| ultrax             |
+--------------------+
16 rows in set (0.16 sec)

mysql> use a   #打開數據庫
Database changed
mysql> show tables;
Empty set (0.00 sec)

mysql> create table a1(id int);  #創建a1表
Query OK, 0 rows affected (0.22 sec)

mysql> show tables;   #顯示所有表;
+-------------+
| Tables_in_a |
+-------------+
| a1          |
+-------------+
1 row in set (0.00 sec)

mysql> describe a1  #顯示表結構
    -> ;
+-------+---------+------+-----+---------+-------+
| Field | Type    | Null | Key | Default | Extra |
+-------+---------+------+-----+---------+-------+
| id    | int(11) | YES  |     | NULL    |       |
+-------+---------+------+-----+---------+-------+
1 row in set (0.00 sec)

mysql> show engines; #查看引擎
+--------------------+---------+----------------------------------------------------------------+--------------+------+------------+
| Engine             | Support | Comment                                                        | Transactions | XA   | Savepoints |
+--------------------+---------+----------------------------------------------------------------+--------------+------+------------+
| MRG_MYISAM         | YES     | Collection of identical MyISAM tables                          | NO           | NO   | NO         |
| CSV                | YES     | CSV storage engine                                             | NO           | NO   | NO         |
| MyISAM             | YES     | MyISAM storage engine                                          | NO           | NO   | NO         |
| BLACKHOLE          | YES     | /dev/null storage engine (anything you write to it disappears) | NO           | NO   | NO         |
| MEMORY             | YES     | Hash based, stored in memory, useful for temporary tables      | NO           | NO   | NO         |
| InnoDB             | DEFAULT | Supports transactions, row-level locking, and foreign keys     | YES          | YES  | YES        |
| ARCHIVE            | YES     | Archive storage engine                                         | NO           | NO   | NO         |
| PERFORMANCE_SCHEMA | YES     | Performance Schema                                             | NO           | NO   | NO         |
| FEDERATED          | NO      | Federated MySQL storage engine                                 | NULL         | NULL | NULL       |
+--------------------+---------+----------------------------------------------------------------+--------------+------+------------+
9 rows in set (0.00 sec)

[sky@sky9896 ~]$ mysql -u root-p  #連接數據庫
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 114209
Server version: 5.5.49-cll-lve MySQL Community Server (GPL) by Atomicorp

Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.

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> exit   #退出
Bye

mysql> use a;
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> create table a2(
    -> id int unsigned not null  auto_increment, #不能為空,自動增加數值
    -> name char(40) not null default ' ', #不能為空,默認為空
    -> info char(200) null,
    -> primary key(id));#設置id為主鍵
Query OK, 0 rows affected (0.12 sec)

mysql> describe a2;
+-------+------------------+------+-----+---------+----------------+
| Field | Type             | Null | Key | Default | Extra          |
+-------+------------------+------+-----+---------+----------------+
| id    | int(10) unsigned | NO   | PRI | NULL    | auto_increment |
| name  | char(40)         | NO   |     |         |                |
| info  | char(200)        | YES  |     | NULL    |                |
+-------+------------------+------+-----+---------+----------------+
3 rows in set (0.00 sec)

mysql> show tables;
+-------------+
| Tables_in_a |
+-------------+
| a1          |
| a2          |
+-------------+
2 rows in set (0.00 sec)

mysql> insert into a2(id,name,info)values('1','wuhaiming','參加項管考試 ');  #向a2表插入一條記錄
Query OK, 1 row affected, 1 warning (0.07 sec)

mysql> select * from a2;
+----+-----------+--------+
| id | name      | info   |
+----+-----------+--------+
|  1 | wuhaiming | ?????? |
+----+-----------+--------+
1 row in set (0.00 sec)

mysql> select  id from a2;
+----+
| id |
+----+
|  1 |
+----+
1 row in set (0.00 sec)

mysql> insert into a2 values(2,'a2','sky9890');
Query OK, 1 row affected (0.04 sec)

mysql> select * from a2;
+----+-----------+---------+
| id | name      | info    |
+----+-----------+---------+
|  1 | wuhaiming | ??????  |
|  2 | a2        | sky9890 |
+----+-----------+---------+
2 rows in set (0.00 sec)

mysql> insert into a2(id,name)values('','whm');
Query OK, 1 row affected, 1 warning (0.06 sec)

mysql> select * from a2;
+----+-----------+---------+
| id | name      | info    |
+----+-----------+---------+
|  1 | wuhaiming | ??????  |
|  2 | a2        | sky9890 |
|  3 | whm       | NULL    |
+----+-----------+---------+
3 rows in set (0.00 sec)

mysql> describe a2;
+-------+------------------+------+-----+---------+----------------+
| Field | Type             | Null | Key | Default | Extra          |
+-------+------------------+------+-----+---------+----------------+
| id    | int(10) unsigned | NO   | PRI | NULL    | auto_increment |
| name  | char(40)         | NO   |     |         |                |
| info  | char(200)        | YES  |     | NULL    |                |
+-------+------------------+------+-----+---------+----------------+
3 rows in set (0.00 sec)

mysql> insert into a2 values('','a6','sky9890'),('','a7',);#插入一條記錄
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 ')' at line 1
mysql> insert into a2 values('','a6','sky9890'),('','a7','sky'); #連續插入兩條記錄
Query OK, 2 rows affected, 2 warnings (0.17 sec)
Records: 2  Duplicates: 0  Warnings: 2

mysql> select * from a2;
+----+-----------+---------+
| id | name      | info    |
+----+-----------+---------+
|  1 | wuhaiming | ??????  |
|  2 | a2        | sky9890 |
|  3 | whm       | NULL    |
|  4 | a6        | sky9890 |
|  5 | a7        | sky     |
+----+-----------+---------+
5 rows in set (0.00 sec)

mysql> describe a1;
+-------+---------+------+-----+---------+-------+
| Field | Type    | Null | Key | Default | Extra |
+-------+---------+------+-----+---------+-------+
| id    | int(11) | YES  |     | NULL    |       |
+-------+---------+------+-----+---------+-------+
1 row in set (0.00 sec)

mysql> describe a2;
+-------+------------------+------+-----+---------+----------------+
| Field | Type             | Null | Key | Default | Extra          |
+-------+------------------+------+-----+---------+----------------+
| id    | int(10) unsigned | NO   | PRI | NULL    | auto_increment |
| name  | char(40)         | NO   |     |         |                |
| info  | char(200)        | YES  |     | NULL    |                |
+-------+------------------+------+-----+---------+----------------+
3 rows in set (0.00 sec)

mysql> select * from a1;
Empty set (0.00 sec)

mysql> insert into a1(id) select id from a2;
Query OK, 5 rows affected (0.06 sec)
Records: 5  Duplicates: 0  Warnings: 0

mysql> select * from a1;
+------+
| id   |
+------+
|    1 |
|    2 |
|    3 |
|    4 |
|    5 |
+------+
5 rows in set (0.00 sec)

mysql> select * from a2;
+----+-----------+---------+
| id | name      | info    |
+----+-----------+---------+
|  1 | wuhaiming | ??????  |
|  2 | a2        | sky9890 |
|  3 | whm       | NULL    |
|  4 | a6        | sky9890 |
|  5 | a7        | sky     |
+----+-----------+---------+
5 rows in set (0.00 sec)

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| a                  |
| back20150625ultrax |
| cacti              |
| cacti20151220      |
| cacti20160104      |
| feifeicms          |
| mysql              |
| performance_schema |
| phpcom             |
| study              |
| syslog             |
| test               |
| test1              |
| tt                 |
| ultrax             |
+--------------------+
16 rows in set (0.00 sec)

mysql> drop database b; #刪除b數據庫
ERROR 1008 (HY000): Can't drop database 'b'; database doesn't exist
mysql> show tables;
+-------------+
| Tables_in_a |
+-------------+
| a1          |
| a2          |
+-------------+
2 rows in set (0.00 sec)

mysql> drop tables  a1;#刪除a1表
Query OK, 0 rows affected (0.09 sec)

mysql> show tables;
+-------------+
| Tables_in_a |
+-------------+
| a2          |
+-------------+
1 row in set (0.00 sec)

mysql> delete from a2 where id=5 or info='sky'; #刪除一條記錄
Query OK, 1 row affected (0.05 sec)

mysql> select * from a2;
+----+-----------+---------+
| id | name      | info    |
+----+-----------+---------+
|  1 | wuhaiming | ??????  |
|  2 | a2        | sky9890 |
|  3 | whm       | NULL    |
|  4 | a6        | sky9890 |
+----+-----------+---------+
4 rows in set (0.00 sec)

mysql> update a2 set  info='sky' where id=1; #更新一個字段值
Query OK, 1 row affected (0.07 sec)
Rows matched: 1  Changed: 1  Warnings: 0

mysql> select * from a2;
+----+-----------+---------+
| id | name      | info    |
+----+-----------+---------+
|  1 | wuhaiming | sky     |
|  2 | a2        | sky9890 |
|  3 | whm       | NULL    |
|  4 | a6        | sky9890 |
+----+-----------+---------+
4 rows in set (0.00 sec)

mysql> SHOW VARIABLES LIKE 'character%';
+--------------------------+----------------------------+
| Variable_name            | Value                      |
+--------------------------+----------------------------+
| character_set_client     | utf8                       |
| character_set_connection | utf8                       |
| character_set_database   | latin1                     |
| character_set_filesystem | binary                     |
| character_set_results    | utf8                       |
| character_set_server     | latin1                     |
| character_set_system     | utf8                       |
| character_sets_dir       | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+
8 rows in set (0.00 sec)

mysql> SET collation_database = utf8 ;
ERROR 1273 (HY000): Unknown collation: 'utf8'
mysql> set character_set_database=utf8;
Query OK, 0 rows affected (0.00 sec)

mysql> update a2 set  info='吳海明' where id=1;        
Query OK, 1 row affected, 1 warning (0.06 sec)
Rows matched: 1  Changed: 1  Warnings: 1

mysql> select * from a2;
+----+-----------+---------+
| id | name      | info    |
+----+-----------+---------+
|  1 | wuhaiming | ???     |
|  2 | a2        | sky9890 |
|  3 | whm       | NULL    |
|  4 | a6        | sky9890 |
+----+-----------+---------+
4 rows in set (0.00 sec)

mysql> alter table a2 rename a1 #修改表名
    -> ;
Query OK, 0 rows affected (0.06 sec)

mysql> show tables;
+-------------+
| Tables_in_a |
+-------------+
| a1          |
+-------------+
1 row in set (0.00 sec)

mysql> select * from a2;      
ERROR 1146 (42S02): Table 'a.a2' doesn't exist
mysql> select * from a2;
ERROR 1146 (42S02): Table 'a.a2' doesn't exist
mysql> select * from a1;
+----+-----------+---------+
| id | name      | info    |
+----+-----------+---------+
|  1 | wuhaiming | ???     |
|  2 | a2        | sky9890 |
|  3 | whm       | NULL    |
|  4 | a6        | sky9890 |
+----+-----------+---------+
4 rows in set (0.00 sec)

mysql> alter table a1 change info information char(200);#更改字段名
Query OK, 4 rows affected (0.26 sec)
Records: 4  Duplicates: 0  Warnings: 0

mysql> describe a1;
+-------------+------------------+------+-----+---------+----------------+
| Field       | Type             | Null | Key | Default | Extra          |
+-------------+------------------+------+-----+---------+----------------+
| id          | int(10) unsigned | NO   | PRI | NULL    | auto_increment |
| name        | char(40)         | NO   |     |         |                |
| information | char(200)        | YES  |     | NULL    |                |
+-------------+------------------+------+-----+---------+----------------+
3 rows in set (0.00 sec)

mysql> alter table a1 add time date;#在末尾填加列
Query OK, 4 rows affected (0.26 sec)
Records: 4  Duplicates: 0  Warnings: 0

mysql> describe a1;
+-------------+------------------+------+-----+---------+----------------+
| Field       | Type             | Null | Key | Default | Extra          |
+-------------+------------------+------+-----+---------+----------------+
| id          | int(10) unsigned | NO   | PRI | NULL    | auto_increment |
| name        | char(40)         | NO   |     |         |                |
| information | char(200)        | YES  |     | NULL    |                |
| time        | date             | YES  |     | NULL    |                |
+-------------+------------------+------+-----+---------+----------------+
4 rows in set (0.00 sec)

mysql> alter table a1 drop time; #刪除列
Query OK, 4 rows affected (0.26 sec)
Records: 4  Duplicates: 0  Warnings: 0

mysql> describe a1;
+-------------+------------------+------+-----+---------+----------------+
| Field       | Type             | Null | Key | Default | Extra          |
+-------------+------------------+------+-----+---------+----------------+
| id          | int(10) unsigned | NO   | PRI | NULL    | auto_increment |
| name        | char(40)         | NO   |     |         |                |
| information | char(200)        | YES  |     | NULL    |                |
+-------------+------------------+------+-----+---------+----------------+
3 rows in set (0.00 sec)

mysql> alter table a1 add time date first;#插入到第一列
Query OK, 4 rows affected (0.24 sec)
Records: 4  Duplicates: 0  Warnings: 0

mysql> describe a1;                      
+-------------+------------------+------+-----+---------+----------------+
| Field       | Type             | Null | Key | Default | Extra          |
+-------------+------------------+------+-----+---------+----------------+
| time        | date             | YES  |     | NULL    |                |
| id          | int(10) unsigned | NO   | PRI | NULL    | auto_increment |
| name        | char(40)         | NO   |     |         |                |
| information | char(200)        | YES  |     | NULL    |                |
+-------------+------------------+------+-----+---------+----------------+
4 rows in set (0.00 sec)

mysql> select * from a1;
+------+----+-----------+-------------+
| time | id | name      | information |
+------+----+-----------+-------------+
| NULL |  1 | wuhaiming | ???         |
| NULL |  2 | a2        | sky9890     |
| NULL |  3 | whm       | NULL        |
| NULL |  4 | a6        | sky9890     |
+------+----+-----------+-------------+
4 rows in set (0.00 sec)

mysql> alter table a1 add nian year after time;#插入到指定列后
Query OK, 4 rows affected (0.25 sec)
Records: 4  Duplicates: 0  Warnings: 0

mysql> describe a1;
+-------------+------------------+------+-----+---------+----------------+
| Field       | Type             | Null | Key | Default | Extra          |
+-------------+------------------+------+-----+---------+----------------+
| time        | date             | YES  |     | NULL    |                |
| nian        | year(4)          | YES  |     | NULL    |                |
| id          | int(10) unsigned | NO   | PRI | NULL    | auto_increment |
| name        | char(40)         | NO   |     |         |                |
| information | char(200)        | YES  |     | NULL    |                |
+-------------+------------------+------+-----+---------+----------------+
5 rows in set (0.00 sec)

mysql> grant all on cacti.* to 'a1'@'localhost' identified by '123456';#授權
Query OK, 0 rows affected (0.02 sec)

mysql> exit
Bye
mysql> grant create,select on *.* to 
'a2'@'localhost' identified by '123'; #授權
Query OK, 0 rows affected (0.00 sec)
mysql> revoke select on  *.*  from 
'a2'@'localhost'; #撤回權限

 

向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

盐池县| 保靖县| 调兵山市| 永兴县| 蚌埠市| 赤水市| 志丹县| 宁武县| 马公市| 上蔡县| 融水| 荣昌县| 望江县| 临安市| 青神县| 龙泉市| 都江堰市| 金山区| 武穴市| 玛沁县| 山西省| 安图县| 横峰县| 仁化县| 高州市| 兴国县| 湛江市| 富阳市| 铁力市| 义乌市| 瑞安市| 内丘县| 河津市| 墨竹工卡县| 方城县| 枣庄市| 广河县| 衡阳市| 广宗县| 金沙县| 承德市|