标签:
1.链接数据库
C:\>mysql -hlocalhost -uroot -p //按enter后,会提示输入密码,若密码为空直接enter
C:\>mysql --help
C:\>mysqladmin -uroot -p password //按照提示修改密码,密码不填就表示为密码为空
2.数据库操作(创建数据库school_db,其下创建数据表students)
create database school_db;
show databases;
use database school_db;
select database();
show tables;
drop database;
3.数据表操作
create table students(
id int unsigned not null auto_increment primary key,
name char(8) not null,
sex char(4) not null,
age tinyint unsigned not null,
tel char(13) null default "-"
);
insert into students values(NULL,‘Tom‘,‘man‘,22,‘13249076325‘);
insert into students (name,sex) values(‘Lucy‘,‘woman‘);
select * from students;
select * from students where name like "%L%";
select * from students where id<5 and age>20;
select * from students order by id limit 0,2;
update students set tel=default where id=5;
update students set name="Jack",age=age+1 where id=1;
delete from students;
delete from students where id=2
4.创建后表的修改:
alter table students add address char(60);
alter table students add birthday after age;
alter table students change tel telphone char(13) default "-";
alter table students change name name char(16) not null;
alter table students drop birthday;
alter table students rename workmates;
alter table students rename my_db.students; //把表移动到数据库my_db下面,并命名为students
drop table workmates;
drop database school_db;
5.导出导入数据库和数据表
C:\>mysqldump -uroot school_db > E:\school_db.sql;
C:\>mysqldump -uroot school_db students > E:\school_db_students.sql;
C:\>mysql -uroot -D school_db < E:/school_db.sql; // 用最下面的source
C:\>mysqldump -uroot school_db < E:/school_db.sql; // 将数据库导入到数据库中
C:\>mysqldump -uroot school_db < E:/school_db_students.sql; // 将数据表导入到数据库中
mysql>use school_db;
myslq>source E:/school_db.sql;
标签:
原文地址:http://www.cnblogs.com/htmlphp/p/5096658.html