MySQL操作手记

启动服务器: mysqld -- console

停止服务器: mysqladmin -u root shutdown

连接服务器: mysql - h host -u user -p (mysql 127.0.0.1 -u willem -p)

断开: quit

增加数据库: create database wil091028

表增加列: alter table tablename add column cname ctype

设列为主键: add primary key (c)

创建表: create table pet (name VARCHAR(20) , owner VARCHAR(20))

自增编号: creat table 'database'.'table' ( 'id' int unsigned not null auto_increatent primary key, ... )

保存表和列信息的表: information_schema.tables information_schema.columns

创建用户: grant all privileges on *.* to 'monty'@"local host' identified by 'some_pass' with grant option

grant all privileges on *.* to 'monty'@'%' dentified by 'some_pass' with grant option

 

数据导入: mysqlimport --localhost --user=wil --password=091028 db file.txt

 

数据导出: mysqldump -u willem -p dbname tbname > d:/users.sql

 

添加列: alter table 'users' add 'cname' text not null

 

修改列: alter table 'tbname' modify column 'fieldname' varchar(14)

 

删除列: alter table tbname drop column cname

 

改列名: alter table tbname change oldcname newcname text not null

 

改表名: rename table oldtbname to newtbname

 

建外键: alter table tbname add constraint fk_name foregin key (cname) reference tbname(id) on delete restriction update restrict

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值