Bootstrap

CentOS 7.9安装MySQL

下载Linux版MySQL安装包

下载解压后

安装,按照从上至下顺序,一条一条执行即可安装完毕。

  • 进入到rpm所在目录
  • rpm -ivh mysql-community-common-8.0.26-1.el7.x86_64.rpm 
  • rpm -ivh mysql-community-client-plugins-8.0.26-1.el7.x86_64.rpm
  • rpm -ivh mysql-community-libs-8.0.26-1.el7.x86_64.rpm
  • rpm -ivh mysql-community-libs-compat-8.0.26-1.el7.x86_64.rpm
  • yum install openssl-devel
  • rpm -ivh mysql-community-devel-8.0.26-1.el7.x86_64.rpm
  • rpm -ivh mysql-community-client-8.0.26-1.el7.x86_64.rpm
  • sudo yum install libaio 【这一步看情况,如果在执行下一条时出现报错,可以执行这条,当然,得看你具体报什么错】
  • rpm -ivh mysql-community-server-8.0.26-1.el7.x86_64.rpm

启动MySQL服务

  • systemctl start mysqld  启动
  • systemctl restart mysqld  重启
  • systemctl stop mysqld  停止
  • systemctl status mysqld 查询状态

查询默认生成的root用户密码

  • grep 'temporary password' /var/log/mysqld.log

修改密码策略

  • set global validate_password.policy = 0; 设置密码复杂度
  • set global validate_password.length = 4; 设置密码长度

修改密码

  • alter user 'root'@'localhost' IDENTIFIED BY '1234';

创建一个可远程访问到用户,0.0.0.0

  • create user  'root'@'%' IDENTIFIED WITH mysql_native_password BY '1234';

修改root用户的权限

  • GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' WITH GRANT OPTION;

  • FLUSH PRIVILEGES;

设置只读权限

  • GRANT SELECT ON *.* TO 'your_username'@'your_host';
  • FLUSH PRIVILEGES;

;