Centos7 使用mariadb数据库mysql

安装mariadb数据库

使用yum install mariadb*进行安装,遇到输入的地方就按Y;安装完成后可以开启数据库;mysql默认端口号3306
如果端口被占用输入rm -f /var/run/yum.pid


# 临时启动 mariadb 
systemctl start mariadb

# 临时关闭 mariadb
systemctl stop mariadb

# 重启 mariadb
systemctl restart mariadb

# 设置开机自动启动
systemctl enable mariadb

# 关闭开机自动启动
systemctl disable mariadb

# 重新加载服务配置文件 
systemctl reload mariadb

# 查看 mariadb 状态
systemctl status mariadb

# 远程连接 mysql
mysql -h10.9.63.168 -uroot -p

登录mariadb数据库

使用mysql -uroot -p,刚安装好的没有密码,直接回车就行;


mysql 基本命令


# 查看数据库
show databases;

# 使用数据库
use 数据库名;

# 查看有哪些表
show tables;

# 查看表结构
desc 表名;
describe 表名;

# 查看创建数据库过程
show create database 数据库名;

# 查看创建表过程
show create table 表名;

# 查询表数据内容
select * from 表名;

# 查询表对应关键字数据
select 字段名,字段名,字段名 from 表名;

# 按条件查询表
select * from 表名 where 字段名='值';

# 查询表内相似的值
select * from 表名 where name like '值%';

# 查询表值升序、降序 
select * from 表名 order by 字段名 asc;
select * from 表名 order by 字段名 desc;

# 查询表 代表查看内容从m条开始,只查看n条
select * from 表名 limit m,n;



# 修改表中对应关键字数据
update user set password=password("123456") where user="root";
update user set host="10.9.63.128" where user="root";
update 表名 set 字段名="10.9.63.128" where 字段名="root";

# 修改表名
rename table 原表名 to 新表名;

# 修改Student表sno关键字改为Sno
alter table Student change sno Sno char(5) not null;


# 创建数据库 数据库名 以utf-8编码
create database 数据库名 character set utf8;

# 创建表
create table 表名(字段1 类型(宽度) 约束条件,字段2 类型(宽度) 约束条件;

# 往表内插入数据
insert into 表名(字段1,字段2) values('值1','值2');
insert into 表名 values('值1','值2'),('值1','值2');
insert into 表名 set 字段1='值',字段2='值';


# 删除数据库
drop database 数据库名;

# 删除表
drop table 表名;

# 删除表内字段值
delete from 表名 where 字段='值';



其他


# 更新数据库
flush privileges;

# 开启远程连接数据库
grant all privileges on *.* to 'root'@'%' identified by '654321' with grant option

# 授权用户开启远程连接数据库
grant all on bbs.* to 'lmx'@'192.168.1.128' identified by '123456';

# 撤销授权用户开启远程连接数据库
revoke all on bbs.* from 'lmx'@'192.168.1.128';

# 退出数据库
exit

创建表练习


# 创建学生表 Student
# 学号 Sno,设置主键,不允许为空
# 学生姓名Sname
# 学生性别Ssex
# 学生出生年月日Sbirthday
# 学生所在班级 Classsh
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值