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

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

MySQL数据库的基本操作演示(MySQL数据库基本操作)  MySQL数据库 第1张

登陆数据库

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数据库实战演习
转载请说明出处
知优网 » MySQL数据库的基本操作演示(MySQL数据库基本操作)

发表评论

您需要后才能发表评论