一、mysql-8.0.33-linux-glibc安装
安装步骤
1.解压
tar -xvf mysql-8.0.33-linux-glibc2.12-x86_64.tar.xz
2.清空其他环境
rm -rf /etc/my.cnf
3.安装依赖库
yum list installed | grep libaio
4.创建用户
useradd -r -s /sbin/nologin mysql
查看
id mysql
5.创建mysql-files目录
在/usr/local/mysql目录下创建mysql-files目录
mkdir /usr/local/mysql/my-files
6.修改权限
修改mysql-files的权限为750,所属组和属主均为mysql
chown mysql:mysql /usr/local/mysql/my-files/
chmod 750 /usr/local/mysql/my-files/
7.初始化数据库,找到初始密码
/usr/local/mysql//bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysq/
8.判断是否生成data目录
ls /usr/local/mysql/data/
查看是否存在data目录,若存在,则证明初始化成功
ls /usr/local/mysql/data/
9.设置ssl安全加密
/usr/local/mysql/bin/mysql_ssl_rsa_setup --datadir=/usr/local/mysql/
10.复制目录
将mysql.server文件放到/etc/init.d/目录下,方便启动mysql服务
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql8
11.启动服务
service mysql8 start
登录
需要输入初始密码
/usr/local/mysql/bin/mysql -uroot -p
更改密码
set password='1';
至此mysql-8.0.33-linux-glibc安装成功
二、mysql-8.0.33-linux-glibc使用
创建账户
新增添用户dongdong
create user 'dongdong'@'%' identified by 'dongdong';
查看
select host,user from mysql.user;
使用用户dongdong登录
/usr/local/mysql/bin/mysql -udongdong -pdongdong
发现,没有权限
在root用户下登录
/usr/local/mysql/bin/mysql -uroot -p
赋予权限
赋予用户dongdong所有权限
grant all on . to 'dongdong';
再次登录,发现已经拥有权限
/usr/local/mysql/bin/mysql -udongdong -pdongdong
创建库
创建数据库 test
create database if not exists test charset utf8;
创建表
使用数据库test
use test;
创建表user
create table user(
-> id int primary key,
-> username varchar(45) not null,
-> password varchar(45) not null ->
);
添加数据
向表user插入数据
insert into user values(1,"dongdong","123");Query OK, 1 row affected (0.03 sec)
insert into user values(2,"ningning","456");Query OK, 1 row affected (0.00 sec)
insert into user values(3,"xiaozhao","789");Query OK, 1 row affected (0.00 sec)
insert into user values(4,"xiaolei","aaa");Query OK, 1 row affected (0.00 sec)
查看
select * from test.user;
添加dd账号,修改密码,查看dd信息
添加账号,并设立初始密码为‘1’
create user 'dd'@'%' identified by '1';
查看信息
select host,user from mysql.user;
修改密码为'2'
alter user 'dd'@'%' identified by '2';
注:远程登录
1.远程登录的前提条件:
mysql.user表中的host属性为%,若为localhost,则不允许远程登录
update mysql.user.set host="%" where user="root" ;
flush privileges;
2.远程登录
图像化工具——sqlyog ,navicat
客户端工具mysql
mysql -h192.168.1.100 -P3306 -udongdong -p dongdong
-h 主机ip或域名
-P 端口
-u 用户名
-p 密码
角色
创建角色
添加角色jinli,yuangong
create role 'jinli';
create role 'yuangong';
查看经理权限
show grants for 'jinli';
为经理添加 增 删 改 查 的权限
grant insert,delete,update,select on test.user to 'jinli';
再次查看经理权限
show grants for 'jinli';
为员工添加 新增 、查看 的权限
grant select,insert on test.user to 'yuangong';
查看员工权限
show grants for 'yuangong';
创建bbb和ccc用户
create user 'bbb'@'%' identified by 'bbb';
create user 'ccc'@'%' identified by 'ccc';
赋予角色
给bbb赋予经理角色
grant jinli to 'bbb';
给ccc账户赋予员工角色
grant yuangong to 'ccc';
查看角色赋予情况
标签:dongdong,8.0,21,33,create,user,mysql,local,usr From: https://blog.csdn.net/m0_73907608/article/details/140932692