• 欢迎访问癹冬阁,本站专注于IT服务,记录工作点滴

CentOS 7 YUM安装与配置mysql 5.7

开源世界 Winter 7个月前 (01-08) 337次浏览 已收录 0个评论

1.安装 mysql 5.7 的 Yum 源

#rpm -Uvh https://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm

可以修改/etc/yum.repos.d/mysql-community.repo 源来改变默认安装的 mysql 版本,比如要安装 5.6 则将 5.7 源中的 enabled=1 修改为 enabled=0,再将 5.6 源中的 enabled=0 修改为 enabled=1.如下图:

image

2.安装 mysql

#yum install -y mysql-community-server

3.修改 mysql 存贮目录

建立数据库存贮目录

#mkdir /home/data/mysql

#chown mysql:mysql -R /home/data/mysql

修改配置文件

#vim /etc/my.cnf

找到 datadir=/var/lib/mysql 和 socket=/var/lib/mysql/mysql.sock,并将其修改为

datadir=/home/data/mysql

socket=/home/data/mysql/mysql.sock

建立软链接

ln -s /home/data/mysql/mysql.sock /var/lib/mysql/mysql.sock

4.启动 mysql 服务

#systemctl start mysqld

查看启动状态

#systemctl status mysqld
● mysqld.service – MySQL Server
   Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
   Active: active (running) since 一 2018-01-08 10:43:48 CST; 4h 24min ago
     Docs: man:mysqld(8)
           http://dev.mysql.com/doc/refman/en/using-systemd.html
Main PID: 23400 (mysqld)
   CGroup: /system.slice/mysqld.service
           └─23400 /usr/sbin/mysqld –daemonize –pid-file=/var/run/mysqld/mysqld.pid

1 月 08 10:43:41 lnmt.caihuang.com systemd[1]: Starting MySQL Server…
1 月 08 10:43:48 lnmt.caihuang.com systemd[1]: Started MySQL Server.

5.将 mysql 设为开机启动

#systemctl enable mysqld

#systemctl daemon-reload

6.修改 mysql root 密码

mysql 安装完成后,在/var/log/mysqld.log 保存有安装生成的默认密码:

# grep ‘temporary password’ /var/log/mysqld.log
2018-01-08T02:43:42.968699Z 1 [Note] A temporary password is generated for root@localhost: oRahty0sKL_d

# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.7.20 MySQL Community Server (GPL)

Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the current input statement.

mysql>ALTER USER 'root'@'localhost' IDENTIFIED BY 'YourP@ssW0rd!';

请注意密码安全策略,可用以下命令查看

image


癹冬阁版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明CentOS 7 YUM 安装与配置 mysql 5.7
喜欢 (0)
[winters@8win.net]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址