MySQL常用命令
2018-06-18 01:07:37来源:未知 阅读 ()
1.创建数据库
命令 create database 数据库名 charset=utf8;
mysql> create database python charset=utf8; Query OK, 1 row affected (0.00 sec)
2.显示数据库
命令 show databases;
mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | | python | +--------------------+ 4 rows in set (0.00 sec)
3.指定数据库
命令 use 数据库名;
mysql> use python; Database changed
4.查看当前使用数据库
命令 select database();
mysql> select database(); +------------+ | database() | +------------+ | python | +------------+ 1 row in set (0.00 sec)
5.删除数据库
命令 drop database 数据库名;
mysql> drop database python; Query OK, 0 rows affected (0.00 sec)
6.创建表
命令 create table 表名(列及类型);
mysql> create table students( -> id int auto_increment primary key not null, -> name varchar(10) not null, -> brithday date not null, -> hobby varchar(20) default 'MySQL'); Query OK, 0 rows affected (0.19 sec)
auto_increment表示自动增长
7.显示表
命令 show tables;
mysql> show tables; +-------------------+ | Tables_in_python1 | +-------------------+ | students | +-------------------+ 1 row in set (0.00 sec)
8.显示字段
命令 desc 表名;
mysql> desc students; +----------+-------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +----------+-------------+------+-----+---------+----------------+ | id | int(11) | NO | PRI | NULL | auto_increment | | name | varchar(10) | NO | | NULL | | | brithday | date | NO | | NULL | | | hobby | varchar(20) | YES | | MySQL | | +----------+-------------+------+-----+---------+----------------+ 4 rows in set (0.01 sec)
9.新增字段
命令 alter table 表名 add 字段;
mysql> alter table students add gender bit default 0;
Query OK, 0 rows affected (0.07 sec)
Records: 0 Duplicates: 0 Warnings: 0
mysql> desc students;
+----------+-------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+----------+-------------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| name | varchar(10) | NO | | NULL | |
| brithday | date | NO | | NULL | |
| hobby | varchar(20) | YES | | MySQL | |
| gender | bit(1) | YES | | b'0' | |
+----------+-------------+------+-----+---------+----------------+
5 rows in set (0.00 sec)
10.添加数据
a.全列插入
命令 insert into 表名 values();
mysql> insert into students values(0,'隔壁老王','1997-4-13','code',1); Query OK, 1 row affected (0.00 sec)
b.缺省插入
命令 insert into 表名(列1,列2,...) values(值1,值2,...);
mysql> insert into students(name,brithday) values('张三','1996-4-13'); Query OK, 1 row affected (0.01 sec)
11.查看内容
命令 select * from 表名;
mysql> select * from students; +----+--------------+------------+-------+--------+ | id | name | brithday | hobby | gender | +----+--------------+------------+-------+--------+ | 1 | 隔壁老王 | 1997-04-13 | code | | | 2 | 张三 | 1996-04-13 | MySQL | | +----+--------------+------------+-------+--------+ 2 rows in set (0.00 sec)
12.修改表
命令 update 表名 set 列1=值1 where 条件;
mysql> update students set hobby='打飞机' where id=1; Query OK, 1 row affected (0.01 sec) Rows matched: 1 Changed: 1 Warnings: 0 mysql> select * from students; +----+--------------+------------+-----------+--------+ | id | name | brithday | hobby | gender | +----+--------------+------------+-----------+--------+ | 1 | 隔壁老王 | 1997-04-13 | 打飞机 | | | 2 | 张三 | 1996-04-13 | MySQL | | +----+--------------+------------+-----------+--------+ 2 rows in set (0.00 sec)
标签:
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有
上一篇:优化mysql
- MySQL replace函数怎么替换字符串语句 2020-03-09
- PHP访问MySQL查询超时怎么办 2020-03-09
- mysql登录时闪退 2020-02-27
- MySQL出现1067错误号 2020-02-27
- mysql7.x如何单独安装mysql 2020-02-27
IDC资讯: 主机资讯 注册资讯 托管资讯 vps资讯 网站建设
网站运营: 建站经验 策划盈利 搜索优化 网站推广 免费资源
网络编程: Asp.Net编程 Asp编程 Php编程 Xml编程 Access Mssql Mysql 其它
服务器技术: Web服务器 Ftp服务器 Mail服务器 Dns服务器 安全防护
软件技巧: 其它软件 Word Excel Powerpoint Ghost Vista QQ空间 QQ FlashGet 迅雷
网页制作: FrontPages Dreamweaver Javascript css photoshop fireworks Flash