CentOS安装mysql5.7
2021-4-20
| 2023-2-19
0  |  0 分钟
password
Created
Feb 19, 2023 04:53 PM
type
Post
status
Published
date
Apr 20, 2021
slug
summary
CentOS安装mysql5.7
tags
CentOS
MySQL
category
icon
  1. 下载mysql yum包
wget http://repo.mysql.com/mysql57-community-release-el7-10.noarch.rpm
  1. 安装muysql源
rpm -Uvh mysql57-community-release-el7-10.noarch.rpm
  1. 安装mysql服务端
yum install -y mysql-community-server
另外: 可能这时候等待了很久会碰到一个错误, 主要内容如下
...Unable to find a match: mysql-community-server...
解决方式是:
# 先执行 yum module disable mysql # 再执行 yum -y install mysql-community-server
还有, 如果碰到了错误, 如下:
...The GPG keys listed for the "MySQL 5.7 Community Server" repository are already installed but they are not correct for this package...
主要是签名的问题, 可能是云服务商处理了这个包导致hash变了, 这时候需要处理下签名关系
rpm --import https://repo.mysql.com/RPM-GPG-KEY-mysql-2022
  1. 启动mysql
systemctl start mysqld.service
  1. 检查启动是否正常
systemctl status mysqld.service
有绿色提示, 表示正常
  1. 修改初始密码
# 先打印出来初始密码 grep 'temporary password' /var/log/mysqld.log # 用打印出来的初始密码进行登录 mysql -uroot -p # 进入mysql的交互终端, 禁用掉密码复杂度的要求 set global validate_password_policy=0; set global validate_password_length=1; # 设置我们需要的密码 ALTER USER 'root'@'localhost' IDENTIFIED BY 'yourpassword'; # 再设置其他设备远程登录, 否则无法登陆成功 GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'yourpassword' WITH GRANT OPTION; FLUSH PRIVILEGES;
 
  1. 设置开机自启动(记得退出mysql)
systemctl enable mysqld systemctl daemon-reload
  1. 设置字符集和默认引擎
# For advice on how to change settings please see # http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html [mysql] default-character-set=utf8 [mysqld] datadir=/var/lib/mysql socket=/var/lib/mysql/mysql.sock default-storage-engine=INNODB character_set_server=utf8 symbolic-links=0 log-error=/var/log/mysqld.log pid-file=/var/run/mysqld/mysqld.pid
  1. 重启mysql, 使配置生效
service mysqld restart
  1. 开放防火墙
这里centos7和8不太一样, 或者说unix下的服务商防火墙的设置不太一样
有的使用的是firewall, 有的则是iptables
# 如果是firewall firewall-cmd --state firewall-cmd --zone=public --add-port=3306/tcp --permanent firewall-cmd --reload # 如果是iptables iptables -I INPUT -p tcp --dport 3306 -j ACCEPT
  1. 卸载仓库
一开始的时候我们安装的yum,每次yum操作都会更新一次,耗费时间,我们把他卸载掉
yum -y remove mysql57-community-release-el7-10.noarch
  1. 后续数据库的基本操作
启动mysql:service mysqld start 停止mysql:service mysqld stop 重启mysql:service mysqld restart
 
 
相关文章 :
  • CentOS
  • MySQL
  • CentOS安装redisRxjs和它的一些概念
    目录