CentOS7 MySQL基础

一、安装

yum -y install mariadb-server mariadb 

二、启动

systemctl start mariadb

三、数据库操作

1.查看数据库:> show databases; (注意分号“;”不要落下)

2.新建一个数据库命令:> create database 数据库名称; 

  删除一个数据库命令:> drop database 数据库名称; 

3.使用某个数据库:> use 数据库名称;

四、表操作

1.查看表命令:> show tables;

2.建立一个新表:> create table 表名 (字段参数); 或 >create table if not exists 表名(字段参数);

   删除一个旧表:> drop table 表名; 或 >drop table if exists 表名;

3.查看表结构:> desc 表名称; 或 >show columns from 表名称;

4.对表数据的操作:

   增:>insert into 表名称 (字段名1,字段名2,字段名3......) values(字段名1的值,字段名2的值,字段名3的值......);

   删:>delete from 表名称 where 表达式;

   改:>update 表名称 set 字段名=“新值” where 表达式;

   查:>select 字段名1,字段名2,字段名3..... from 表名称;

5.增加字段:>alter table 表名称 add 字段名 数据类型 其它; (其它包括默认初始值的设定等等)

6.删除字段:>alter table 表名称 drop 字段名;

7.更改字段:>alter table 表名称 change 原字段名 新字段名(其它包括默认初始值的设定等等);

8.更改表名:>alter table 表名称 rename 表新名称; 或 rename table 表名称 to 表名称;

 

#约束

#是在表上强制执行地数据校验规则,主要用于保证数据库地完整性
/*

not null

unique 唯一键tb_depttb_dept

primary key

foreign key 外键

check 检查

auto_increment

*/

 

重置密码:

use mysql;

update user set password = password("123456") where user = "root";

flush privileges;

exit;

 

#killall -TERM mysqld

#systemctl start mariadb

 

posted @ 2019-02-19 15:05  弗拉宾教头  阅读(213)  评论(0编辑  收藏  举报