当前位置:   article > 正文

centos7 安装mysql 5.7笔记_cenyos7 安装mysql

cenyos7 安装mysql

1. 环境

  • centos7
  • 阿里云服务器

2. 官网地址

https://dev.mysql.com/doc/refman/5.7/en/linux-installation-yum-repo.html

3. 下载repo

https://dev.mysql.com/downloads/repo/yum/

在这里插入图片描述
在这里插入图片描述
注意需要根据linux的版本选择对应的仓库

yum localinstall mysql80-community-release-el7-3.noarch.rpm

4. 修改安装msyql的版本

yum repolist enabled | grep "mysql.*-community.*"
  • 1
mysql-connectors-community/x86_64 MySQL Connectors Community                 153
mysql-tools-community/x86_64      MySQL Tools Community                      110
mysql80-community/x86_64          MySQL 8.0 Community Server                 424
  • 1
  • 2
  • 3

修改为安装5.7

yum-config-manager --disable mysql80-community
yum-config-manager --enable mysql57-community

mysql-connectors-community/x86_64 MySQL Connectors Community                 153
mysql-tools-community/x86_64      MySQL Tools Community                      110
mysql57-community/x86_64          MySQL 5.7 Community Server                 424
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

5. 安装

yum install mysql-community-server

6. 启动

service mysqld start
service mysqld status

7. 查询密码

grep ‘temporary password’ /var/log/mysqld.log

mysql -uroot -p

8. 修改初始密码

ALTER USER ‘root’@‘localhost’ IDENTIFIED BY ‘MyNewPass4!’;

默认有validate_password会验证密码,需要大写字母等等
set global validate_password_policy=0;
set global validate_password_length=1;

9. 修改远程访问权限

update mysql.user set host=’%’ where user=‘root’;

flush privileges;

9.1. 方法2

grant all privileges on *.* to 'root'@'%' identified by '123456' with grant option;
flush privileges;
  • 1
  • 2

10. 设置字符集为utf-8

#在[mysqld]部分添加:
character-set-server=utf8
#在文件末尾新增[client]段,并在[client]段添加:
default-character-set=utf8
  • 1
  • 2
  • 3
  • 4

vim /etc/my.cnf

[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
symbolic-links=0
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
character-set-server=utf8
[client]
default-character-set=utf8
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9

11. 修改开启启动Mysql

#启动之前需要生成临时密码,需要用到证书,可能证书过期,需要进行更新操作
yum update -y
#启动mysql服务
service mysqld start
#设置mysql开机启动
chkconfig mysqld on
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

12. 查看属性

https://dev.mysql.com/doc/refman/5.6/en/environment-variables.html

show VARIABLES like '%dir%' ;
  • 1

13. 遇到问题

13.1. xx.so文件找不到

应该是安装的版本不对,修改了下repo,卸载之后重新安装了

13.2. 启动后查询不到密码

看日志发现数据库初始化时候错误

  • 因为之前装过mysql, /var/lib/mysql 中有数据,清空重装好了.

14. 其他命令

yum list installed |grep mysql
yum removee -y mysql
yum update
yum clean all
yum makecache

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Cpp五条/article/detail/461296
推荐阅读
相关标签
  

闽ICP备14008679号