Linux(CentOS)安装MySQL5.7

首页 » 编程之家 » Java » 正文

Linux(CentOS)安装MySQL5.7


安装前说明:

1、以下安装教程部分内容直接粘引用的是之前在我CSDN中的图片解释内容,对于正常安装没有影响。

2、以下安装教程在本次书写中已经过实践(真实服务器),加上之前在CSDN中的至少实践两次以上。


官网下载MySQL

 

官网:https://dev.mysql.com/downloads/repo/yum/

 

下载自己需要的版本后,如下

 

[root@VM-0-8-centos software]# ls
mysql80-community-release-el7-3.noarch.rpm
[root@VM-0-8-centos software]# 

 

首先本地安装      rpm  yum localinstall mysql80-community-release-el7-3.noarch.rpm

 

[root@VM-0-8-centos software]# yum localinstall mysql80-community-release-el7-3.noarch.rpm 
Loaded plugins: fastestmirror, langpacks
Examining mysql80-community-release-el7-3.noarch.rpm: mysql80-community-release-el7-3.noarch
Marking mysql80-community-release-el7-3.noarch.rpm to be installed
Resolving Dependencies
--> Running transaction check
---> Package mysql80-community-release.noarch 0:el7-3 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

===========================================================================================================================
 Package                            Arch            Version         Repository                                        Size
===========================================================================================================================
Installing:
 mysql80-community-release          noarch          el7-3           /mysql80-community-release-el7-3.noarch           31 k

Transaction Summary
===========================================================================================================================
Install  1 Package

Total size: 31 k
Installed size: 31 k
Is this ok [y/d/N]: y
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : mysql80-community-release-el7-3.noarch                                                                  1/1 
  Verifying  : mysql80-community-release-el7-3.noarch                                                                  1/1 

Installed:
  mysql80-community-release.noarch 0:el7-3                                                                                 

Complete!
[root@VM-0-8-centos software]# 

 

上述安装完后会在本地建立一个mysql仓库,接着我们指定仓库中的mysql版本(即将要安装的)

指定安装版本—–编辑mysql-community.repo文件      vi /etc/yum.repos.d/mysql-community.repo

 

Linux(CentOS)安装MySQL5.7

 

具体代码如下:

 

# Enable to use MySQL 5.6
[mysql56-community]
name=MySQL 5.6 Community Server
baseurl=http://repo.mysql.com/yum/mysql-5.6-community/el/7/$basearch/
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
 
# Enable to use MySQL 5.7
[mysql57-community]
name=MySQL 5.7 Community Server
baseurl=http://repo.mysql.com/yum/mysql-5.7-community/el/7/$basearch/
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
 
[mysql80-community]
name=MySQL 8.0 Community Server
baseurl=http://repo.mysql.com/yum/mysql-8.0-community/el/7/$basearch/
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql

 

其中,enabled=0表示不安装,我们找到mysql5.7然后将enabled设置为1,其余设置为0(以防默认)。

设置好安装版本后,然后安装      yum install mysql-community-server

 

安装完成后,登录mysql,因在安装过程中,没有设置密码,第一次登录用我们直接回车看提示进行试探。

第一次登录出现如下情况 :

 

[root@master yum.repos.d]# mysql -u root -p
Enter password: 
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)

 

解决办法第一步,查看mysql服务状态

 

systemctl status mysqld
[root@master]# systemctl status mysqld
● mysqld.service - MySQL Server
   Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
   Active: inactive (dead)
     Docs: man:mysqld(8)
           http://dev.mysql.com/doc/refman/en/using-systemd.html
[root@master]#

 

可以看出服务没有激活

解决办法第二步,开启mysql服务

 

[root@master]# systemctl start mysqld
[root@master]# systemctl status mysqld
● mysqld.service - MySQL Server
   Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
   Active: active (running) since Wed 2019-09-25 22:06:12 CST; 2s ago
     Docs: man:mysqld(8)
           http://dev.mysql.com/doc/refman/en/using-systemd.html
  Process: 1995 ExecStart=/usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid $MYSQLD_OPTS (code=exited, status=0/SUCCESS)
  Process: 1922 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
 Main PID: 1998 (mysqld)
   CGroup: /system.slice/mysqld.service
           └─1998 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid...
 
Sep 25 22:06:05 master systemd[1]: Starting MySQL Server...
Sep 25 22:06:12 master systemd[1]: Started MySQL Server.
[root@master]#

 

服务已经开启,我们再次无密码登录

 

[root@master yum.repos.d]# mysql -u root -p
Enter password: 
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

 

发现没有密码被拒绝,此时应该想到好看日志,首先查看mysql的错误日志在那个文件

查看mysql错误日志在那个文件夹下

 

[root@master yum.repos.d]# cat /etc/my.cnf
# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html
 
[mysqld]
#
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
#
# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin
#
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
 
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
 
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
[root@master yum.repos.d]# cat /var/log/mysqld.log

 

从上面看有注意到mysql的错误日志位置(log-error=/var/log/mysqld.log)

查看mysql.log

 

Linux(CentOS)安装MySQL5.7

 

复制密码再次登录

 

[root@master yum.repos.d]# mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.27
 
Copyright (c) 2000, 2019, 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>

 

登录成功!查看数据库试试

 

mysql> show databases;
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
mysql>

 

提示要重置密码

修改密码第一步:设置密码安全检验(降低)

 

mysql> set global validate_password_policy=0;    
Query OK, 0 rows affected (0.00 sec)
 
mysql> set global validate_password_length=1;
Query OK, 0 rows affected (0.00 sec)

 

重新登录

 

[root@master yum.repos.d]# mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.7.27 MySQL Community Server (GPL)
 
Copyright (c) 2000, 2019, 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.

 

查看策略表

 

Linux(CentOS)安装MySQL5.7

 

可以看出,密码长度最小设置文4位,设置密码要求已经最低。到了这个阶段,mysql5.7已经安装好了。

为了方便远程连接,现给root用户授权。

 

update user set host='%' where user='root';

 

至此,MySQL5.7在Linux系统上的安装已完成,如配置过程中有遇到其他问题,欢迎留言讨论!

 

 

 

 

 

 

 

 

 

作者:bear, 转载或复制请以 超链接形式 并注明出处 数据与编程之美
原文地址:《Linux(CentOS)安装MySQL5.7》 发布于2021-01-12

分享到:
赞(1) 打赏

评论 抢沙发

评论前必须登录!

  注册



长按图片转发给朋友

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏

一碗牛肉面
鼓励站长分享更多学习经验、教程、学习资源。
切换注册

登录

忘记密码 ?

您也可以使用第三方帐号快捷登录

Q Q 登 录
微 博 登 录
切换登录

注册