linux安装mysql全纪录[包括yum和rpm安装,编码,远程连接以及大小写问题]

图片 16

一.概述

  上一章讲到了RPM安装后的文件目录,这章还是介绍下安装步骤。也便以后做参考吧。

  1. 移出centos 7系统自带的mysql库

  yum remove mysql-libs 

    图片 1

  2. 将下载的mysql包放到/home/hsr/tool
目录下(mysql-5.7.20-1.el7.x86_64.rpm-bundle.tar)

   图片 2
  3. 解压到mysql文件夹下的rpm包
    图片 3

  4.必备的4个rpm安装

  rpm -ivh mysql-community-common-5.7.20-1.el7.x86_64.rpm

    图片 4

rpm -ivh mysql-community-libs-5.7.20-1.el7.x86_64.rpm

    图片 5

rpm -ivh mysql-community-client-5.7.20-1.el7.x86_64.rpm

    图片 6

rpm -ivh mysql-community-server-5.7.20-1.el7.x86_64.rpm

    图片 7
  5. 查看服务状态
     图片 8
  6.查看初始密码

cat /var/log/mysqld.log | grep password

    图片 9
  7.复制出密码登录
    图片 10
  8. 修改密码
    登录成功后在创建库里会提示如下:
    图片 11

SET PASSWORD = PASSWORD('js*2015');

    图片 12

    上图Reset密码时:提示您当前的密码不符合策略要求,也就是太简单。把密码级别设到最低

set global validate_password_policy=0;

    图片 13
    再重置密码:

SET PASSWORD = PASSWORD('js*2015%');

    图片 14
  9.允许远程连接

GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'js*2015%' WITH GRANT OPTION;  

    图片 15
  这样,我们就可以在windows电脑上用mysql客户端远程连接linux上的mysql服务了。如果在windows电脑上连接不了,先用telnet
来拼下ip和端口,检查防火墙

 

linux安装mysql全纪录[包括yum和rpm安装,编码,远程连接以及大小写问题]

一、查看mysql是否已经安装

使用“whereis mysql”命令来查看mysql安装路径:

[root@hadoop01 ~]# whereis mysql
mysql: /usr/bin/mysql /usr/lib64/mysql /usr/share/mysql
/usr/share/man/man1/mysql.1.gz

 

使用前提是你的MySQL不是解压版的,而是rpm包或者使用yum命令安装的;

备注:“whereis”命令用于查看软件的安装路径。

使用“rpm –qa|grep mysql”查看安装了哪些MySQL的rpm包:

[root@hadoop01 ~]# rpm -qa|grep mysql
mysql-community-common-5.6.35-2.el6.x86_64
mysql-community-libs-5.6.35-2.el6.x86_64
mysql-community-release-el6-5.noarch
mysql-community-client-5.6.35-2.el6.x86_64
mysql-community-server-5.6.35-2.el6.x86_64

 

二、卸载MySQL

[root@hadoop01 ~]# rpm -qa|grep mysql      先查看mysql的安装包有哪些
mysql-community-release-el6-5.noarch
mysql-community-common-5.6.26-2.el6.i686
[root@hadoop01 ~]# yum remove mysql-community-release-el6-5.noarch mysql-community-common-5.6.26-2.el6.i686   删除安装包
Loaded plugins: fastestmirror, refresh-packagekit, security
Setting up Remove Process
Resolving Dependencies
--> Running transaction check
---> Package mysql-community-common.i686 0:5.6.26-2.el6 will be erased
---> Package mysql-community-release.noarch 0:el6-5 will be erased
--> Finished Dependency Resolution

Dependencies Resolved

=======================================================================================================================
 Package                     Arch          Version             Repository                                  Size
=======================================================================================================================
Removing:
 mysql-community-common      i686          5.6.26-2.el6        installed                                   2.1 M
 mysql-community-release     noarch        el6-5               @/mysql-community-release-el6-5.noarch      4.3 k

Transaction Summary
=======================================================================================================================
Remove        2 Package(s)

Installed size: 2.1 M
Is this ok [y/N]: y                 输入y,确定
Downloading Packages:
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
  Erasing    : mysql-community-release-el6-5.noarch                          1/2 
  Erasing    : mysql-community-common-5.6.26-2.el6.i686                      2/2 
  Verifying  : mysql-community-common-5.6.26-2.el6.i686                      1/2 
  Verifying  : mysql-community-release-el6-5.noarch                          2/2 

Removed:
  mysql-community-common.i686 0:5.6.26-2.el6             mysql-community-release.noarch 0:el6-5                                          

Complete!
[root@hadoop01 ~]# rpm -qa|grep mysql        再次查看mysql的安装包
[root@hadoop01 ~]#

删除我们在mysql中创建的数据库:

MySQL创建的数据库一般位于“/var/lib/mysql”目录下,将“/var/lib/mysq”目录删除即可,否则在安装新的MySQL的时候,它发现已经有数据库了,就不会创建新的数据库了。

三、安装mysql

1.下载MySQL安装包

我们这里安装的mysql的版本是6.5。

MySQL的安装方式有两种,一种是用yum安装,yum会自动联网下载rpm包进行安装;一种是用rpm命令安装,需要自己手动下载MySQL的rmp安装包。我们这里先介绍使用yum安装方法。

首先到oracle官网下载“mysql-community-release-el6-5.noarch.rpm”,该文件很小,是MySQL的yum源包,里面只是记录了MySQL的yum地址。

图片 16

 

2.安装mysql的yum仓库

将下载的源“mysql-community-release-el6-5.noarch.rpm”上传到linux服务器,使用yum命令安装此源:

yum localinstall mysql-community-release-el6-5.noarch.rpm

 

[root@hadoop01 mysql]# ll
total 12
drwxr-xr-x. 2 root root 4096 Dec  7 04:34 mysql5.6-rpm
-rw-r--r--. 1 root root 5824 Aug  1  2015 mysql-community-release-el6-5.noarch.rpm
[root@hadoop01 mysql]# yum localinstall mysql-community-release-el6-5.noarch.rpm 
Loaded plugins: fastestmirror, refresh-packagekit, security
Setting up Local Package Process
Examining mysql-community-release-el6-5.noarch.rpm: mysql-community-release-el6-5.noarch
Marking mysql-community-release-el6-5.noarch.rpm to be installed
Loading mirror speeds from cached hostfile
Resolving Dependencies
--> Running transaction check
---> Package mysql-community-release.noarch 0:el6-5 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

===========================================================================================================
 Package                       Arch       Version    Repository                             Size
===========================================================================================================
Installing:
 mysql-community-release       noarch     el6-5      /mysql-community-release-el6-5.noarch  4.3 k

Transaction Summary
===========================================================================================================
Install       1 Package(s)

Total size: 4.3 k
Installed size: 4.3 k
Is this ok [y/N]: y
Downloading Packages:
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
  Installing : mysql-community-release-el6-5.noarch                 1/1 
  Verifying  : mysql-community-release-el6-5.noarch                 1/1 

Installed:
  mysql-community-release.noarch 0:el6-5

Complete!
[root@hadoop01 mysql]#

3.安装mysql

yum install mysql-server

 

执行此命令之前,必须保证linux虚拟机能够连接到外网,否则是安装不成的,只要能够连上外网,安装就不会有问题,下面是安装的记录:

[root@hadoop01 mysql]# yum install mysql-server
Loaded plugins: fastestmirror, refresh-packagekit, security
Setting up Install Process
Loading mirror speeds from cached hostfile
c6-media                                       | 4.0 kB     00:00     
mysql-connectors-community                     | 2.5 kB     00:00     
mysql-connectors-community/primary_db          |  13 kB     00:00     
mysql-tools-community                          | 2.5 kB     00:00     
mysql-tools-community/primary_db               |  34 kB     00:00     
mysql56-community                              | 2.5 kB     00:00     
mysql56-community/primary_db                   | 176 kB     00:00     
Package mysql-server is obsoleted by mysql-community-server, trying to install mysql-community-server-5.6.35-2.el6.x86_64 instead
Resolving Dependencies
--> Running transaction check
---> Package mysql-community-server.x86_64 0:5.6.35-2.el6 will be installed
--> Processing Dependency: mysql-community-common(x86-64) = 5.6.35-2.el6 for package: mysql-community-server-5.6.35-2.el6.x86_64
--> Processing Dependency: mysql-community-client(x86-64) >= 5.6.10 for package: mysql-community-server-5.6.35-2.el6.x86_64
--> Processing Dependency: perl(DBI) for package: mysql-community-server-5.6.35-2.el6.x86_64
--> Running transaction check
---> Package mysql-community-client.x86_64 0:5.6.35-2.el6 will be installed
--> Processing Dependency: mysql-community-libs(x86-64) >= 5.6.10 for package: mysql-community-client-5.6.35-2.el6.x86_64
---> Package mysql-community-common.x86_64 0:5.6.35-2.el6 will be installed
---> Package perl-DBI.x86_64 0:1.609-4.el6 will be installed
--> Running transaction check
---> Package mysql-community-libs.x86_64 0:5.6.35-2.el6 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

=================================================================================================
 Package                      Arch         Version           Repository             Size
=================================================================================================
Installing:
 mysql-community-server       x86_64       5.6.35-2.el6      mysql56-community      54 M
Installing for dependencies:
 mysql-community-client       x86_64       5.6.35-2.el6      mysql56-community      18 M
 mysql-community-common       x86_64       5.6.35-2.el6      mysql56-community      308 k
 mysql-community-libs         x86_64       5.6.35-2.el6      mysql56-community      1.9 M
 perl-DBI                     x86_64       1.609-4.el6       c6-media               705 k

Transaction Summary
=================================================================================================
Install       5 Package(s)

Total download size: 75 M
Installed size: 336 M
Is this ok [y/N]: y
Downloading Packages:
(1/5): mysql-community-client-5.6.35-2.el6.x86_64.rpm           |  18 MB     00:19     
(2/5): mysql-community-common-5.6.35-2.el6.x86_64.rpm           | 308 kB     00:00     
(3/5): mysql-community-libs-5.6.35-2.el6.x86_64.rpm             | 1.9 MB     00:02     
(4/5): mysql-community-server-5.6.35-2.el6.x86_64.rpm           |  54 MB     01:17     
(5/5): perl-DBI-1.609-4.el6.x86_64.rpm                          | 705 kB     00:00     
-------------------------------------------------------------------------------------------------
Total                                                           767 kB/s |  75 MB     01:40     
warning: rpmts_HdrFromFdno: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Retrieving key from file:/etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
Importing GPG key 0x5072E1F5:
 Userid : MySQL Release Engineering <mysql-build@oss.oracle.com>
 Package: mysql-community-release-el6-5.noarch (@/mysql-community-release-el6-5.noarch)
 From   : file:/etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
Is this ok [y/N]: y
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
  Installing : mysql-community-common-5.6.35-2.el6.x86_64                  1/5 
  Installing : mysql-community-libs-5.6.35-2.el6.x86_64                    2/5 
  Installing : mysql-community-client-5.6.35-2.el6.x86_64                  3/5 
  Installing : perl-DBI-1.609-4.el6.x86_64                                 4/5 
  Installing : mysql-community-server-5.6.35-2.el6.x86_64                  5/5 
warning: /etc/my.cnf created as /etc/my.cnf.rpmnew
  Verifying  : mysql-community-client-5.6.35-2.el6.x86_64                  1/5 
  Verifying  : mysql-community-common-5.6.35-2.el6.x86_64                  2/5 
  Verifying  : mysql-community-libs-5.6.35-2.el6.x86_64                    3/5 
  Verifying  : mysql-community-server-5.6.35-2.el6.x86_64                  4/5 
  Verifying  : perl-DBI-1.609-4.el6.x86_64                                 5/5 

Installed:
  mysql-community-server.x86_64 0:5.6.35-2.el6                             

Dependency Installed:
  mysql-community-client.x86_64 0:5.6.35-2.el6 
  mysql-community-common.x86_64 0:5.6.35-2.el6 
  mysql-community-libs.x86_64 0:5.6.35-2.el6 
  perl-DBI.x86_64 0:1.609-4.el6

Complete!
[root@hadoop01 mysql]# rpm -qa|grep mysql    查看已经安装的mysql的rpm包
mysql-community-common-5.6.35-2.el6.x86_64
mysql-community-libs-5.6.35-2.el6.x86_64
mysql-community-release-el6-5.noarch
mysql-community-client-5.6.35-2.el6.x86_64
mysql-community-server-5.6.35-2.el6.x86_64
[root@hadoop01 mysql]# whereis mysql     查看mysql安装的路径
mysql: /usr/bin/mysql /usr/lib64/mysql /usr/share/mysql /usr/share/man/man1/mysql.1.gz
[root@hadoop01 mysql]#
[root@hadoop01 mysql]# ls /var/lib/mysql     我们创建的数据库都会存储在这个目录下面
[root@hadoop01 mysql]#