标签:family nbsp format def character 开发 窗口 实体 ext
【注" "】命名
使用命令窗口链接MySQL数据库:
Window+R打开运行输入cmd;
mysql -u用户名 -p 回车后填写密码; 【注意:空格区分】
数据库服务器、数据库和表的关系:
所谓数据库服务器, 是指在机器上装了一个数据库管理程序,这个管理程序可以管理多个数据库,一般开发人员会针对每一个应用创建一个数据库。
为保存应用中实体的数据,一般会在数据库创建多个表,以保存程序中实体的数据。
数据库的管理:
查询所有数据库 show databases;
mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | java0512 | | mysb1 | | mysql | | performance_schema | | test | +--------------------+ 6 rows in set (0.00 sec)
创建数据库 create database " " " " 自定义名称;
character set " " 指定数据库采用的字符集;
mysql> create database mysb2 character set utf8; Query OK, 1 row affected (0.00 sec)
显示数据库创建:show create database " ";
mysql> show create database mysb2; +----------+----------------------------------------------------------------+ | Database | Create Database | +----------+----------------------------------------------------------------+ | mysb2 | CREATE DATABASE `mysb2` /*!40100 DEFAULT CHARACTER SET utf8 */ | +----------+----------------------------------------------------------------+ 1 row in set (0.00 sec)
数据库删除:drop database " ";
mysql> drop database mysb2; Query OK, 0 rows affected (0.00 sec)
修改数据库:alter database " " character set utf8;
mysql> alter database mysb1 character set utf8; Query OK, 1 row affected (0.00 sec)
表管理:
选择数据库: use " ";
查看所有表:show tables;
mysql> use mysb1; Database changed mysql> show tables; +-----------------+ | Tables_in_mysb1 | +-----------------+ | yuangong | +-----------------+ 1 row in set (0.00 sec)
创建表:create table " "(指定数据类型); 创建表前,要先使用use 语句使用库
mysql> create table student(id varchar(20),sage int); Query OK, 0 rows affected (0.00 sec)
查看表结构:desc " ";
mysql> desc student; +-------+-------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +-------+-------------+------+-----+---------+-------+ | id | varchar(20) | YES | | NULL | | | sage | int(11) | YES | | NULL | | +-------+-------------+------+-----+---------+-------+ 2 rows in set (0.00 sec)
删除表:drop table " ";
mysql> drop table student; Query OK, 0 rows affected (0.01 sec)
修改表:
1.)添加字段 alert table " " add column " " varchar();
mysql> alter table student add column sgender varchar(20); Query OK, 0 rows affected (0.01 sec) Records: 0 Duplicates: 0 Warnings: 0
2.)删除字段alter table " " drop column " ";
mysql> alter table student drop column sgender; Query OK, 0 rows affected (0.01 sec) Records: 0 Duplicates: 0 Warnings: 0
3.)修改字段类型 alter table " " modify column id varchar(50);
mysql> alter table student modify column id varchar(50); Query OK, 0 rows affected (0.01 sec) Records: 0 Duplicates: 0 Warnings: 0
4.)修改字段昵称 alter table " " change column id name varchar(50);
mysql> alter table student change column id name varchar(50); Query OK, 0 rows affected (0.01 sec) Records: 0 Duplicates: 0 Warnings: 0
5.)修改表名称 alter table " " rename to teacher;
mysql> alter table student rename to teacher; Query OK, 0 rows affected (0.01 sec)
标签:family nbsp format def character 开发 窗口 实体 ext
原文地址:https://www.cnblogs.com/wode007/p/13141538.html