阿新

centos7使用yum安装mysql5.7
centos7使用yum安装mysql5.71. 配置YUM源在MySQL官网中下载YUM源rpm安装包:http...
扫描右侧二维码阅读全文
09
2018/04

centos7使用yum安装mysql5.7

centos7使用yum安装mysql5.7

1. 配置YUM源

  • 下载mysql源安装包

    shell> wget http://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm
  • 安装mysql源

    shell> yum localinstall mysql57-community-release-el7-8.noarch.rpm
  • 检查mysql源是否安装成功

    shell> yum repolist enabled | grep "mysql.*-community.*"

    TIM截图20180409173618.png

看到上图所示表示安装成功

  • 可以修改vim /etc/yum.repos.d/mysql-community.repo源,改变默认安装的mysql版本。比如要安装5.6版本,将5.7源的enabled=1改成enabled=0。然后再将5.6源的enabled=0改成enabled=1即可。

2. 安装mysql

shell> yum install mysql-community-server

3. 启动MySQL服务

shell> systemctl start mysqld

4. 开机启动

shell> systemctl enable mysqld
shell> systemctl daemon-reload

5. 修改root本地登录密码

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

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

找到密码后登陆mysql,然后输入下列命令修改密码:

mysql> set password for 'root'@'localhost'=password('MyNewPass4!'); 

刷新权限

mysql> FLUSH PRIVILEGES;

6. 添加远程登录用户

默认只允许root帐户在本地登录,如果要在其它机器上连接mysql,必须修改root允许远程连接,或者添加一个允许远程连接的帐户,为了安全起见,我添加一个新的帐户:

mysql> GRANT ALL PRIVILEGES ON *.* TO 'axin'@'%' IDENTIFIED BY 'axin#@!' WITH GRANT OPTION;

7. 配置默认编码为utf8

修改/etc/my.cnf配置文件,在[mysqld]下添加编码配置,如下所示:

[mysqld]
character_set_server=utf8
init_connect='SET NAMES utf8'

重新启动mysql服务

默认配置文件路径

配置文件:/etc/my.cnf
日志文件:/var/log//var/log/mysqld.log
服务启动脚本:/usr/lib/systemd/system/mysqld.service
socket文件:/var/run/mysqld/mysqld.pid

Last modification:June 22nd, 2018 at 03:02 pm
If you think my article is useful to you, please feel free to appreciate

Leave a Comment