天天看点

MySQL 用户和权限管理服务器端配置用户软件安装目录数据路径socket文件位置服务器id号短口号客户端配置socket文件位置授权TCPIPSocket

用户和权限管理

用户作用

登录mysql

管理mysql

用户定义

用户名@'白名单'

写法:

wordpress@'%'

wordpress@'localhost'

wordpress@'127.0.0.1'

wordpress@'10.0.0.%'

wordpress@'10.0.0.5%'

wordpress@'10.0.0.0/255.255.254.0'

wordpress@'10.0.%'

用户管理

创建用户

mysql> create user ac@'10.0.0.%' identified by 'sa';

说明:8.0以前,可以自动创建用户并授权

mysql> grant all on . to ac@'10.0.0.%' identified by 'sa';

查询用户

mysql> select user,host from mysql.user;

修改用户密码

mysql> alter user ac@'10.0.0.%' identified by 'sa';

删除用户

mysql> drop user ac@'10.0.0.%' ;

权限管理

权限列表

ALL

SELECT,INSERT, UPDATE, DELETE, CREATE, DROP, RELOAD, SHUTDOWN, PROCESS, FILE, REFERENCES, INDEX, ALTER, SHOW DATABASES, SUPER, CREATE TEMPORARY TABLES, LOCK TABLES, EXECUTE, REPLICATION SLAVE, REPLICATION CLIENT, CREATE VIEW, SHOW VIEW, CREATE ROUTINE, ALTER ROUTINE, CREATE USER, EVENT, TRIGGER, CREATE TABLESPACE

授权命令

例:grant all on . to ac@'10.0.0.%' identified by 'sa' with grant option;

说明:grant [权限] on [作用目标] to [用户] identified by [密码] with grant option

授权需求

创建一个管理员用户root,可以通过10网段,管理数据库.

grant SELECT,INSERT, UPDATE, DELETE on wordpress.* to wordpress@'10.0.0.%' identified by '123';

创建一个应用用户wordpress,可以通过10网段,wordpress库下的所有表进行SELECT,INSERT, UPDATE, DELETE.

权限回收

show grants for wordpress@'10.0.0.%';

mysql> revoke delete on wordpress.* from 'wordpress'@'10.0.0.%';

mysql> show grants for wordpress@'10.0.0.%';

MySQL 的启动和关闭

正常启停

sys -v

mysql.server start ---> mysqld_safe ---> mysqld

system

mysql.service ---> mysqld

    需要依赖于 /etc/my.cnf

维护

mysqld_safe

例:修改密码mysqld_safe --skip-grant-tables --skip-networking &

将参数临时加到命令行,命令行的优先级高

初始化配置

初始化作用

影响数据库的启动

影响到客户端的功能

初始化方法

初始化配置文件(例如/etc/my.cnf)

启动命令行上进行设置(例如:mysqld_safe mysqld)

预编译时设置(仅限于编译安装时设置)

配置文件格式

[标签]

xxx=xxx

标签归类

服务器端:

[mysqld]

[mysqld_safe]

[server]

客户端:

[mysql]

[mysqladmin]

[mysqldump]

[client]

模板文件 (5.7)

服务器端配置

用户

user=mysql

软件安装目录

basedir=/application/mysql

数据路径

datadir=/data/mysql/data

socket文件位置

socket=/tmp/mysql.sock

服务器id号

server_id=6

短口号

port=3306

客户端配置

配置文件读取顺序

查询: mysqld --help --verbose |grep my.cnf

/etc/my.cnf /etc/mysql/my.cnf /usr/local/mysql/etc/my.cnf ~/.my.cnf

强制使用自定义配置文件

--defautls-file

[root@db01 tmp]# mysqld_safe --defaults-file=/tmp/aa.txt &

MySQL的连接管理

mysql连接命令

注意:提前应该将用户授权做好

授权

mysql> grant all on . to root@'10.0.0.%' identified by '123';

TCPIP

mysql -uroot -p -h 10.0.0.51 -P3306

Socket

mysql -uroot -p -S /tmp/mysql.sock

客户端工具

dbforger

sqlyog

navicat