mysql8.0.25安装
![](https://img2023.cnblogs.com/blog/2826060/202301/2826060-20230129210314986-1474126411.png)
chmod -R 777 /tmp
rpm -ivh mysql-community-common-8.0.25-1.el7.x86_64.rpm
rpm -ivh mysql-community-client-plugins-8.0.25-1.el7.x86_64.rpm
rpm -ivh mysql-community-libs-8.0.25-1.el7.x86_64.rpm
rpm -ivh mysql-community-client-8.0.25-1.el7.x86_64.rpm
rpm -ivh mysql-community-server-8.0.25-1.el7.x86_64.rpm
mysql --version
mysql Ver 8.0.25 for Linux on x86_64 (MySQL Community Server - GPL)
- 服务初始化
- 为了保证数据库目录与文件的所有者为mysql登录用户,如果你是以root用户运行mysql服务,需要执行下面的命令初始化
[root@localhost opt]# mysqld --initialize --user=mysql
cat /var/log/mysqld.log
![](https://img2023.cnblogs.com/blog/2826060/202301/2826060-20230129211304438-1816882473.png)
systemctl start mysqld
systemctl enable mysqld.service
systemctl disable mysqld.service
mysql -uroot -p
alter user 'root'@'localhost' identified by '123456'
![](https://img2023.cnblogs.com/blog/2826060/202301/2826060-20230129214132601-1277169314.png)
![](https://img2023.cnblogs.com/blog/2826060/202301/2826060-20230129214158575-1354046727.png)
- 修改root用户host字段(可访问的地址)%通配符
update user set host ='192.168.46.%' where user = 'root';
flush privileges;
![](https://img2023.cnblogs.com/blog/2826060/202301/2826060-20230129214512020-2031006583.png)
mysql5.7安装
![](https://img2023.cnblogs.com/blog/2826060/202301/2826060-20230129205301834-185626916.png)
- 检查/tmp临时目录权限
- 由于mysql安装过程中,会通过mysql用户在/tmp目录下新建tmp_db文件,所以请给/tmp较大的权限
chmod -R 777 /tmp
rpm -ivh mysql-community-common-5.7.28-1.el7.x86_64.rpm
rpm -ivh mysql-community-libs-5.7.28-1.el7.x86_64.rpm --nodeps --force
rpm -ivh mysql-community-client-5.7.28-1.el7.x86_64.rpm
rpm -ivh mysql-community-server-5.7.28-1.el7.x86_64.rpm --nodeps --force
用户管理
select user from user;
![](https://img2023.cnblogs.com/blog/2826060/202301/2826060-20230131213006236-515301189.png)
# 'userName'@'host'
create user 'cml'@'%' identified by '123456';
![](https://img2023.cnblogs.com/blog/2826060/202301/2826060-20230131214115683-2253056.png)
mysql -u cml -p123456;
update user set user = 'cml1' where user = 'cml';
flush privileges;
# 默认删除host为%,如果扇出host为localhost的用户drop user 'cml'@'localhost';
drop user 'cml1';
alter user user() identified by '123123';
alter user 'cml'@'%' identified by '123456';
权限管理
- 权限列表
- CREATE和DROP
- 可以创建新的数据库和表,或删除(移掉)已有的数据库和表。如果将MySQL数据库中的DROP权限授予某用户,用户就可以删除MySQL访问权限保存的数据库
- SELECT、INSERT、UPDATE和DELETE
- SELECT
- INDEX
- 允许创建或删除索引,INDEX适用于已有的表。如果具有某个表的CREATE权限,就可以在CREATE TABLE语句中包括索引定义
- ALTER
- 可以使用ALTER TABLE来更改表的结构和重新命名表
- CREATE ROUTINE
- 用来创建保存的程序(函数和程序),ALTER ROUTINE权限用来更改和删除保存的程序
- EXECUTE
- GRANT
- FILE
- 使用户可以使用LOAD DATA INFILE和SELECT ... INTO OUTFILE语句读或写服务器上的文件,任何被授予FILE权
限的用户都能读或写MySQL服务器上的任何文件(说明用户可以读任何数据库目录下的文件,因为服务器可以访问这些文件)
- 授予权限
- root用户新建dbtest1数据库
- 给cml用户授权,可以查看和修改dbtest1数据库
grant select,update on dbtest1.* to cml;
![](https://img2023.cnblogs.com/blog/2826060/202301/2826060-20230131223636315-1971555276.png)
grant select on dbtest1.* to 'cml'@'%';
show grants;
show grants for 'cml'@'%';
revoke select on dbtest1.* from 'cml'@'%';
revoke all privileges on *.* from 'cml'@'%';