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)
此篇文章仅为个人学习过程所作笔记,有任何错误欢迎指正