
一. 环境
- CentOS7
- MariaDB5.5.64
二. 安装
yum -y install mariadb mariadb-server
三. 启动mariaDB并加入开机启动
systemctl start mariadb
systemctl enable mariadb
四. 初使化
刚安装的mariaDB,需要初始化工作,提高安全性.
- 使用工具
mysql_secure_installation
mariaDB自带的工具.
初使化MariaDB
五. 登陆使用
mysql -u root -p
show databases;
create database hello;
create table hello (name varchar(25),sex tinyint(1));
insert into hello(name, sex) values("hello_world", 1);
select * from hello;

六. 修改密码
set password=password('sgfoot')

七. 创建用户
# 创建只允许本地访问的帐号
create user 'sgfoot'@'localhost' identified by 'sgfoot';
# 创建只允许192.168开头的ip访问的帐号
create user 'sgfoot'@'192.168.%.%' identified by 'sgfoot';
# 创建任意ip访问的帐号
create user 'sgfoot'@'%' identified by 'sgfoot';
# 查看所有的帐号
select host, user, password from user where user like 'sgfoot%'

八. 帐号授权
# 授权select, insert, update,delete
grant select,insert, update,delete on hello.* to 'sgfoot'@'localhost';
# 取消权限
revoke all on *.* from sgfoot@localhost;
# 刷新权限
flush privileges;
九. 删除用户

# 先查看
select user, host from mysql.user;
# 对应着删除
drop user marry@192.168.21.23

网友评论