centos7 安装mysql 5.7笔记

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/

centos7 安装mysql 5.7笔记_第1张图片
centos7 安装mysql 5.7笔记_第2张图片
注意需要根据linux的版本选择对应的仓库

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

4. 修改安装msyql的版本

yum repolist enabled | grep "mysql.*-community.*"
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

修改为安装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

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;

10. 设置字符集为utf-8

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

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

11. 修改开启启动Mysql

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

12. 查看属性

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

show VARIABLES like '%dir%' ;

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

你可能感兴趣的:(mysql)