查看默认的编码格式:
show variables like "%char%";
修改编码格式:
set ... utf8
查看数据库编码:
show create database emp;
查看数据表编码:
show create table student;
登录:
mysql -uroot -p
远程登录:
mysql -h 10.19.3.62 -uUSERNAME -pPASSWORD;
修改密码:
update user set PASSWORD=PASSWORD('newPWD') where USER='root' and HOST=‘localhost';
显示数据库:
show databases;
选择数据库:
use dbName;
显示所有表:
show tables;
显示employees表的列信息:
describe employees;
修改表名:
alter table employees rename emp;
备份数据库:
mysqldump -uroot -p dbName > backup_file
eg:mysqldump -uroot -p emp > D:emp_backup_20120715.sql
恢复数据库:
若没有数据库,要先创建一个,然后再恢复
create database jspdev; mysqldump -uroot -p emp < D:emp_backup_20120715.sql
创建表:
create table student (id int not null auto_increment,name varchar(20) not null,primary key PK_positon(id));
清空表:
delete from student;
删除表:
drop table student;
表增加一列:
alter table student add(address varchar(20) );
表修改列:
alter talbe student modify address varchar(20) not null;
表删除列:
alter table student drop column address;
表去掉主键:
alter table student drop primary key;
向表中插入数据:
insert into student(id,name) values('3','Jack'); insert into student (id,name) values('4','Tom');
修改表内容:将tom改为Tom
update student set name='Tom' where name='tom';