MySQL使用笔记
基本操作
start mysql
stop mysql
登陆mysql:mysql –h localhost –u root –proot
退出:QUIT
获得mysql的版本号:select version();
获得当前系统的时间:select current_date;(年月日)
获得当前系统时间:select now();(年月日时分秒)
获得当前登陆的用户信息:select user();
数据库操作
显示当前服务器上的数据库:show databases;(mysql数据库描述用户的访问权限)
改变但前使用的数据库:use databaseName;
创建数据库:create database databaseName;
获得当前使用的数据库:select database();
导入外部sql脚本:source ***.sql
导出sql脚本:mysqldump databasename > d:/ –u root -p
表操作
创建表:create table tableName();
显示当前数据库下的所有表:show tables;
查看表的详细信息:Describe(desc) tableName;
设置自增主键:id int unsigned not null auto_increment (在向表中插入数据时,必须使用default才能产生自动增长的数据,也可以自己任意输入数据,比较灵活)
添加列:alter table table_name add age int not null/ alter table table_name add(test char(10));
修改列:alter table table_name modify test char(20) not null
删除列:alter table table_name drop column test
添加约束:
主键:alter table table_name add constraint pk_id primary key (列名);
删除主键:alter table table_name drop primary key;
唯一约束qunique(column_name)
检查约束check();
默认约束:alter table table_name alter age set default 18
删除默认约束:alter table table_name alter test drop default;
添加外键约束:alter table table_name2 add constraint fk_uid foreign key(uid) references table_name1(key);
向表中插入数据(2中):
使用insert into tableName values()
使用load data local infile ‘/e:/’ into table tableName;这种方式将记事本中的数据添加在mysql数据库指定的表中(可以插入多行)
插入多行:insert into tableNam
MySQL使用 来自淘豆网m.daumloan.com转载请标明出处.