发布于 2016-01-02 08:55:28 | 204 次阅读 | 评论: 0 | 来源: PHPERZ

这里有新鲜出炉的Mysql教程,程序狗速度看过来!

Mysql关系型数据库管理系统

MySQL是一个开放源码的小型关联式数据库管理系统,开发者为瑞典MySQL AB公司。MySQL被广泛地应用在Internet上的中小型网站中。由于其体积小、速度快、总体拥有成本低,尤其是开放源码这一特点,许多中小型网站为了降低网站总体拥有成本而选择了MySQL作为网站数据库。


数据库启动并进行初始安全设置之后,我们就可以登录数据库了。

登录数据库

[root@bogon ~]# mysql -p

Enter password:                        输入设置的密码

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

Your MySQL connection id is 6

Server version: 5.7.10 MySQL CommunityServer (GPL)

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

Oracle is a registered trademark of OracleCorporation and/or its

affiliates. Other names may be trademarksof their respective

owners.

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

mysql>

创建、删除和查看数据库

创建数据库

语法:create database dbname;

mysql> create database xiaowei;

Query OK, 1 row affected (0.02 sec)

删除数据库

语法:drop database dbname;

mysql> drop database xiaowei;

Query OK, 0 rows affected (0.07 sec)

查看数据库

mysql> show databases;

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

| Database           |

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

| information_schema |

| mysql              |

| performance_schema |

| sys                |

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

4 rows in set (0.05 sec)

选择要操作的数据库

mysql> use xiaowei;

Database changed

创建表

mysql> create table t1(

   -> id int,

   -> name varchar(20)

   -> );

Query OK, 0 rows affected (0.04 sec)

删除表

mysql> drop table t1;

Query OK, 0 rows affected (0.04 sec)

查看表

mysql> show tables;

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

| Tables_in_xiaowei |

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

| t1                |

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

1 row in set (0.00 sec)

查看数据表结构

语法:desc  tablename;

mysql> desc t1;

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

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

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

| id   | int(11)     | YES  |     | NULL   |       |

| name | varchar(20) | YES  |     | NULL   |       |

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

2 rows in set (0.08 sec)

详细查看数据表结构

语法:show create table tablename;

语法:show create table t1\G; 格式化输出

mysql> show create table t1\G;

*************************** 1. row***************************

      Table: t1

Create Table: CREATE TABLE `t1` (

 `id` int(11) DEFAULT NULL,

 `name` varchar(20) DEFAULT NULL

) ENGINE=InnoDB DEFAULT CHARSET=latin1

1 row in set (0.00 sec)

ERROR:

No query specified

插入数据

Insert into t1 set

Id=1,

Name=’tube’

;

批量插入数据 

mysql> Insert into t1 values(2,'kevin'),(3,'mark');

Query OK, 2 rows affected (0.00 sec)

Records: 2 Duplicates: 0  Warnings: 0

查看表中的数据

mysql> select * from t1;

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

| id  | name  |

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

|   1 | NULL  |

|   1 | xiaon |

|   2 | kevin |

|   3 | mark  |

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

4 rows in set (0.00 sec)



最新网友评论  共有(0)条评论 发布评论 返回顶部

Copyright © 2007-2017 PHPERZ.COM All Rights Reserved   冀ICP备14009818号  版权声明  广告服务