这是自己在网上收集和自己平时使用的一下命令和语句(适合新手学习),如有不对还请大家指出来
转载请注明(http://blog.csdn.net/u012169499/article/details/41908375)
一.mysql(请注意命令之间存在空格)
如果需要远程连接数据库:
--改表。可能是你的帐号不允许从远程登陆,只能在localhost。这个时候只要在localhost的那台电脑,登入mysql后,更改 "mysql" 数据库里的 "user" 表里的 "host" 项,从"localhost"改称"%"
mysql -u root -padmin
mysql>use mysql;
mysql>update user set host = '%' where user = 'root';
mysql>select host, user from user;
--授权。例如,你想newuser使用newpassword从任何主机连接到mysql服务器的话。
GRANT ALL PRIVILEGES ON *.* TO 'newuser'@'%' IDENTIFIED BY 'newpassword' WITH GRANT OPTION;
如果你想允许用户newuser从ip为192.168.1.3的主机连接到mysql服务器,并使用newpassword作为密码
GRANT ALL PRIVILEGES ON *.* TO 'newuser'@'192.168.1.3' IDENTIFIED BY 'newpassword' WITH GRANT OPTION;
--在window自带的防火墙里的例外添加3306端口
mysql -uroot -padmin //以权限用户root登录
mysql>use mysql; //选择mysql库
mysql>select 'host' from user where user='root'; //查看mysql库中的user表的host值(即可进行连接访问的主机/IP名称)
mysql>update user set host = '%' where user ='root'; //修改host值,也可以直接增加IP地址
mysql>flush privileges; //刷新MySQL的系统权限相关表
mysql>select 'host' from user where user='root';
重新启动mysql服务即可完成。
cmd命令启动/关闭数据库:net start/stop mysql
打开mysql进入到命令行:mysql -u+用户名 -p+密码
首先我们在test数据库中来创建一个简单的user表:
use test;//使用test数据库
drop table if exists user;//如果存在user表就删除user表
create table user(
uid int primary key auto_increment,
uname varchar(8) not null,
sex char(2) default '男'
);
show tables from test; //查看所有表
desc user / show columns from user; //两者都能查看表结构
1.增加列(alter table + 表名 + add 列名 列类型 列参数):
例:alter table user add birth date not null default '0000-00-00';
插入列默认是表最后。如果想要指定插入列位置,则需要关键字first,after
alter table user add age int not null default '0' first /after uid;
2.修改列(
①alter table + 表名 + modify + 列名 + 新列类型 + 新列参数 (只修改类型和参数);
②alter table + 表名 + change + 旧列名 + 新列名 + 新列类型 + 新列参数(修改列名,类型和参数);
):
例: ① alter table user modify age varchar(2) not null;
② alter table user change age info text;
3.删除列(alter table + 表名 + drop + 列名):
例: alter table user drop info;
4.查看创建代码(show create table + 表名):
例: show create table user;
二.oracle
cmd命令启动/关闭监听器: lsnrctl start/stop
cmd命令启动/关闭服务:net start/stop oracleserviceorcl
oracle数据库导入导出详见:oracle导出命令
登录oracle:sqlplus system/root 若输入sqlplus /nolog(则就是不登录数据库服务器)
切换用户:(需要在sqlplus环境)connect system/root
创建表空间:
create tablespace demo
datafile 'e:\test.dbf'
size 5m autoextend on;
创建用户:
create user jie
identified by jie
default tablespace demo;
删除用户:
drop user jie cascade;
给用户授权:
grant connect,resource to jie;
grant create view to jie;
grant create sequence to jie;
创建user表:
create table man(
user_id int primary key ,
uname varchar2(10) not null,
sex char(3) default '男'
);
查看表结构:desc+空格+表名 :
desc man;
创建序列:
create sequence seq_user_id;
插入数据:
insert into man(user_id,uname) values(seq_user_id.nextval,'mark');
commit;
查看当前sequence的计数值:
select seq_user_id.currval from man;
获取当前sequence的下个计数值:
select seq_user_id.nextval from man;
主键的删除