CentOS 7 YUM安装与配置mysql 5.7

2,314次阅读
没有评论

共计 1854 个字符,预计需要花费 5 分钟才能阅读完成。

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

正文完
 
Winter
版权声明:本站原创文章,由 Winter 2018-01-08发表,共计1854字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
评论(没有评论)
验证码