1.mysql-5.6.24-win32.zip下载 安装

MySQL官网 点击Downloads(GA)下面的MySQL Server 进入下载页面。


wKiom1Vmq0qipnl4AAZIuNGncZk399.jpg


2.选择Windows 32位。


wKiom1Vmq7uDShLQAAQRxGFNsEA860.jpg


3.下载文件mysql-5.6.24-win32.zip,解压到目录F:\mysql-5.6.24-win32


4.复制my-default.ini 重命名为my.nin


wKioL1VmsQOiG2cIAAKpvLt2Yc4685.jpg


4.1 my-default.ini文件内容为


wKioL1Vm0zewlvYNAAQQ0ZNdvOc610.jpg

4.2 my.ini更改为如下内容


[client]

port=3306

default-character-set=utf8

#客户端字符类型,与服务端一致,建议utf8

[mysqld]

port=3306

character_set_server=utf8

#服务端字符类型,建议utf8

basedir=F:\mysql-5.6.24-win32

#解压根目录

datadir=F:\mysql-5.6.24-win32\data

#解压根目录\data

sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES

[WinMySQLAdmin]

F:\mysql-5.6.24-win32\bin\mysqld.exe 

#解压根目录\bin\mysqld.exe


4.3 my.ini配置信息说明

[client]

default-character-set=utf8       客户端编码方式


basedir 安装目录

datadir 数据文件存放目录    

port 端口


5.运行cmd安装运行MySQL 


5.1 开始——运行——cmd    进入安装目录 F:\mysql-5.6.24-win32\bin

运行mysqld -install,提示安装成功。我的已经安装过所以提示The service already exists!

net start mysql启动MySQL服务


C:\Windows\system32>cd\


C:\>f:


F:\>cd F:\mysql-5.6.24-win32


F:\mysql-5.6.24-win32>cd bin


F:\mysql-5.6.24-win32\bin>mysqld -install

Service successfully installed.


F:\mysql-5.6.24-win32\bin>net start mysql

MySQL 服务正在启动 ...

MySQL 服务已经启动成功。


5.2 修改root密码,初始root密码为空,mysql -u root -p 密码为空。show databases;显示所有表。

use mysql;切换到mysql。进入mysql输入命令以分号结束。


F:\mysql-5.6.24-win32\bin>mysql -u root -p

Enter password:

Welcome to the MySQL monitor.  Commands end with ; or \g.

Your MySQL connection id is 3

Server version: 5.6.24 MySQL Community Server (GPL)


Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.


Oracle is a registered trademark of Oracle Corporation and/or its

affiliates. Other names may be trademarks of their respective

owners.


Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.


mysql> show databases;

+--------------------+

| Database           |

+--------------------+

| information_schema |

| mysql              |

| performance_schema |

| test               |

+--------------------+

4 rows in set (0.01 sec)


mysql> use mysql

Database changed


5.3 修改root密码为123456

mysql>delete from User where User="";

mysql>update User set Password=PASSWORD('newpassword') where User='root';

mysql>FLUSH PRIVILEGES; 

mysql>quit;

FLUSH PRIVILEGES:强制让MySQL重新加载权限,即刻生效

此时登录时可用如下命令:

D:\wamp\mysql\bin>mysql -u root -p

ENTERPASSWORD:newpassword



mysql> delete from User where User="";

Query OK, 1 row affected (0.00 sec)


mysql> update User set Password=PASSWORD('123456') where User='root';

Query OK, 3 rows affected (0.00 sec)

Rows matched: 3  Changed: 3  Warnings: 0


mysql> FLUSH PRIVILEGES;

Query OK, 0 rows affected (0.00 sec)


mysql> quit

Bye

F:\mysql-5.6.24-win32\bin>mysql -u root -p

Enter password: ******

Welcome to the MySQL monitor.  Commands end with ; or \g.

Your MySQL connection id is 4

Server version: 5.6.24 MySQL Community Server (GPL)


Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.


Oracle is a registered trademark of Oracle Corporation and/or its

affiliates. Other names may be trademarks of their respective

owners.


Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.


mysql>


6 创建数据库


6.1 创建一个以feng命名的数据库,编码规则为utf8.进入数据库使用use+数据库名称。


mysql> create database feng character set utf8;

Query OK, 1 row affected (0.00 sec)

mysql> use feng

Database changed

mysql>


6.2 创建数据库表create table 表名称(列声明)

创建一个students表,表中存放学号(id)名字(name)性别(sex)年龄(age)电话(tel)

通过文本编辑器保存为createtable.sql文件,通过命令提示符下的文件重定向执行该脚本,

wKioL1Voag_x6dSTAADxOWAdKmA047.jpg

6.3 将students表保存到feng数据库

F:\mysql-5.6.24-win32\bin>mysql -D feng -u root -p < C:\Users\Administrator\Desk

top\createtable.sql

Enter password: ******


F:\mysql-5.6.24-win32\bin>


id 列的名称

int (-8388608~8388607)

int unsigned (16777125)

not null 说明该列的值不能为空

auto_increment 在整数列中使用,插入数据时若该列为null,MySQL为自动生成一个比现存值更大的唯一标识符值。

primary key 表明该列是表的主键

char(8) 字符长度为8

tinyint 取值范围为(-127~128)


6.4 查询表信息,show tables; describe students;

mysql> show tables;

+----------------+

| Tables_in_feng |

+----------------+

| students       |

+----------------+

1 row in set (0.31 sec)


mysql> describe students;

+-------+---------------------+------+-----+---------+----------------+

| Field | Type                | Null | Key | Default | Extra          |

+-------+---------------------+------+-----+---------+----------------+

| id    | int(10) unsigned    | NO   | PRI | NULL    | auto_increment |

| name  | char(8)             | NO   |     | NULL    |                |

| sex   | char(4)             | NO   |     | NULL    |                |

| age   | tinyint(3) unsigned | NO   |     | NULL    |                |

| tel   | char(13)            | YES  |     | _       |                |

+-------+---------------------+------+-----+---------+----------------+

5 rows in set (0.20 sec)


mysql>


7 向表中插入数据

7.1 insert into 表名 (列表1,列表2,列表3,...)values (值1,值2,值3,...);


mysql> insert into students (id,name,sex,age,tel) values (null,"天天","女","23",

"15623458765");

Query OK, 1 row affected (0.00 s)


insert into students values(NULL, "王刚", "男", 20, "13811371377");


7.2 查询表中数据

select 列名称 from 表名称 [查询条件]

查询students表中所有学生名字和年龄


mysql> select name,age from students;

+-----------+-----+

| name      | age |

+-----------+-----+

| 王刚      |  20 |

| 孙丽华    |  21 |

| 王杰      |  21 |

| 孙丽华    |  21 |

| 问我      |  21 |

| 问我      |  21 |

| 天天      |  23 |

+-----------+-----+

7 rows in set (0.00 sec)


7.3 按特定条件查询

select 列名称 from 表名称 where 条件,查询所有性别为女的信息。

mysql>  select * from students where sex="女";

+----+-----------+-----+-----+-------------+

| id | name      | sex | age | tel         |

+----+-----------+-----+-----+-------------+

|  2 | 孙丽华    | 女  |  21 | _           |

|  3 | 王杰      | 女  |  21 | 14523456789 |

|  4 | 孙丽华    | 女  |  21 | _           |

|  5 | 问我      | 女  |  21 | _           |

|  6 | 问我      | 女  |  21 | _           |

|  7 | 天天      | 女  |  23 | 15623458765 |

+----+-----------+-----+-----+-------------+

6 rows in set (0.00 sec)

where 列名=值 

比较运算符 =,>,<,<=,!=

扩展运算符 is [not] null in like or and


mysql> select * from students where age<23;

+----+-----------+-----+-----+-------------+

| id | name      | sex | age | tel         |

+----+-----------+-----+-----+-------------+

|  1 | 王刚      | 男  |  20 | 13811371377 |

|  2 | 孙丽华    | 女  |  21 | _           |

|  3 | 王杰      | 女  |  21 | 14523456789 |

|  4 | 孙丽华    | 女  |  21 | _           |

|  5 | 问我      | 女  |  21 | _           |

|  6 | 问我      | 女  |  21 | _           |

+----+-----------+-----+-----+-------------+

6 rows in set (0.00 sec)


mysql> select * from students where name like "%王%";

+----+--------+-----+-----+-------------+

| id | name   | sex | age | tel         |

+----+--------+-----+-----+-------------+

|  1 | 王刚   | 男  |  20 | 13811371377 |

|  3 | 王杰   | 女  |  21 | 14523456789 |

+----+--------+-----+-----+-------------+

2 rows in set (0.03 sec)


mysql> select * from students where id<5 and age>20;

+----+-----------+-----+-----+-------------+

| id | name      | sex | age | tel         |

+----+-----------+-----+-----+-------------+

|  2 | 孙丽华    | 女  |  21 | _           |

|  3 | 王杰      | 女  |  21 | 14523456789 |

|  4 | 孙丽华    | 女  |  21 | _           |

+----+-----------+-----+-----+-------------+

3 rows in set (0.04 sec)



7.4 更新表中数据update 表名称 set 列名称=值 where 条件。

mysql> update students set tel=default where id=5;

Query OK, 0 rows affected (0.06 sec)

Rows matched: 1  Changed: 0  Warnings: 0


mysql> update students set tel=default where id=5;

Query OK, 0 rows affected (0.06 sec)

Rows matched: 1  Changed: 0  Warnings: 0


mysql> update students set age=age+1;

Query OK, 7 rows affected (0.05 sec)

Rows matched: 7  Changed: 7  Warnings: 0

mysql> update students set name="华" ,age=19 where tel="14523456789";

Query OK, 1 row affected (0.00 sec)

Rows matched: 1  Changed: 1  Warnings: 0


7.5 删除表中数据

delete from 表数据 where 条件


mysql> delete from students where id=1;

Query OK, 1 row affected (0.04 sec)