sql创建数据库,表以及增删查改命令的使用

sql创建数据库,表以及增删查改命令的使用

1.首先在kali上打开mysql

输入:
/etc/init.d/mysql start 
mysql

2.创建数据库aaa(名称自定义但不能为数字)

输入:
create database aaa;

通过show命令看到现在的database里多了一个名字叫aaa的表

MariaDB [(none)]> show databases;
+--------------------+
| Database           |
+--------------------+
| aaa                |
| information_schema |
| mysql              |
| performance_schema |
+--------------------+
4 rows in set (0.001 sec)

3.使用mysql数据库查看表

输入:
use mysql;
show tables;

查看结果如下图:

MariaDB [(none)]> use mysql;
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 [mysql]> show tables;
+---------------------------+
| Tables_in_mysql           |
+---------------------------+
| column_stats              |
| columns_priv              |
| db                        |
| event                     |
| func                      |
| general_log               |
| gtid_slave_pos            |
| help_category             |
| help_keyword              |
| help_relation             |
| help_topic                |
| host                      |
| index_stats               |
| innodb_index_stats        |
| innodb_table_stats        |
| plugin                    |
| proc                      |
| procs_priv                |
| proxies_priv              |
| roles_mapping             |
| servers                   |
| slow_log                  |
| table_stats               |
| tables_priv               |
| time_zone                 |
| time_zone_leap_second     |
| time_zone_name            |
| time_zone_transition      |
| time_zone_transition_type |
| transaction_registry      |
| user                      |
+---------------------------+
31 rows in set (0.001 sec)

4. 创建表users

输入:
create table users (username varchar(255) ,password varchar(255));

创建结果为:

Query OK, 0 rows affected (0.044 sec)

现在这个表中没有字段值,我们需要往表中加一些值

5.添加字段值

添加格式为:insert into 表名(列1,列2) values(‘值1’,‘值2’)
列数可以加可以不加

输入:
insert into users  values(‘admin’,‘123456’);

显示结果为:

Query OK, 1 row affected (0.002 sec)

我们来看下现在的表长什么样子了
这里使用了命令

select * from users; #星号在这里即是全部的意思

MariaDB [mysql]> select * from users;
+----------+----------+
| username | password |
+----------+----------+
| admin    | 123456   |
+----------+----------+
1 row in set (0.001 sec)

6.多添加两条以备后续增删

此处重复上述操作
得到的结果为:

MariaDB [mysql]> select * from users;
+----------+----------+
| username | password |
+----------+----------+
| admin    | 123456   |
| baekhyun | 920506   |
+----------+----------+
2 rows in set (0.000 sec)

7.更新命令

格式:update 表名 set 列名=‘新值’ where 列名=‘某值’;
不加where表中数据会全部更改,后果很严重!请加上限制条件!

update users set password='asdfghjkl' where username='admin';
#或者update users set password='asdfghjkl' where password='123456';

更改结果为:

MariaDB [mysql]> select * from users;
+----------+-----------+
| username | password  |
+----------+-----------+
| admin    | asdfghjkl |
| baekhyun | 920506    |
+----------+-----------+

8.删除命令
格式:delete from 表名 where 列名=‘某值’;
不加where表中数据会全部更改,后果很严重!请加上限制条件!

delete from users where username='baekhyun';

删除后的结果为

MariaDB [mysql]> select * from users;
+----------+-----------+
| username | password  |
+----------+-----------+
| admin    | asdfghjkl |
+----------+-----------+
1 row in set (0.000 sec)

此篇文章仅为个人学习过程所作笔记,有任何错误欢迎指正

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值