MENU

#Linux运维教程#centos 7.4 64位 安装mysql 5.7详细教程

December 6, 2018 • Linux阅读设置

下载mysql源安装包:


[root@MyCloudServer ~]#wget http://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm

安装mysql源:


[root@MyCloudServer ~]#yum localinstall mysql57-community-release-el7-8.noarch.rpm

检查mysql源是否安装成功:


[root@MyCloudServer ~]# yum repolist enabled | grep "mysql.-community."

[root@MyCloudServer ~]# yum repolist enabled | grep "mysql.*-community.*"
mysql-connectors-community/x86_64       MySQL Connectors Community            74
mysql-tools-community/x86_64            MySQL Tools Community                 74
mysql57-community/x86_64                MySQL 5.7 Community Server           307

安装MySQL:


[root@MyCloudServer ~]# yum install mysql-community-server

启动MySQL服务:


[root@MyCloudServer ~]# systemctl start mysqld

查看MySQL的启动状态:


[root@MyCloudServer ~]# systemctl status mysqld
mysqld.service - MySQL Server
Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled)
Active: active (running) since Thu 2018-12-06 12:45:12 CST; 25min ago

 Docs: man:mysqld(8)
       http://dev.mysql.com/doc/refman/en/using-systemd.html

Main PID: 9535 (mysqld)
CGroup: /system.slice/mysqld.service

       └─9535 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid

Dec 06 12:45:12 MyCloudServer systemd[1]: Started MySQL Server.
Dec 06 13:10:44 MyCloudServer systemd[1]: Started MySQL Server.
开机启动
[root@MyCloudServer ~]# systemctl enable mysqld
[root@MyCloudServer ~]# systemctl daemon-reload
5、修改root本地登录密码
mysql安装完成之后,在/var/log/mysqld.log文件中给root生成了一个默认密码。通过下面的方式找到root默认密码,然后登录mysql进行修改:

[root@MyCloudServer ~]#  grep 'temporary password' /var/log/mysqld.log

2018-12-06T04:45:06.219566Z 1 [Note] A temporary password is generated for root@localhost: L6#.?>3<jwj,

登陆进去:

[root@MyCloudServer ~]# mysql -uroot -p
Enter password:

首先需要修改密码不然无法使用复制一下策略:


ALTER USER 'root'@'localhost' IDENTIFIED BY 'MbeS7wP3ss4!';

查看密码策略:


mysql> show variables like '%password%';
Variable_nameValue
default_password_lifetime0
disconnect_on_expired_passwordON
log_builtin_as_identified_by_passwordOFF
mysql_native_password_proxy_usersOFF
old_passwords0
report_password
sha256_password_proxy_usersOFF
validate_password_check_user_nameOFF
validate_password_dictionary_file
validate_password_length8
validate_password_mixed_case_count1
validate_password_number_count1
validate_password_policyMEDIUM
validate_password_special_char_count1

14 rows in set (0.01 sec)
默认配置文件路径:
配置文件:/etc/my.cnf
日志文件:/var/log//var/log/mysqld.log
服务启动脚本:/usr/lib/systemd/system/mysqld.service
socket文件:/var/run/mysqld/mysqld.pid

其他配置信息,见下文。1.png