1.首先从mysql.com下载mysql-noinstall-5.1.47-win32.zip,解压到e:\mysql5.1目录下.
2.设置系统环境变量,方便便在cmd命令行中使用mysql.  环境变量设置:右键单击桌面我的电脑,属性->高级->环境变量->双击 Path项,添加e:\mysql5.1\bin目录,如果要使用SDK开发,则要添加Lib和include目录到对应的Lib和include 环境变量中.
3.安装mysql服务(最好cmd在e:\mysql5.1\bin目录下):mysqld -install
4.启动服务 net start mysql,这样就可以在mysql下工作了.不需要用的时候可以用以下命令:    停止服务 net stop mysql     删除服务 mysqld -remove
5.打开一个CMD窗口,执行MySQL -h localhost回车,就可以看到 { Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 5 Server version: 5.1.40-community MySQL Community Server (GPL) Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. } 表示成功连接到MySQL了数据库了,接下来,可以查看数据库.
6.连接mysql  格式: mysql -h主机地址 -u用户名 -p用户密码  例1:连接到本机上的mysql  mysql -uroot -p  例2:连接到远程主机上的mysql  mysql -h110.110.110.110 -uroot -pabcd123
7.退出mysql命令  exit(回车)  或者  quit(回车)
8.修改密码  格式:mysqladmin -u用户名 -p旧密码 password 新密码  例:给root加个密码ab12。首先在dos下进入目录mysqlbin,然后键入以下命令  mysqladmin -uroot password ab12  注:因为开始时root没有密码,所以-p旧密码一项就可以省略了。  例2:再将root的密码改为djg345。  mysqladmin -uroot -pab12 password djg345
9.增加新用户  格式:grant select on 数据库.* to 用户名@登录主机 identified by "密码";  例1、增加一个用户test1密码为abc,让他可以在任何主机上登录, 并对所有数据库有查询、插入、修改、删除的权限。首先用以root用户连入mysql,然后键入以下命令:  grant select?insert?update?delete on *.* to test1@"%" identified by "abc";
(注意,这里test1还不能再localhost中登陆,还要键入一个命令:  grant select?insert?update?delete on *.* to test1@localhost identified by "abc";)
例2、增加一个用户test2密码为abc?让其只可以在localhost上登录, 并可以对数据库mydb进行查询、插入、修改、删除的操作(localhost指本地主机, 即mysql数据库所在的那台主机),这样用户即使用知道test2的密码,也无法从internet上直接访问数据库,只能通过mysql主机上的web页来访问了。  grant select?insert?update?delete on mydb.* to test2@localhost identified by "abc";
注:还有一种增加新用户并分配权限的方式:  MySql 新建用户,新建数据库,用户授权,删除用户,修改密码    1.新建用户。  //登录MYSQL   @>mysql -u root -p   @>密码  //创建用户  mysql> insert into mysql.user(Host,User,Password,ssl_cipher,x509_issuer,x509_subject) values("localhost","pppadmin",password("passwd"),'','','');   这样就创建了一个名为:phplamp 密码为:1234 的用户。  然后登录一下。  mysql>exit;   @>mysql -u phplamp -p   @>输入密码   mysql>登录成功   2.为用户授权。   //登录MYSQL(有ROOT权限)。我里我以ROOT身份登录.   @>mysql -u root -p   @>密码  //首先为用户创建一个数据库(phplampDB)   mysql>create database phplampDB;   //授权phplamp用户拥有phplamp数据库的所有权限。  >grant all privileges on phplampDB.* to phplamp@localhost identified by '1234';   刷新系统权限表   mysql>flush privileges;   mysql>其它操作  /* 如果想指定部分权限给一用户,可以这样来写:   mysql>grant select,update on phplampDB.* to phplamp@localhost identified by '1234';   //刷新系统权限表。  mysql>flush privileges; */   3.删除用户。  @>mysql -u root -p   @>密码  mysql>Delete FROM user Where User="phplamp" and Host="localhost";   mysql>flush privileges;   //删除用户的数据库   mysql>drop database phplampDB;   4.修改指定用户密码。  @>mysql -u root -p   @>密码  mysql>update mysql.user set password=password('新密码') where User="phplamp" and Host="localhost";   mysql>flush privileges;
10.显示数据库列表  show databases;
11.显示库中的数据表  use mysql;//数据库名称  show tables;
12.显示数据表的结构  describe 表名;
13.建库  create database 库名;
14.建表  use 库名;  create table 表名(字段设定列表);
15.删库和删表   drop database 库名;   drop table 表名;
16.将表中记录清空  delete from 表名;
17.显示表中的记录  select * from 表名;   例:  drop database if exists school; //如果存在school则删除   create database school; //建立库school   use school; //打开库school  create table teacher //建立表teacher  (   id int(3) auto_increment not null primary key?  name char(10) not null?  address varchar(50) default '深圳'?  year date  ); //建表结束   //以下为插入字段   insert into teacher values(''?'glchengang'?'深圳一中'?'1976-10-10');  insert into teacher values(''?'jack'?'深圳一中'?'1975-12-23');
注:在建表中  (1) 将id设为长度为3的数字字段:int(3),并让它每个记录自动加一: auto_increment, 并不能为空:not null,而且让它成为主字段primary key  (2) 将name设为长度为10的字符字段  (3) 将address设为长度50的字符字段,而且缺省值为深圳。varchar和char有什么区别呢,只有等以后的文章再说了。   (4) 将year设为日期字段。  如果你在mysql提示符键入上面的命令也可以,但不方便调试。 你可以将以上命令原样写入一个文本文件中假设为school.sql,然后复制到c:下,并在dos状态进入目录mysql in,然后键入以下命令:  mysql -uroot -p密码 < c:school.sql  如果成功,空出一行无任何显示;如有错误,会有提示。(以上命令已经调试,你只要将//的注释去掉即可使用)。
18.将文本数据转到数据库中   1、 文本数据应符合的格式:字段数据之间用tab键隔开,null值用来代替。例:   3 rose 深圳二中 1976-10-10   4 mike 深圳一中 1975-12-23   2、 数据传入命令load data local infile "文件名" into table 表名;   注意:你最好将文件复制到mysql in目录下,并且要先用use命令选表所在的库。
19.导出和导入数据   a、导出表   mysqldump --opt school > school.sql   注释:将数据库school中的表全部备份到school.sql文件,school.sql是一个文本文件, 文件名任取,打开看看你会有新发现。  mysqldump --opt school teacher student > school.teacher.student.sql  注释:将数据库school中的teacher表和student表备份到school.teacher.student.sql文件,school.teacher.student.sql是一个文本文件,文件名任取,打开看看你会有新发现。  b、导入表   mysql   mysql>create database school;   mysql>use school;  mysql>source school.sql;  (或将school.sql换为school.teacher.sql / school.teacher.student.sql)  c、导出数据库   mysqldump --databases db1 db2 > db1.db2.sql   注释:将数据库dbl和db2备份到db1.db2.sql文件,db1.db2.sql是一个文本文件,文件名任取,打开看看你会有新发现。  (举个例子:  mysqldump -h host -u user -p pass --databases dbname > file.dump   就是把host上的以名字user,口令pass的数据库dbname导入到文件file.dump中。)  d、导入数据库   mysql < db1.db2.sql  e、复制数据库   mysqldump --all-databases > all-databases.sql   注释:将所有数据库备份到all-databases.sql文件,all-databases.sql是一个文本文件, 文件名任取。  f、导入数据库  mysql  mysql>drop database a;   mysql>drop database b;  mysql>drop database c;   ...  mysql>source all-databases.sql; (或exit退出mysql后 mysql < all-databases.sql)
20.创建一个可以从任何地方连接服务器的一个完全的超级用户,但是必须使用一个口令something做这个  grant all privileges on *.* to monty@"%" identified by 'something' with grant option;
21.删除授权  revoke all privileges on *.* from root@"%";  use mysql;  delete from user where user="root" and host="%";  flush privileges;  22.创建一个用户custom在特定客户端weiqiong.com登录,可访问特定数据库bankaccount   mysql> grant select?insert?update?delete?create?drop on bankaccount.*  to custom@weiqiong.com identified by 'stupid';
23.重命名表  alter table t1 rename t2;
24.改变列  为了改变列a,从integer改为tinyint not null(名字一样),并且改变列b,从char(10)改为char(20),同时重命名它,从b改为c:  alter table t2 modify a tinyint not null? change b c char(20);
25.增加列  增加一个新timestamp列,名为d:   alter table t2 add d timestamp;
26.在列d上增加一个索引,并且使列a为主键   alter table t2 add index (d)? add primary key (a);
27.删除列   alter table t2 drop column c;
28.删除记录   delete from t1 where c>10;
29.改变某几行  update t1 set user=weiqiong?password=weiqiong;
30.创建索引  使用name列的头10个字符创建一个索引:   create index part_of_name on customer (name(10));