CentOS 7 YUM安装与配置mysql 5.7

开源世界 Winter 2年前 (2018-01-08) 831次浏览 已收录 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)
发表我的评论
取消评论

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

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

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