一、数据库的安装 1、查询数据库是否有安装包 rpm -qa|grep mysql
2、删除已经存在的数据库 (1)第一种方法:yum remove mysql * 删除linux种的数据库 (2)第二种方法:rpm -e --nodeps 包名 删除linux种的数据库 (3)第三种方法:yum erase 包名 删除linux种的数据库
3、安装数据库 (1)安装mysql数据库客户端 yum install mysql (2)在线安装mysql数据库服务端 yum install mysql-server  4、对数据库服务的操作(要使用就要开启数据库) service mysqld status 查看数据库服务状态 service mysqld start 开启数据库 service msyqld restart 重启数据库 service msyqld stop 关闭数据库
5、设置初始密码: mysqladmin -u root password ‘123456’  6、进入数据库操作界面 mysql -u root -p 在敲回车 输入密码
 7、显示所有的数据库 show databases;  8、新建一个数据库: create database 数据库名 案例:create database dcs  9、drop database 数据库名 删除数据库 案例:drop database hs ;  10、use 库名 使用数据库 案例:use dcs ;
 11、 show tables 显示数据库中所有的表  12、数据库中退出界面到linux中; (1)ctrl+z 退出; (2)ctrl+c 退出; (3) \q退出 (4)exit 退出 (5)quit退出
13、数据库授权: (1)授权: grant all privileges on . to root@‘%’ identified by ‘123456’ 
(2)刷新权限 flush privileges ;  14、创建表基本结构 格式: create table 表名( 字段名1 字符类型(字符长度), 字符名2 字符类型(字符长度)); 案例: create table gs1(id int(20),name char(20),age int(20)); 
15、字符类型: (1)数据类型 a、int 类型 字节数:4 b、float 浮点数 字节数 :4 c、bigint 字符数:8  (2)字符类型 char 字符 范围 0-255 varchar 字符范围 0-65535  (3)时间类型
a、time 时间 b、year 年 c、datetime 年月日,时分秒 d、date 年月日
 16、约束 定义:约束用于表中字段进行限制,保证表中数据的正确性和唯一性。 1、primary key 主键约束 非空、唯一、用于唯一标识对应的记录。 一个表中只有一个主键约束,不能为空,唯一。 
2、 unique 唯一索引 保证字段值具有唯一性,并且能为空,一个表中开源有多个唯一索引 案例:create table gs2(id int(10)primary , age int(10) unique, name char(10) not null , fs int(10) default 60 ); 唯一的: 
3、not null 非空约束 案例:create table gs2(id int(10)primary , age int(10) unique, name char(10) not null , fs int(10) default 60 );
4、default 默认值 定义:默认给字段指定默认值 案例:create table gs2(id int(10)primary , age int(10) unique, name char(10) not null , fs int(10) default 60 ); 
5、auto_increment 自增长
案例:create table gs3(id int(10)primary key auto_increment , age int(10) unique, name char(10) not null , fs int(10) default 60 );

17、desc 查看表结构 格式:desc 表名; 案例:desc gs1; 
18、 插入表中数据: (1)插入数据方法一: 格式: inser into 表名 values (数值1,数值2,数值3) ; 备注:数值不用引号,字符类型,时间等需要用引号 案例:insert into gs1 values(1,‘wy’,‘18’);  (2)插入数据方法二:(部分数) 格式: inser into 表名 (字段1,字段2 ) values (数值1,数值2) ; 案例:insert into gs1(id, name) values(1,‘jx’);
19、查询语句: 格式:select * from 表名 案例:select * from gs1 ;  20、default charset=utf8 
二、安装navicat:
1、下载navicat包  2、解压包:

3、点击下图 4、点击注册  5、密钥: NAVH-WK6A-DMVK-DKW3
6、复制注册码,激活  7、表示安装成功  8、创建快捷方式:  9、桌面显示navicat的快捷方式  10、 配置链接参数 
11、打开sql编辑界面 
连接中出现问题: 1、防火墙是否关闭 service iptables stop 2、数据库是否开启 service mysqld start 3、授权还要刷新 grant all privileges on . to root@‘%’ identified by ‘123456’ 刷新: flush privileges ; 4、ip地址是否正确 确定数据库在那个ip上,ip是否有变化 5、账号和密码是否正确
========================== 作业: student 学生表 
删除表:
格式:drop table 表名; 案例:DROP TABLE gs1 ;

|