2.给数据库的root管理员账户设置密码123,再修改成1234

[root@NaNaQi ~]# mysql -uroot

Welcome to the MariaDB monitor. Commands end with ; or \g.

Your MariaDB connection idis 10Server version:10.3.11-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)]> set password = password('123'); #这里的password是加密

Query OK,0 rows affected (0.002sec)

MariaDB [(none)]> Ctrl-C -- exit!Aborted

验证

[root@NaNaQi~]# mysql -uroot -p

Enter password:

Welcome to the MariaDB monitor. Commands end with ; or \g.

Your MariaDB connection idis 11Server version:10.3.11-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)]>修改密码

[root@NaNaQi~]# mysql -uroot -p

Enter password:

Welcome to the MariaDB monitor. Commands end with ; or \g.

Your MariaDB connection idis 12Server version:10.3.11-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)]> alter user root@localhost identified by '1234';

Query OK,0 rows affected (0.001sec)

MariaDB [(none)]>quit

Bye

3.安全初始化数据库,更改root密码为12345

[root@NaNaQi ~]# mysql_secure_installation

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB

SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!In order to log into MariaDB to secure it, we'll need the current

password for the root user. If you've just installed MariaDB, and

you haven't set the root password yet, the password will be blank,

so you should just press enter here.

Enter current passwordfor root (enter fornone):

OK, successfully used password, moving on...

Setting the root password ensures that nobody can log into the MariaDB

root user without the proper authorisation.

You already have a root passwordset, so you can safely answer 'n'.

Change the root password? [Y/n] y #修改root密码?New password:

Re-enter newpassword:

Password updated successfully!Reloading privilege tables..

... Success!Bydefault, a MariaDB installation has an anonymous user, allowing anyone

to log into MariaDB without having to have a user account createdforthem. Thisis intended only fortesting, and to make the installation

go a bit smoother. You should remove them before moving into a

production environment.

Remove anonymous users? [Y/n] y #删除匿名用户?... Success!Normally, root should only be allowed to connectfrom 'localhost'. This

ensures that someone cannot guess at the root passwordfromthe network.

Disallow root login remotely? [Y/n] n #禁止root远程登录?... skipping.

Bydefault, MariaDB comes with a database named 'test'that anyone can

access. Thisis also intended only fortesting, and should be removed

before moving into a production environment.

Remove test database and access to it? [Y/n] y #删除测试数据库并访问它?

-Dropping test database...

... Success!

-Removing privileges on test database...

... Success!Reloading the privilege tables will ensure that all changes made so far

will take effect immediately.

Reload privilege tables now? [Y/n] y #现在重新加载特权表吗?... Success!Cleaning up...

All done! If you've completed all of the above steps, your MariaDB

installation should now be secure.

Thanksfor using MariaDB!

4.用两种方法查看数据库

MariaDB [(none)]>show databases;+--------------------+

| Database |

+--------------------+

| information_schema |

| mysql |

| performance_schema |

+--------------------+

3 rows in set (0.000sec)

MariaDB [(none)]>quit

Bye

[root@NaNaQi~]# mysql -uroot -p12345 -e 'show databases;'

+--------------------+

| Database |

+--------------------+

| information_schema |

| mysql |

| performance_schema |

+--------------------+

5.创建数据库school之后再删除

MariaDB [(none)]> create database ifnot exists school;

Query OK,0 rows affected, 1 warning (0.000sec)

MariaDB [(none)]>show databases;+--------------------+

| Database |

+--------------------+

| information_schema |

| mysql |

| performance_schema |

| school |

+--------------------+

4 rows in set (0.000sec)

MariaDB [(none)]> drop database ifexists school;

Query OK,0 rows affected (0.001sec)

MariaDB [(none)]>show databases;+--------------------+

| Database |

+--------------------+

| information_schema |

| mysql |

| performance_schema |

+--------------------+

3 rows in set (0.001 sec)

6.创建数据库school,在其里面创建表student,表里面有id,name,age,使用desc命令查看表 student数据。

MariaDB [(none)]>create database school;

Query OK,1 row affected (0.000sec)

MariaDB [(none)]>use school;

Database changed

MariaDB [school]>show tables;

Emptyset (0.000sec)

MariaDB [school]> create table student(id int not null,name varchar(50)null,age tinyint);

Query OK,0 rows affected (0.002sec)

MariaDB [school]>show tables;+------------------+

| Tables_in_school |

+------------------+

| student |

+------------------+

1 row in set (0.000sec)

MariaDB [school]>desc student;+-------+-------------+------+-----+---------+-------+

| Field | Type | Null | Key | Default | Extra |

+-------+-------------+------+-----+---------+-------+

| id | int(11) | NO | | NULL | |

| name | varchar(50) | YES | | NULL | |

| age | tinyint(4) | YES | | NULL | |

+-------+-------------+------+-----+---------+-------+

3 rows in set (0.001 sec)

7.修改表student,插入班级class,之后再删除age一行,最后删除表student。

MariaDB [school]> alter table student add class varchar(20);

Query OK,0 rows affected (0.002sec)

Records:0 Duplicates: 0 Warnings: 0MariaDB [school]>desc student;+-------+-------------+------+-----+---------+-------+

| Field | Type | Null | Key | Default | Extra |

+-------+-------------+------+-----+---------+-------+

| id | int(11) | NO | | NULL | |

| name | varchar(50) | YES | | NULL | |

| age | tinyint(4) | YES | | NULL | |

| class | varchar(20) | YES | | NULL | |

+-------+-------------+------+-----+---------+-------+

4 rows in set (0.001sec)

MariaDB [school]>alter table student drop age;

Query OK,0 rows affected (0.005sec)

Records:0 Duplicates: 0 Warnings: 0MariaDB [school]>desc student;+-------+-------------+------+-----+---------+-------+

| Field | Type | Null | Key | Default | Extra |

+-------+-------------+------+-----+---------+-------+

| id | int(11) | NO | | NULL | |

| name | varchar(50) | YES | | NULL | |

| class | varchar(20) | YES | | NULL | |

+-------+-------------+------+-----+---------+-------+

3 rows in set (0.001sec)

MariaDB [school]>drop table student;

Query OK,0 rows affected (0.038sec)

MariaDB [school]>show tables;

Emptyset (0.000 sec)

8.授权主机,与192.168.44.129登录数据库的所有数据库与所有表,权限为所有权限,用户为root,密码为12345

MariaDB [school]> grant all on *.* to 'root'@'192.168.27.149' identified by '12345';Query OK, 0 rows affected (0.002sec)

MariaDB [school]> grant all on *.* to 'root'@'192.168.44.129' identified by '12345';

Query OK,0 rows affected (0.001 sec)

9.查看root用户在的192.168.27.149的权限,并取消root用户的192.168.44.129的授权

MariaDB [school]> show grants for 'root'@'192.168.44.129';+-------------------------------------------------------------------------------------------------

| Grants for root@192.168.44.129

+------------------------------------------------------------------------------------------------

| GRANT SELECT, INSERT, UPDATE, CREATE, DROP, RELOAD, SHUTDOWN, PROCESS, FILE, REFERENCES, INDEX, ALTER, SHOW DATABASES, SUPER, CREATE TEMPORARY TABLES, LOCK TABLES, EXECUTE, REPLICATION SLAVE, REPLICATION CLIENT, CREATE VIEW, SHOW VIEW, CREATE ROUTINE, ALTER ROUTINE, CREATE USER, EVENT, TRIGGER, CREATE TABLESPACE, DELETE VERSIONING ROWS ON *.* TO 'root'@'192.168.44.129' IDENTIFIED BY PASSWORD '*00A51F3F48415C7D4E8908980D443C29C69B60C9' |

+-------------------------------------------------------------------------------------------------

1 row in set (0.000 sec)

10.在school数据库中创建表student,在其中先单次插入一条数据,再连续插入五条数据。表student包含id,name,age。

MariaDB [school]>use school;

Database changed

MariaDB [school]> create table student (id int not null,name varchar(50),age tinyint);

Query OK,0 rows affected (0.039sec)

MariaDB [school]>show tables;+------------------+

| Tables_in_school |

+------------------+

| student |

+------------------+

1 row in set (0.001sec)

MariaDB [school]>desc student;+-------+-------------+------+-----+---------+-------+

| Field | Type | Null | Key | Default | Extra |

+-------+-------------+------+-----+---------+-------+

| id | int(11) | NO | | NULL | |

| name | varchar(50) | YES | | NULL | |

| age | tinyint(4) | YES | | NULL | |

+-------+-------------+------+-----+---------+-------+

3 rows in set (0.001sec)

MariaDB [school]> insert into student values(1,'tom',15);

Query OK,1 row affected (0.001sec)

MariaDB [school]> select * fromstudent;+----+------+------+

| id | name | age |

+----+------+------+

| 1 | tom | 15 |

+----+------+------+

1 row in set (0.001sec)

MariaDB [school]> insert into student values(2,'zhangshan',20),(3,'lisi',18),(4,'wangwu',20),(5,'zhaosan',13),(6,'qianliu',14);

Query OK,5 rows affected (0.001sec)

Records:5 Duplicates: 0 Warnings: 0MariaDB [school]> select * fromstudent;+----+-----------+------+

| id | name | age |

+----+-----------+------+

| 1 | tom | 15 |

| 2 | zhangshan | 20 |

| 3 | lisi | 18 |

| 4 | wangwu | 20 |

| 5 | zhaosan | 13 |

| 6 | qianliu | 14 |

+----+-----------+------+

6 rows in set (0.000 sec)

11.创建表teacher,设置id为主键且自动增长。(只有主键才能设置自动增长)

MariaDB [school]> create table teacher(id int not null primary key auto_increment,name varchar(20) not null,age tinyint,salary float);

Query OK,0 rows affected (0.004sec)

MariaDB [school]>desc teacher;+--------+-------------+------+-----+---------+----------------+

| Field | Type | Null | Key | Default | Extra |

+--------+-------------+------+-----+---------+----------------+

| id | int(11) | NO | PRI | NULL | auto_increment |

| name | varchar(20) | NO | | NULL | |

| age | tinyint(4) | YES | | NULL | |

| salary | float | YES | | NULL | |

+--------+-------------+------+-----+---------+----------------+

4 rows in set (0.001 sec)

12.往表teacher里插入三条数据,再往表teacher里连续插入多条数据。(需指定插入数据的字段)

MariaDB [school]> insert into teacher values(1,'chengsongling',21,4000);

Query OK,1 row affected (0.001sec)

MariaDB [school]> insert into teacher values(2,'chengsongling',21,4000);

Query OK,1 row affected (0.001sec)

MariaDB [school]> insert into teacher values(3,'taochi',21,4000);

Query OK,1 row affected (0.001sec)

MariaDB [school]> select * fromteacher;+----+---------------+------+--------+

| id | name | age | salary |

+----+---------------+------+--------+

| 1 | chengsongling | 21 | 4000 |

| 2 | chengsongling | 21 | 4000 |

| 3 | taochi | 21 | 4000 |

+----+---------------+------+--------+

3 rows in set (0.000sec)

MariaDB [school]> insert into teacher(name,age,salary) values('meijianbiao',30,9000),('mufeng',23,5000),('fangxinxin',24,10000),('leichen',21,10000),('yuqinhao',50,100000),('tanghaolun',10,10000);

Query OK,6 rows affected (0.001sec)

Records:6 Duplicates: 0 Warnings: 0MariaDB [school]> select * fromteacher;+----+---------------+------+--------+

| id | name | age | salary |

+----+---------------+------+--------+

| 1 | chengsongling | 21 | 4000 |

| 2 | chengsongling | 21 | 4000 |

| 3 | taochi | 21 | 4000 |

| 4 | meijianbiao | 30 | 9000 |

| 5 | mufeng | 23 | 5000 |

| 6 | fangxinxin | 24 | 10000 |

| 7 | leichen | 21 | 10000 |

| 8 | yuqinhao | 50 | 100000 |

| 9 | tanghaolun | 10 | 10000 |

+----+---------------+------+--------+

9 rows in set (0.000 sec)

13.修改表teacher中的数据,先把id为9的那行数据年龄改成35,再把年龄改成30,工资改成50000。

MariaDB [school]> update teacher set age = 35 where id = 9;

Query OK,1 row affected (0.001sec)

Rows matched:1 Changed: 1 Warnings: 0MariaDB [school]> select * fromteacher;+----+---------------+------+--------+

| id | name | age | salary |

+----+---------------+------+--------+

| 1 | chengsongling | 21 | 4000 |

| 2 | chengsongling | 21 | 4000 |

| 3 | taochi | 21 | 4000 |

| 4 | meijianbiao | 30 | 9000 |

| 5 | mufeng | 23 | 5000 |

| 6 | fangxinxin | 24 | 10000 |

| 7 | leichen | 21 | 10000 |

| 8 | yuqinhao | 50 | 100000 |

| 9 | tanghaolun | 35 | 10000 |

+----+---------------+------+--------+

9 rows in set (0.001sec)

ariaDB [school]> update teacher set age = 30,salary = 50000 where id = 9;

Query OK,1 row affected (0.003sec)

Rows matched:1 Changed: 1 Warnings: 0MariaDB [school]> select * fromteacher;+----+---------------+------+--------+

| id | name | age | salary |

+----+---------------+------+--------+

| 1 | chengsongling | 21 | 4000 |

| 2 | chengsongling | 21 | 4000 |

| 3 | taochi | 21 | 4000 |

| 4 | meijianbiao | 30 | 9000 |

| 5 | mufeng | 23 | 5000 |

| 6 | fangxinxin | 24 | 10000 |

| 7 | leichen | 21 | 10000 |

| 8 | yuqinhao | 50 | 100000 |

| 9 | tanghaolun | 30 | 50000 |

+----+---------------+------+--------+

9 rows in set (0.001 sec)

14.查找teacher表name与salary一项,再给name设置显示的别名为姓名,给salary设置显示的别名为薪资。

MariaDB [school]> select name,salary fromteacher;+---------------+--------+

| name | salary |

+---------------+--------+

| chengsongling | 4000 |

| chengsongling | 4000 |

| taochi | 4000 |

| meijianbiao | 9000 |

| mufeng | 5000 |

| fangxinxin | 10000 |

| leichen | 10000 |

| yuqinhao | 100000 |

| tanghaolun | 50000 |

+---------------+--------+

9 rows in set (0.001sec)

MariaDB [school]> select name as '姓名',salary as '薪资' fromteacher;+---------------+--------+

| 姓名 | 薪资 |

+---------------+--------+

| chengsongling | 4000 |

| chengsongling | 4000 |

| taochi | 4000 |

| meijianbiao | 9000 |

| mufeng | 5000 |

| fangxinxin | 10000 |

| leichen | 10000 |

| yuqinhao | 100000 |

| tanghaolun | 50000 |

+---------------+--------+

9 rows in set (0.000 sec)

15.先查找薪资为50000的数据的姓名,再查找薪资大于8000的所有记录,最后查找年龄再25到30之间的记录。

MariaDB [school]> select name from teacher where salary = 50000;+------------+

| name |

+------------+

| tanghaolun |

+------------+

1 row in set (0.000sec)

MariaDB [school]> select * from teacher where salary > 8000;+----+-------------+------+--------+

| id | name | age | salary |

+----+-------------+------+--------+

| 4 | meijianbiao | 30 | 9000 |

| 6 | fangxinxin | 24 | 10000 |

| 7 | leichen | 21 | 10000 |

| 8 | yuqinhao | 50 | 100000 |

| 9 | tanghaolun | 30 | 50000 |

+----+-------------+------+--------+

5 rows in set (0.001sec)

MariaDB [school]> select * from teacher where age between 25 and 30;+----+-------------+------+--------+

| id | name | age | salary |

+----+-------------+------+--------+

| 4 | meijianbiao | 30 | 9000 |

| 9 | tanghaolun | 30 | 50000 |

+----+-------------+------+--------+

2 rows in set (0.001 sec)

16.查找表teacher中以c开头的姓名的记录,再查找以ing结尾的姓名的记录,最后再查找以ing结尾或ao结尾的姓名的记录。

MariaDB [school]> select * from teacher where name like 'c%';+----+---------------+------+--------+

| id | name | age | salary |

+----+---------------+------+--------+

| 1 | chengsongling | 21 | 4000 |

| 2 | chengsongling | 21 | 4000 |

+----+---------------+------+--------+

2 rows in set (0.000sec)

MariaDB [school]> select * from teacher where name like '%ing';+----+---------------+------+--------+

| id | name | age | salary |

+----+---------------+------+--------+

| 1 | chengsongling | 21 | 4000 |

| 2 | chengsongling | 21 | 4000 |

+----+---------------+------+--------+

2 rows in set (0.000sec)

MariaDB [school]> select * from teacher where name like '%ing' or name like '%ao';+----+---------------+------+--------+

| id | name | age | salary |

+----+---------------+------+--------+

| 1 | chengsongling | 21 | 4000 |

| 2 | chengsongling | 21 | 4000 |

| 4 | meijianbiao | 30 | 9000 |

| 8 | yuqinhao | 50 | 100000 |

+----+---------------+------+--------+

4 rows in set (0.000 sec)

17.往表teacher里插入两条数据,再增加一行字段为department,默认为空,再把id为11的数据的department改为空格。

MariaDB [school]> insert teacher(name,age,salary) values('yanchuang',80,null),('chenben',69,0);

Query OK,2 rows affected (0.001sec)

Records:2 Duplicates: 0 Warnings: 0MariaDB [school]> select * fromteacher;+----+---------------+------+--------+

| id | name | age | salary |

+----+---------------+------+--------+

| 1 | chengsongling | 21 | 4000 |

| 2 | chengsongling | 21 | 4000 |

| 3 | taochi | 21 | 4000 |

| 4 | meijianbiao | 30 | 9000 |

| 5 | mufeng | 23 | 5000 |

| 6 | fangxinxin | 24 | 10000 |

| 7 | leichen | 21 | 10000 |

| 8 | yuqinhao | 50 | 100000 |

| 9 | tanghaolun | 30 | 50000 |

| 10 | yanchuang | 80 | NULL |

| 11 | chenben | 69 | 0 |

+----+---------------+------+--------+

11 rows in set (0.000sec)

MariaDB [school]> alter table teacher add department varchar(50) null;

Query OK,0 rows affected (0.001sec)

Records:0 Duplicates: 0 Warnings: 0MariaDB [school]> select * fromteacher;+----+---------------+------+--------+------------+

| id | name | age | salary | department |

+----+---------------+------+--------+------------+

| 1 | chengsongling | 21 | 4000 | NULL |

| 2 | chengsongling | 21 | 4000 | NULL |

| 3 | taochi | 21 | 4000 | NULL |

| 4 | meijianbiao | 30 | 9000 | NULL |

| 5 | mufeng | 23 | 5000 | NULL |

| 6 | fangxinxin | 24 | 10000 | NULL |

| 7 | leichen | 21 | 10000 | NULL |

| 8 | yuqinhao | 50 | 100000 | NULL |

| 9 | tanghaolun | 30 | 50000 | NULL |

| 10 | yanchuang | 80 | NULL | NULL |

| 11 | chenben | 69 | 0 | NULL |

+----+---------------+------+--------+------------+

11 rows in set (0.000sec)

MariaDB [school]> update teacher set department = ' ' where id = 11;

Query OK,1 row affected (0.001sec)

Rows matched:1 Changed: 1 Warnings: 0MariaDB [school]> select * fromteacher;+----+---------------+------+--------+------------+

| id | name | age | salary | department |

+----+---------------+------+--------+------------+

| 1 | chengsongling | 21 | 4000 | NULL |

| 2 | chengsongling | 21 | 4000 | NULL |

| 3 | taochi | 21 | 4000 | NULL |

| 4 | meijianbiao | 30 | 9000 | NULL |

| 5 | mufeng | 23 | 5000 | NULL |

| 6 | fangxinxin | 24 | 10000 | NULL |

| 7 | leichen | 21 | 10000 | NULL |

| 8 | yuqinhao | 50 | 100000 | NULL |

| 9 | tanghaolun | 30 | 50000 | NULL |

| 10 | yanchuang | 80 | NULL | NULL |

| 11 | chenben | 69 | 0 | |

+----+---------------+------+--------+------------+

11 rows in set (0.000 sec)

18.查找表teacher中dapartment数据不为空的数据。(数据中null等于空,空白不等于空)

MariaDB [school]> select * from teacher where department is not null;+----+---------+------+--------+------------+

| id | name | age | salary | department |

+----+---------+------+--------+------------+

| 11 | chenben | 69 | 0 | |

+----+---------+------+--------+------------+

1 row in set (0.000 sec)

19.先在表teacher里按age升序排列,再按salary降序排列。

MariaDB [school]> select * fromteacher order by age;+----+---------------+------+--------+------------+

| id | name | age | salary | department |

+----+---------------+------+--------+------------+

| 1 | chengsongling | 21 | 4000 | NULL |

| 2 | chengsongling | 21 | 4000 | NULL |

| 3 | taochi | 21 | 4000 | NULL |

| 7 | leichen | 21 | 10000 | NULL |

| 5 | mufeng | 23 | 5000 | NULL |

| 6 | fangxinxin | 24 | 10000 | NULL |

| 4 | meijianbiao | 30 | 9000 | NULL |

| 9 | tanghaolun | 30 | 50000 | NULL |

| 8 | yuqinhao | 50 | 100000 | NULL |

| 11 | chenben | 69 | 0 | |

| 10 | yanchuang | 80 | NULL | NULL |

+----+---------------+------+--------+------------+

11 rows in set (0.000sec)

MariaDB [school]> select * fromteacher order by salary desc;+----+---------------+------+--------+------------+

| id | name | age | salary | department |

+----+---------------+------+--------+------------+

| 8 | yuqinhao | 50 | 100000 | NULL |

| 9 | tanghaolun | 30 | 50000 | NULL |

| 6 | fangxinxin | 24 | 10000 | NULL |

| 7 | leichen | 21 | 10000 | NULL |

| 4 | meijianbiao | 30 | 9000 | NULL |

| 5 | mufeng | 23 | 5000 | NULL |

| 1 | chengsongling | 21 | 4000 | NULL |

| 3 | taochi | 21 | 4000 | NULL |

| 2 | chengsongling | 21 | 4000 | NULL |

| 11 | chenben | 69 | 0 | |

| 10 | yanchuang | 80 | NULL | NULL |

+----+---------------+------+--------+------------+

11 rows in set (0.000 sec)

20.先删除表teacher中工资为空的数据,再删除department不为空的数据。最后删除整个表teacher的数据。(使用delete命令删除,表依然会存在,且会保留表结构)

MariaDB [school]> delete from teacher where salary is null;

Query OK,1 row affected (0.050sec)

MariaDB [school]> select * fromteacher;+----+---------------+------+--------+------------+

| id | name | age | salary | department |

+----+---------------+------+--------+------------+

| 1 | chengsongling | 21 | 4000 | NULL |

| 2 | chengsongling | 21 | 4000 | NULL |

| 3 | taochi | 21 | 4000 | NULL |

| 4 | meijianbiao | 30 | 9000 | NULL |

| 5 | mufeng | 23 | 5000 | NULL |

| 6 | fangxinxin | 24 | 10000 | NULL |

| 7 | leichen | 21 | 10000 | NULL |

| 8 | yuqinhao | 50 | 100000 | NULL |

| 9 | tanghaolun | 30 | 50000 | NULL |

| 11 | chenben | 69 | 0 | |

+----+---------------+------+--------+------------+

10 rows in set (0.035sec)

MariaDB [school]> delete from teacher where department is not null;

Query OK,1 row affected (0.001sec)

MariaDB [school]> select *fromteacher;+----+---------------+------+--------+------------+

| id | name | age | salary | department |

+----+---------------+------+--------+------------+

| 1 | chengsongling | 21 | 4000 | NULL |

| 2 | chengsongling | 21 | 4000 | NULL |

| 3 | taochi | 21 | 4000 | NULL |

| 4 | meijianbiao | 30 | 9000 | NULL |

| 5 | mufeng | 23 | 5000 | NULL |

| 6 | fangxinxin | 24 | 10000 | NULL |

| 7 | leichen | 21 | 10000 | NULL |

| 8 | yuqinhao | 50 | 100000 | NULL |

| 9 | tanghaolun | 30 | 50000 | NULL |

+----+---------------+------+--------+------------+

9 rows in set (0.000sec)

MariaDB [school]> delete fromteacher;

Query OK,9 rows affected (0.001sec)

MariaDB [school]> select * fromteacher;

Emptyset (0.000sec)

MariaDB [school]>show tables;+------------------+

| Tables_in_school |

+------------------+

| student |

| teacher |

+------------------+

2 rows in set (0.000 sec)

21.再往teacher表里插入数据,会发现id还在顺延,使用truncate可以彻底删除。之后插入数据会发现id重新开始计数。(使用truncate删除的话数据无法恢复)

MariaDB [school]> insert teacher(name,age,salary) values('tom',20,8000),('jerry',23,6000),('zhangsan',22,9000);

Query OK,3 rows affected (0.001sec)

Records:3 Duplicates: 0 Warnings: 0MariaDB [school]> select * fromteacher;+----+----------+------+--------+------------+

| id | name | age | salary | department |

+----+----------+------+--------+------------+

| 12 | tom | 20 | 8000 | NULL |

| 13 | jerry | 23 | 6000 | NULL |

| 14 | zhangsan | 22 | 9000 | NULL |

+----+----------+------+--------+------------+

3 rows in set (0.000sec)

MariaDB [school]>truncate teacher;

Query OK,0 rows affected (0.008sec)

MariaDB [school]> select * fromteacher;

Emptyset (0.000sec)

MariaDB [school]> insert teacher(name,age,salary) values('tom',20,8000),('jerry',23,6000),('zhangsan',22,9000);

Query OK,3 rows affected (0.001sec)

Records:3 Duplicates: 0 Warnings: 0MariaDB [school]> select * fromteacher;+----+----------+------+--------+------------+

| id | name | age | salary | department |

+----+----------+------+--------+------------+

| 1 | tom | 20 | 8000 | NULL |

| 2 | jerry | 23 | 6000 | NULL |

| 3 | zhangsan | 22 | 9000 | NULL |

+----+----------+------+--------+------------+

3 rows in set (0.001 sec)

mysql 1280_mysql基础相关推荐

  1. 那些值得回味的MySQL的基础知识

    那些值得回味的MySQL的基础知识 MySQL零碎知识点整理 题记: 在如今甚是流行的MySQL中有些基础的知识却是我们日常工作中处理问题容易忘却的一部分,所以不能忘了本,那么我们现在就去回忆那些曾经 ...

  2. concat mysql sql注入_sql注入-mysql注入基础及常用注入语句

    最近在教学中,关于SQL注入,总发现学生理解起来有些难度,其实主要的原因是对各类数据库以及SQL语句不熟悉,今天先介绍mysql注入需要掌握的基础, Mysql内置information_schema ...

  3. php大牛额城战笔记,PHP语言大牛开发笔记(8)——MySQL数据库基础回顾[2]

    本文主要向大家介绍了PHP语言大牛开发笔记(8)--MySQL数据库基础回顾[2],通过具体的实例向大家展示,希望对大家学习php语言有所帮助. 一.数据表 为了确保数据的完整性和一致性,在创建表时指 ...

  4. mysql opti_MySQL基础操作

    查看帮助:? 关键词 如 ? trigger 一.Mysql常用基础操作 1.mysql表复制 1) create table t2 like t1;   --复制表结构,t2与t1表结构一致 2) ...

  5. 1.0 MySQL数据库基础知识

    MySQL数据库基础知识 MYSQL介绍 MySQL分支版本的发展 MySQL. Oracle. SQLServer的市场区别 MYSQL数据库使用上的结构 MYSQL体系架构图 MYSQL体系架构- ...

  6. Mysql常用基础命令操作实战

    目录 一    启动与关闭MySQL    3 1.1    单实例MySQL启动与关闭方法    3 ※1※    常规启动关闭数据库方式(推荐)    3 1.2    多实例MySQL启动与关闭 ...

  7. MySQL数据库基础(五)——SQL查询

    MySQL数据库基础(五)--SQL查询 一.单表查询 1.查询所有字段 在SELECT语句中使用星号""通配符查询所有字段 在SELECT语句中指定所有字段 select fro ...

  8. mysql数据库基础的简单操作指南

    最近在学习mysql,本文是做的关于mysql学习的笔记,跟大家分享一下,希望对大家学习mysql知识有所助益.mysql现在几乎已经成了网站建设的主流数据库,很多php网站系统都采用了mysql数据 ...

  9. 【笔记】MySQL的基础学习(二)

    [笔记]MySQL的基础学习(二) MySQL 老男孩  一 视图 视图其实就是给表起个别名 1.创建视图 格式:CREATE VIEW 视图名称 AS SQL语句 CREATE VIEW v1 AS ...

最新文章

  1. 《Unity着色器和屏幕特效开发秘笈》—— 3.4 创建BlinnPhong高光类型
  2. I.MX6 GPS JNI HAL register init hacking
  3. 笔记:猎头如何在一周之内“摸清”一个行业
  4. SAP 导出 HTML,【我sap这导出数据表格export.mhtml怎么转换为 excel 工作表.xlsx】excel生成html表格数据...
  5. 1777亿重罚,苹果瑟瑟发抖!
  6. CTF SQL注入知识点
  7. 解决 googel 无法直接跳转网页打开搜索结果
  8. 基于加速度计与气压计的三阶卡尔曼滤波计算加速度、速度及高度
  9. Python基础语言学习 day 6 ——列表的遍历、增删改、相关操作、函数和方法
  10. 计算机显示器是指什么,电脑的显示器是什么 选购显示器的小技巧
  11. php中文搜索工具,Laravel 下 TNTSearch+jieba-PHP 实现中文全文搜索
  12. python如何压缩pdf_PDF怎么压缩?,懂得这些技巧就够了
  13. 【FS96生物医学工程学】生物医学工程复试问题
  14. 大学四年学习生活成长总结
  15. 阿里云服务器登陆宝塔
  16. C语言函数大全-- m 开头的函数(1)
  17. 杭电ACM 1000题
  18. 使用 FFmpeg 开发播放器基础--使用 ffmpeg 解码视频文件
  19. ASA广告投放之关键词的选择
  20. resin配置文件的详细解释

热门文章

  1. VS2015静态编译libcurl(C++ curl封装类)
  2. LNK1146: 没有用选项“/LIBPATH:”指定的参数
  3. python ord()与chr()用法以及区别
  4. 判断是否Ajax请求
  5. The SDK Build Tools revision (23.0.3) is too low for project ':app'. Minimum required is 25.0.0
  6. c语言普通变量间接访问,C语言学习笔记-指针
  7. cuda 安装_win10+VS 2017 安装 CUDA(Visual Studio Integration失败)
  8. flask之url_for()函数解析
  9. nginx的4个学习资料
  10. libevent 获取多线程结构体变量加锁方法