CentOS-7安装MySQL

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_26346457/article/details/79881920

一、MySQL官网获取下载地址

当我们需要安装MySQL的某一个版本的时候,访问MySQL的官网:https://www.mysql.com/->DOWNLOADS->Archives->MySQL Community Server,选择版本,操作系统,操作系统版本,下载RPM Bundle。这个时候获取到 下载 地址:https://cdn.mysql.com/archives/mysql-5.7/mysql-5.7.20-1.el7.x86_64.rpm-bundle.tar

二、下载和解压

wget -c https://cdn.mysql.com/archives/mysql-5.7/mysql-5.7.20-1.el7.x86_64.rpm-bundle.tar

tar vxf mysql-5.7.20-1.el7.x86_64.rpm-bundle.tar

解压后的文件RPM文件列表:

mysql-community-libs-5.7.20-1.el7.x86_64.rpm
mysql-community-client-5.7.20-1.el7.x86_64.rpm
mysql-community-libs-compat-5.7.20-1.el7.x86_64.rpm
mysql-community-common-5.7.20-1.el7.x86_64.rpm
mysql-community-minimal-debuginfo-5.7.20-1.el7.x86_64.rpm
mysql-community-devel-5.7.20-1.el7.x86_64.rpm
mysql-community-server-5.7.20-1.el7.x86_64.rpm
mysql-community-embedded-5.7.20-1.el7.x86_64.rpm
mysql-community-server-minimal-5.7.20-1.el7.x86_64.rpm
mysql-community-embedded-compat-5.7.20-1.el7.x86_64.rpm
mysql-community-test-5.7.20-1.el7.x86_64.rpm

mysql-community-embedded-devel-5.7.20-1.el7.x86_64.rpm

三、安装

yum localinstall mysql-community-common-5.7.20-1.el7.x86_64.rpm

yum localinstall mysql-community-libs-5.7.20-1.el7.x86_64.rpm

yum localinstall mysql-community-client-5.7.20-1.el7.x86_64.rpm

yum localinstall mysql-community-server-5.7.20-1.el7.x86_64.rpm

当安装common的时候,遇到冲突的时候用yum remove mariadb-libs-1:5.5.56-2.el7.x86_64或者rpm -e mariadb-libs-1:5.5.56-2.el7.x86_64卸载冲突包。

[x@localhost ~]$ sudo yum localinstall mysql-community-common-5.7.20-1.el7.x86_64.rpm 
[sudo] password for x: 
Loaded plugins: fastestmirror
Examining mysql-community-common-5.7.20-1.el7.x86_64.rpm: mysql-community-common-5.7.20-1.el7.x86_64
Marking mysql-community-common-5.7.20-1.el7.x86_64.rpm to be installed
Resolving Dependencies
--> Running transaction check
---> Package mysql-community-common.x86_64 0:5.7.20-1.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

=========================================================================================================================================
 Package                          Arch             Version                   Repository                                             Size
=========================================================================================================================================
Installing:
 mysql-community-common           x86_64           5.7.20-1.el7              /mysql-community-common-5.7.20-1.el7.x86_64           2.5 M

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

Total size: 2.5 M
Installed size: 2.5 M
Is this ok [y/d/N]: y
Downloading packages:
Running transaction check
Running transaction test


Transaction check error:
  file /usr/share/mysql/czech/errmsg.sys from install of mysql-community-common-5.7.20-1.el7.x86_64 conflicts with file from package mariadb-libs-1:5.5.56-2.el7.x86_64
  file /usr/share/mysql/danish/errmsg.sys from install of mysql-community-common-5.7.20-1.el7.x86_64 conflicts with file from package mariadb-libs-1:5.5.56-2.el7.x86_64
  file /usr/share/mysql/dutch/errmsg.sys from install of mysql-community-common-5.7.20-1.el7.x86_64 conflicts with file from package mariadb-libs-1:5.5.56-2.el7.x86_64
  file /usr/share/mysql/english/errmsg.sys from install of mysql-community-common-5.7.20-1.el7.x86_64 conflicts with file from package mariadb-libs-1:5.5.56-2.el7.x86_64
  file /usr/share/mysql/estonian/errmsg.sys from install of mysql-community-common-5.7.20-1.el7.x86_64 conflicts with file from package mariadb-libs-1:5.5.56-2.el7.x86_64
  file /usr/share/mysql/french/errmsg.sys from install of mysql-community-common-5.7.20-1.el7.x86_64 conflicts with file from package mariadb-libs-1:5.5.56-2.el7.x86_64
  file /usr/share/mysql/german/errmsg.sys from install of mysql-community-common-5.7.20-1.el7.x86_64 conflicts with file from package mariadb-libs-1:5.5.56-2.el7.x86_64
  file /usr/share/mysql/greek/errmsg.sys from install of mysql-community-common-5.7.20-1.el7.x86_64 conflicts with file from package mariadb-libs-1:5.5.56-2.el7.x86_64
  file /usr/share/mysql/hungarian/errmsg.sys from install of mysql-community-common-5.7.20-1.el7.x86_64 conflicts with file from package mariadb-libs-1:5.5.56-2.el7.x86_64
  file /usr/share/mysql/italian/errmsg.sys from install of mysql-community-common-5.7.20-1.el7.x86_64 conflicts with file from package mariadb-libs-1:5.5.56-2.el7.x86_64
  file /usr/share/mysql/japanese/errmsg.sys from install of mysql-community-common-5.7.20-1.el7.x86_64 conflicts with file from package mariadb-libs-1:5.5.56-2.el7.x86_64
  file /usr/share/mysql/korean/errmsg.sys from install of mysql-community-common-5.7.20-1.el7.x86_64 conflicts with file from package mariadb-libs-1:5.5.56-2.el7.x86_64
  file /usr/share/mysql/norwegian-ny/errmsg.sys from install of mysql-community-common-5.7.20-1.el7.x86_64 conflicts with file from package mariadb-libs-1:5.5.56-2.el7.x86_64
  file /usr/share/mysql/norwegian/errmsg.sys from install of mysql-community-common-5.7.20-1.el7.x86_64 conflicts with file from package mariadb-libs-1:5.5.56-2.el7.x86_64
  file /usr/share/mysql/polish/errmsg.sys from install of mysql-community-common-5.7.20-1.el7.x86_64 conflicts with file from package mariadb-libs-1:5.5.56-2.el7.x86_64
  file /usr/share/mysql/portuguese/errmsg.sys from install of mysql-community-common-5.7.20-1.el7.x86_64 conflicts with file from package mariadb-libs-1:5.5.56-2.el7.x86_64
  file /usr/share/mysql/romanian/errmsg.sys from install of mysql-community-common-5.7.20-1.el7.x86_64 conflicts with file from package mariadb-libs-1:5.5.56-2.el7.x86_64
  file /usr/share/mysql/russian/errmsg.sys from install of mysql-community-common-5.7.20-1.el7.x86_64 conflicts with file from package mariadb-libs-1:5.5.56-2.el7.x86_64
  file /usr/share/mysql/serbian/errmsg.sys from install of mysql-community-common-5.7.20-1.el7.x86_64 conflicts with file from package mariadb-libs-1:5.5.56-2.el7.x86_64
  file /usr/share/mysql/slovak/errmsg.sys from install of mysql-community-common-5.7.20-1.el7.x86_64 conflicts with file from package mariadb-libs-1:5.5.56-2.el7.x86_64
  file /usr/share/mysql/spanish/errmsg.sys from install of mysql-community-common-5.7.20-1.el7.x86_64 conflicts with file from package mariadb-libs-1:5.5.56-2.el7.x86_64
  file /usr/share/mysql/swedish/errmsg.sys from install of mysql-community-common-5.7.20-1.el7.x86_64 conflicts with file from package mariadb-libs-1:5.5.56-2.el7.x86_64
  file /usr/share/mysql/ukrainian/errmsg.sys from install of mysql-community-common-5.7.20-1.el7.x86_64 conflicts with file from package mariadb-libs-1:5.5.56-2.el7.x86_64
  file /usr/share/mysql/charsets/Index.xml from install of mysql-community-common-5.7.20-1.el7.x86_64 conflicts with file from package mariadb-libs-1:5.5.56-2.el7.x86_64
  file /usr/share/mysql/charsets/armscii8.xml from install of mysql-community-common-5.7.20-1.el7.x86_64 conflicts with file from package mariadb-libs-1:5.5.56-2.el7.x86_64
  file /usr/share/mysql/charsets/ascii.xml from install of mysql-community-common-5.7.20-1.el7.x86_64 conflicts with file from package mariadb-libs-1:5.5.56-2.el7.x86_64
  file /usr/share/mysql/charsets/cp1250.xml from install of mysql-community-common-5.7.20-1.el7.x86_64 conflicts with file from package mariadb-libs-1:5.5.56-2.el7.x86_64
  file /usr/share/mysql/charsets/cp1256.xml from install of mysql-community-common-5.7.20-1.el7.x86_64 conflicts with file from package mariadb-libs-1:5.5.56-2.el7.x86_64
  file /usr/share/mysql/charsets/cp1257.xml from install of mysql-community-common-5.7.20-1.el7.x86_64 conflicts with file from package mariadb-libs-1:5.5.56-2.el7.x86_64
  file /usr/share/mysql/charsets/cp850.xml from install of mysql-community-common-5.7.20-1.el7.x86_64 conflicts with file from package mariadb-libs-1:5.5.56-2.el7.x86_64
  file /usr/share/mysql/charsets/cp852.xml from install of mysql-community-common-5.7.20-1.el7.x86_64 conflicts with file from package mariadb-libs-1:5.5.56-2.el7.x86_64
  file /usr/share/mysql/charsets/cp866.xml from install of mysql-community-common-5.7.20-1.el7.x86_64 conflicts with file from package mariadb-libs-1:5.5.56-2.el7.x86_64
  file /usr/share/mysql/charsets/dec8.xml from install of mysql-community-common-5.7.20-1.el7.x86_64 conflicts with file from package mariadb-libs-1:5.5.56-2.el7.x86_64
  file /usr/share/mysql/charsets/geostd8.xml from install of mysql-community-common-5.7.20-1.el7.x86_64 conflicts with file from package mariadb-libs-1:5.5.56-2.el7.x86_64
  file /usr/share/mysql/charsets/greek.xml from install of mysql-community-common-5.7.20-1.el7.x86_64 conflicts with file from package mariadb-libs-1:5.5.56-2.el7.x86_64
  file /usr/share/mysql/charsets/hebrew.xml from install of mysql-community-common-5.7.20-1.el7.x86_64 conflicts with file from package mariadb-libs-1:5.5.56-2.el7.x86_64
  file /usr/share/mysql/charsets/hp8.xml from install of mysql-community-common-5.7.20-1.el7.x86_64 conflicts with file from package mariadb-libs-1:5.5.56-2.el7.x86_64
  file /usr/share/mysql/charsets/keybcs2.xml from install of mysql-community-common-5.7.20-1.el7.x86_64 conflicts with file from package mariadb-libs-1:5.5.56-2.el7.x86_64
  file /usr/share/mysql/charsets/koi8r.xml from install of mysql-community-common-5.7.20-1.el7.x86_64 conflicts with file from package mariadb-libs-1:5.5.56-2.el7.x86_64
  file /usr/share/mysql/charsets/koi8u.xml from install of mysql-community-common-5.7.20-1.el7.x86_64 conflicts with file from package mariadb-libs-1:5.5.56-2.el7.x86_64
  file /usr/share/mysql/charsets/latin1.xml from install of mysql-community-common-5.7.20-1.el7.x86_64 conflicts with file from package mariadb-libs-1:5.5.56-2.el7.x86_64
  file /usr/share/mysql/charsets/latin2.xml from install of mysql-community-common-5.7.20-1.el7.x86_64 conflicts with file from package mariadb-libs-1:5.5.56-2.el7.x86_64
  file /usr/share/mysql/charsets/latin5.xml from install of mysql-community-common-5.7.20-1.el7.x86_64 conflicts with file from package mariadb-libs-1:5.5.56-2.el7.x86_64
  file /usr/share/mysql/charsets/latin7.xml from install of mysql-community-common-5.7.20-1.el7.x86_64 conflicts with file from package mariadb-libs-1:5.5.56-2.el7.x86_64
  file /usr/share/mysql/charsets/macce.xml from install of mysql-community-common-5.7.20-1.el7.x86_64 conflicts with file from package mariadb-libs-1:5.5.56-2.el7.x86_64
  file /usr/share/mysql/charsets/macroman.xml from install of mysql-community-common-5.7.20-1.el7.x86_64 conflicts with file from package mariadb-libs-1:5.5.56-2.el7.x86_64
  file /usr/share/mysql/charsets/swe7.xml from install of mysql-community-common-5.7.20-1.el7.x86_64 conflicts with file from package mariadb-libs-1:5.5.56-2.el7.x86_64

Error Summary
-------------
[x@localhost ~]$ sudo yum remove mariadb-libs-1:5.5.56-2.el7.x86_64
Loaded plugins: fastestmirror
Resolving Dependencies
--> Running transaction check
---> Package mariadb-libs.x86_64 1:5.5.56-2.el7 will be erased
--> Processing Dependency: libmysqlclient.so.18()(64bit) for package: 2:postfix-2.10.1-6.el7.x86_64
--> Processing Dependency: libmysqlclient.so.18(libmysqlclient_18)(64bit) for package: 2:postfix-2.10.1-6.el7.x86_64
--> Running transaction check
---> Package postfix.x86_64 2:2.10.1-6.el7 will be erased
--> Finished Dependency Resolution

Dependencies Resolved

=========================================================================================================================================
 Package                           Arch                        Version                              Repository                      Size
=========================================================================================================================================
Removing:
 mariadb-libs                      x86_64                      1:5.5.56-2.el7                       @anaconda                      4.4 M
Removing for dependencies:
 postfix                           x86_64                      2:2.10.1-6.el7                       @anaconda                       12 M

Transaction Summary
=========================================================================================================================================
Remove  1 Package (+1 Dependent package)

Installed size: 17 M
Is this ok [y/N]: y
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Erasing    : 2:postfix-2.10.1-6.el7.x86_64                                                                                         1/2 
  Erasing    : 1:mariadb-libs-5.5.56-2.el7.x86_64                                                                                    2/2 
  Verifying  : 1:mariadb-libs-5.5.56-2.el7.x86_64                                                                                    1/2 
  Verifying  : 2:postfix-2.10.1-6.el7.x86_64                                                                                         2/2 

Removed:
  mariadb-libs.x86_64 1:5.5.56-2.el7                                                                                                     

Dependency Removed:
  postfix.x86_64 2:2.10.1-6.el7                                                                                                          

Complete!

三、修改root本地密码

mysql安装完成之后,在/var/log/mysqld.log文件中给root生成了一个默认密码。通过下面的方式找到root默认密码,然后登录mysql进行修改:

grep 'temporary password' /var/log/mysqld.log

进入MySQL:

mysql -u root -p

查看密码策略

show variables like '%password%'

设置密码策略:

set global validate_password_policy=0;

查看密码策略:

select @@validate_password_policy;

设置密码长度:

set global validate_password_length=4;

查看密码长度:

select @@validate_password_length;

然后你就可以将你的密码改为简单的密码。

alter user 'root'@'localhost' identified by '123456';

或者

set password for 'root'@'localhost'='123456';

此set password for 'root'@'localhost'=password('123456');命令将被弃用。

允许远程访问

grant all privileges on *.* to 'root'@'%' identified by '123456' with grant option;

grant all on *.* to 'root'@'%';

其中123456为你的访问密码。

猜你喜欢

转载自blog.csdn.net/qq_26346457/article/details/79881920