Heartsuit's Simple Blog

A place to hold mainly reading notes, and some technical stuff occasionally. 这里主要是一些读书笔记、感悟;还有部分技术相关的内容。


Project maintained by heartsuit Hosted on GitHub Pages — Theme by mattgraham

CentOS7安装MySQL5.7太慢了

目录[-]

背景

服务器环境如下:

[root@ecs-c8ee-0008 ~]# cat /etc/os-release
NAME="CentOS Linux"
VERSION="7 (Core)"
ID="centos"
ID_LIKE="rhel fedora"
VERSION_ID="7"
PRETTY_NAME="CentOS Linux 7 (Core)"
ANSI_COLOR="0;31"
CPE_NAME="cpe:/o:centos:centos:7"
HOME_URL="https://www.centos.org/"
BUG_REPORT_URL="https://bugs.centos.org/"

CENTOS_MANTISBT_PROJECT="CentOS-7"
CENTOS_MANTISBT_PROJECT_VERSION="7"
REDHAT_SUPPORT_PRODUCT="centos"
REDHAT_SUPPORT_PRODUCT_VERSION="7"

计划安装 MySQL5.7 ,直接执行命令: yum -y install mysql-community-server ,发现太慢了。。

安装加速

所谓的加速,就是让安装命令不要直接去 MySQL 官方去下载,那网络真是太慢啦;而是使用国内镜像将包下载下来再安装,会节省不少时间。

  1. 使用国内镜像地址:http://uni.mirrors.163.com/mysql/Downloads/MySQL-5.7/
  2. 找到自己需要安装的版本,手动下载
  3. 下载好后,放到目录:cd /var/cache/yum/x86_64/7/mysql57-community/packages/
  4. 再次执行安装服务命令:yum -y install mysql-community-server
[root@ecs-c8ee-0008 ~]# cd /run/user/0/
[root@ecs-c8ee-0008 0]# yum -y install mysql-community-server
下载太慢。。
[root@ecs-c8ee-0008 0]# cd /var/cache/yum/x86_64/7/mysql57-community/packages/
[root@ecs-c8ee-0008 packages]# wget http://uni.mirrors.163.com/mysql/Downloads/MySQL-5.7/mysql-community-client-5.7.36-1.el7.x86_64.rpm
[root@ecs-c8ee-0008 packages]# wget http://uni.mirrors.163.com/mysql/Downloads/MySQL-5.7/mysql-community-server-5.7.36-1.el7.x86_64.rpm
[root@ecs-c8ee-0008 packages]# yum -y install mysql-community-server

启动服务

[root@ecs-c8ee-0008 packages]# service mysqld status
Redirecting to /bin/systemctl status  mysqld.service
● mysqld.service - MySQL Server
   Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
   Active: inactive (dead)
     Docs: man:mysqld(8)
           http://dev.mysql.com/doc/refman/en/using-systemd.html
[root@ecs-c8ee-0008 packages]# service mysqld start
Redirecting to /bin/systemctl start  mysqld.service
[root@ecs-c8ee-0008 packages]# service mysqld status
Redirecting to /bin/systemctl status  mysqld.service
● mysqld.service - MySQL Server
   Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
   Active: active (running) since 三 2021-12-01 15:18:22 CST; 2s ago
     Docs: man:mysqld(8)
           http://dev.mysql.com/doc/refman/en/using-systemd.html
  Process: 7479 ExecStart=/usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid $MYSQLD_OPTS (code=exited, status=0/SUCCESS)
  Process: 7254 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
 Main PID: 7483 (mysqld)
    Tasks: 27
   Memory: 323.8M
   CGroup: /system.slice/mysqld.service
           └─7483 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid

12月 01 15:18:13 ecs-c8ee-0008 systemd[1]: Starting MySQL Server...
12月 01 15:18:22 ecs-c8ee-0008 systemd[1]: Started MySQL Server.

修改密码

# 先获取到初始化自动生成的密码
[root@ecs-c8ee-0008 packages]# grep "password" /var/log/mysqld.log

# 输入初始密码,此时不能做任何事情,因为MYSQL默认必须修改密码才能正常使用
ALTER USER 'root'@'localhost' IDENTIFIED BY 'new password';

Note: 设置密码时,可能遇到报错: Your password does not satisfy the current policy requirements

# 可通过修改MySQL的密码策略进行解决:
SHOW VARIABLES LIKE 'validate_password%';

# 修改策略,及密码长度
set global validate_password_policy=0;
set global validate_password_length=1;

创建开发者访问数据库的用户

# 实际开发过程中一般分为开发者用户,生产用户,DBA管理用户,运维用户等。
# 而对于开发者只需要具有增删改查的权限即可,如果有修改表字段等这些管理需求,使用管理账号操作
create user test identified by 'your-password';
grant select,insert,update,delete on `your-db-name`.* to test@'%' identified by 'your-password';
flush privileges;

开启远程访问

# 允许远程主机访问
GRANT ALL PRIVILEGES on *.* to test@'%' IDENTIFIED BY 'your-password';
flush privileges;

If you have any questions or any bugs are found, please feel free to contact me.

Your comments and suggestions are welcome!


「说点什么吧😊~~😊」: