MySQL 安装维护

配置时区

serverTimezone=Asia/Shanghai

开启 BinLog

  • 1.修改mysql的my.ini文件,增加以下内容
log-bin=mysql-bin
binlog-format=ROW
  • 2.重启mysql

  • 3.查看bin_log是否成功开启:

show variables like 'log_bin';

修改密码

  1. vim /etc/my.cnf  
    # or
    vim /etc/mysql/my.cnf
    
  2. Add skip-grant-tables under [mysqld]

  3. Restart MySQL

  4. You should be able to log in to MySQL now using the below command mysql -u root -p

  5. Run mysql> flush privileges;

  6. Set new password by ALTER USER 'root'@'localhost' IDENTIFIED BY 'NewPassword';

    如果提示密码等级低:输入: SET GLOBAL validate_password.policy=LOW;

  7. Go back to /etc/my.cnf and remove/comment skip-grant-tables

  8. Restart MySQL

  9. Now you will be able to login with the new password mysql -u root -p

设置必要权限:

grant SELECT,INSERT,UPDATE,DELETE,CREATE,DROP,ALTER on 数据库名称.* to 'qrt_user'@'%';

撤销所有权限

revoke all on *.* from 'qrt_user'@'%';

展示授予了那些权限:

show grants for 'qrt_dev'@'%'; // % 表示所有主机

注意: 全局权限,不可以指定在某一个库上, 如: process 就是一个全局权限

Authentication Plugins

-- 新增用户的时候 可以指定使用那个授权插件
-- WITH 后指定了使用那个授权插件, 如果不知道就使用默认的, mysql8.0 默认使用caching_sha2_password, 需要客户端支持;
CREATE USER 'sha2user'@'localhost'
IDENTIFIED WITH caching_sha2_password BY 'password';

-- 使用默认授权插件
CREATE USER 'sha2user'@'localhost'
IDENTIFIED BY 'password';

账户相关操作: https://dev.mysql.com/doc/refman/8.0/en/creating-accounts.html

扩展:

  1. \G 表示将结果按列打印
posted @ 2020-10-22 22:37  那年长安  阅读(83)  评论(0)    收藏  举报