CenOS7安装mysql5.7

1、配置YUM源

  • 下载MySQL源安装包
wget http://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm
  • 安装MySQL源
yum localinstall mysql57-community-release-el7-8.noarch.rpm
  • 检查MySQL源是否安装成功
yum repolist enabled |grep mysql

2、安装MySQL

yum install mysql-community-server

安装时可能会出现类似以下的错误:
Error downloading packages:
mysql-community-client-5.7.27-1.el7.x86_64: [Errno 256] No more mirrors to try.
mysql-community-common-5.7.27-1.el7.x86_64: [Errno 256] No more mirrors to try.

解决方案如下:

  • 清理软件源
    yum clean all
  • 建立源数据缓存
    yum makecache
    再次重新安装,出现“Complete!”表示安装成功
    rpm -qa | grep mysql,查看都安装了那些包

3、启动MySQL服务

systemctl start mysqld    ## 启动MySQL
systemctl status mysqld    ## 查看MySQL的启动状态
systemctl daemon-reload    ## 重载所有修改过的配置文件

4、查看MySQL下root账号的默认密码

mysql5.7安装完成之后,在/var/log/mysqld.log文件中给root生成了一个默认密码。通过下面的方式找到root默认密码,然后登录MySQL。

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

5、先修改配置文件,后设置密码

  • vim /etc/my.cnf
# 如果不需要密码策略,禁用密码策略
validate_password = off
# 字符编码设置为utf8
character_set_server = utf8
init_connect = 'SET NAMES utf8'
# 设置数据库表名不区分大小(0:区分大小写,1:不区分大小写)
lower_case_table_names=1
  • systemctl restart mysqld
    登录MySQL
    mysql -u root -p
    输入密码:刚查到的默认密码

6、修改密码步骤如下

alter user 'root'@'localhost' identified by 'root';
grant all privileges on *.* to 'root' @'%' identified by 'yourpassword';   # 允许远程访问MySQL
flush privileges; #刷新权限
mysql -u root -p   # 重新登录MySQL输入刚设置的密码"123456"即可登录进MySQL

7、查看设置的字符集

show variables like "%character%";
show variables like "%collation%";

8、MySQL安装目录

show variables like '%dir%';

你可能感兴趣的:(CenOS7安装mysql5.7)