MySQL数据库的基本操作演示

数据库 MySQL
此文章主要是向大家讲述的是MySQL数据库的基本操作,如果你是其方面的新手,那么以下的文章对你而言一定很有意义。

以下的文章主要向大家描述的是MySQL数据库的基本操作,提及MySQL数据库我们大家对其可能都会有一定的了解,今天我们就和大家一起讨论一下MySQL数据库的基本操作,望你能有所收获。

登陆数据库

 

D:\phpStudy\MySQL\bin>MySQL -uroot -proot

 

查看数据库

MySQL> show databases;

 

选择数据库

MySQL> use bugfree;

 

设置字符集

MySQL> set names 'gbk';

 

查询数据库中的表

MySQL> show tables;

 

MySQL数据库的基本操作 ;创建表

MySQL> create table test(

 

-> tid int(10) not null,

 

-> tname varchar(100) not null,

 

-> tdate datetime not null default '0000-00-00',

 

-> primary key (tid));

 

查看表结构

MySQL> desc test;

 

添加列

MySQL> alter table test add(tage int(3));

 

修改原表结构

MySQL> alter table test modify tage int(5) not null;

 

修改列的默认值

MySQL> alter table test alter tage set default '0';

 

去掉列的默认值

MySQL> alter table test alter tage drop default;

 

删除列

MySQL> alter table test drop column tage;

 

插入数据

MySQL> insert into test(tid,tname,tdate) value(1,'yangjuqi','2008-03-21');

 

查询数据

MySQL> select * from test;

 

模糊查询

MySQL> select * from test where tname like '%杨%';

 

MySQL数据库的基本操作 :修改数据

MySQL> update test set tname='张三' where tid='2';

 

删除数据

MySQL> delete from test where tid='2';

 

删除表

MySQL> drop table test;

 

重命名表

MySQL> alter table test rename testbak;

 

分页查询(limit 起始行,取多少行)

MySQL> select * from testbak limit 2,1;

 

刷新数据库

MySQL> flush privileges;

 

显示数据库版本

MySQL> select version();

 

显示当前时间

MySQL> select current_date;

 

修改用户密码

D:\phpStudy\MySQL\bin>MySQLadmin -uroot -proot password yangjuqi

 

将查询出的数据写入文件

MySQL> select * from testbak into outfile "d:/test.txt" fields terminated by ",";

 

查看数据库状态

MySQL> status;

 

查看所有编码

MySQL> show variables like 'character_set_%';

 

导入sql文件命令

以上的相关内容就是对MySQL数据库的基本操作的介绍,望你能有所收获。

【编辑推荐】

  1. MySQL修改root密码的3种方法介绍
  2. MySQL存储过程中的语法学习
  3. MySQL存储过程中的基本函数描述
  4. MySQL数据库内存调优实操
  5. Python编程语言操作MySQL数据库实战演习
责任编辑:佚名 来源: 博客园
相关推荐

2010-06-12 09:53:19

2010-05-12 18:41:34

MySQL数据库

2019-11-07 15:39:36

数据库MySQL文章

2010-06-09 17:36:45

MySQL数据库同步

2010-06-04 09:33:28

连接MySQL数据库

2010-06-12 17:55:23

MySQL数据库同步

2010-06-04 10:40:55

AJAX MySQL

2010-05-13 14:07:39

MySQL数据库

2010-06-07 16:22:55

MySQL数据库

2010-06-02 11:34:23

MySQL 数据库导入

2010-03-04 13:47:13

Python操作Acc

2010-06-01 14:42:55

连接MySQL数据库

2010-05-25 14:05:52

MySQL数据库

2010-05-25 08:49:33

连接MySQL

2010-05-28 13:21:48

MySQL数据库

2010-05-26 14:24:24

MySQL数据库

2011-06-27 12:56:28

2010-06-01 12:51:23

MySQL数据库

2019-10-21 13:52:14

MySQL数据库命令

2010-06-04 15:32:18

MySQL数据库
点赞
收藏

51CTO技术栈公众号