你好陌生人,请不要试图越过权限文章,谢谢!

mysql安装与权限配置


写在前面

  • 详细介绍一些mysql的安装,并且配置远程访问服务与用户的权限控制
  • 配置:centos8腾讯云

mysql安装

先cd到src目录下

1
cd /usr/local/src/

接着,执行wget下载指定的mysql版本,这里我选用5.7版本,可以到官网指定需要的版本

1
wget http://repo.mysql.com/mysql57-community-release-el7-8.noarch.rpm 

安装完毕后,解压rpm包,如果没有rpm 这个指令,可以先 yum install rpm一下就可以了

1
rpm -ivh mysql57-community-release-el7-8.noarch.rpm 

接着编译安装mysql-server文件

1
yum -y install mysql-server 

完毕后,mysql就可以正常运行了


mysql的基础配置

  需要运行mysql我们还需要配置一下my.cnf文件

配置my.cnf文件

1
vim /etc/my.cnf

配置文件写入如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
[mysqld]
#
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
#
# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin
#
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
server_id = 1
expire_logs_days = 3

# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0

log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
  • 覆盖完毕后,按 ESC ,然后按住 Shift + : 输入 wq保存退出

相关配置指令

1.创建指定IP登录

1
CREATE USER 'root'@'IP地址' IDENTIFIED BY '密码';

2.刷新权限

1
flush privileges ;

3.删除用户

1
drop user '用户名'@'IP';

4.添加用户权限

1
grant all on *.* to 'chihonjian'@'%';

5.创建用户

1
CREATE USER ‘用户名‘@‘120.36.7.97‘ IDENTIFIED BY ‘密码‘;

结尾

mysql的权限控制是基于user表来实现的

  通过设置user账户的IP,如果使用 %则任意IP都可以通过远程访问此数据库。

  通过grant [update,insert,delete,select,all] on database . tables to ‘账户‘@‘IP地址’可以为用户添加不同的权限

  在生产环境中,一般不要使用%开放IP地址登录,最好是本地或者内网或指定IP访问。