RPM安装与卸载MySQL-5.6.27-1.linux*.x86_64.rpm*(转载出处:“悠悠-我心”的博客)

1.安装准备
1.1查看是否有自带的MySql 库,如果先有卸载

    [root@hadoop02 ~]# rpm -qa | grep mysql
    mysql-libs-5.1.71-1.el6.x86_64
    [root@hadoop02 ~]# rpm -e --nodeps mysql-libs-5.1.71-1.el6.x86_64
    [root@hadoop02 ~]# rpm -qa | grep mysql
    [root@hadoop02 ~]# 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

1.2准备安装文件,并解压 首先你必须明确你的系统版本及对应该的安装文件版本,详情可参考官方文档http://dev.mysql.com/doc/refman/5.6/en/linux-installation-rpm.html
    MySQL Linux RPM包分配标识符
这里写图片描述
MySQL-5.6.27-1.linux_glibc2.5.x86_64.rpm-bundle.tar 顺便分享下载地址:链接:http://pan.baidu.com/s/1c0fXgIG 密码:aa12

[root@cnpc04 cnpc]# tar -zxvf MySQL-5.6.27-1.linux_glibc2.5.x86_64.rpm-bundle.tar 
  • 1

2.安装 数据库

    [root@cnpc04 cnpc]# ls -l 
    total 619924
    drwxr-xr-x. 4 root root       4096 Dec  1 11:56 hadoop-2.2.0
    -rw-r--r--. 1 root root  317399040 Dec  3 23:34 MySQL-5.6.27-1.linux_glibc2.5.x86_64.rpm-bundle.tar
    -rw-r--r--. 1 7155 wheel  23148726 Sep 21 12:32 MySQL-client-5.6.27-1.linux_glibc2.5.x86_64.rpm(客户端)
    -rw-r--r--. 1 7155 wheel   4586751 Sep 21 12:32 MySQL-devel-5.6.27-1.linux_glibc2.5.x86_64.rpm(这个备用)
    -rw-r--r--. 1 7155 wheel 117809689 Sep 21 12:32 MySQL-embedded-5.6.27-1.linux_glibc2.5.x86_64.rpm
    -rw-r--r--. 1 7155 wheel  88838078 Sep 21 12:33 MySQL-server-5.6.27-1.linux_glibc2.5.x86_64.rpm(服务端)
    -rw-r--r--. 1 7155 wheel   2419375 Sep 21 12:33 MySQL-shared-5.6.27-1.linux_glibc2.5.x86_64.rpm
    -rw-r--r--. 1 7155 wheel   5181229 Sep 21 12:33 MySQL-shared-compat-5.6.27-1.linux_glibc2.5.x86_64.rpm
    -rw-r--r--. 1 7155 wheel  75401437 Sep 21 12:34 MySQL-test-5.6.27-1.linux_glibc2.5.x86_64.rpm

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13

2.1 安装服务端MySQL-server

    [root@hadoop04 cnpc]# rpm -ivh MySQL-server-5.6.27-1.linux_glibc2.5.x86_64.rpm 
    warning: MySQL-server-5.6.27-1.linux_glibc2.5.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
    error: Failed dependencies:
        /usr/bin/perl is needed by MySQL-server-5.6.27-1.linux_glibc2.5.x86_64(发现缺少依赖)
  • 1
  • 2
  • 3
  • 4
  • 5

先安装依赖文件(得连网),当然也可 添加两个 参数  –nodeps –force   意义就在于,安装时不再分析包之间的依赖关系而直接安装(个人认为这种方式比较麻烦,如果是新手,后面会出现未知解决不了的错误,我在这上面就浪费了好多时间啊!如果是高手那另当别论……)也就不会再提示error: Failed dependencies:这样的错误了,试试看吧。

    [root@hadoop04 cnpc]# yum install numact1
    [root@hadoop04 cnpc]# yum install libaio
    [root@hadoop04 cnpc]# yum install perl
  • 1
  • 2
  • 3
  • 4
再次尝试安装(ok)
  • 1
  • 2
    [root@hadoop04 cnpc]# rpm -ivh MySQL-server-5.6.27-1.linux_glibc2.5.x86_64.rpm 
    warning: MySQL-server-5.6.27-1.linux_glibc2.5.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
    Preparing...                ########################################### [100%]
       1:MySQL-server           ########################################### [100%]
  • 1
  • 2
  • 3
  • 4
2.2 安装MySQL-devel
  • 1
  • 2
    [root@hadoop04 cnpc]# rpm -ivh MySQL-devel-5.6.27-1.linux_glibc2.5.x86_64.rpm 
    warning: MySQL-devel-5.6.27-1.linux_glibc2.5.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
    Preparing...                ########################################### [100%]
       1:MySQL-devel            ########################################### [100%]
  • 1
  • 2
  • 3
  • 4
  • 5

2.3安装客户端MySQL-client

    [root@hadoop04 cnpc]# rpm -ivh MySQL-client-5.6.27-1.linux_glibc2.5.x86_64.rpm 
    warning: MySQL-client-5.6.27-1.linux_glibc2.5.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
    Preparing...                ########################################### [100%]
       1:MySQL-client           ########################################### [100%]
  • 1
  • 2
  • 3
  • 4
  • 5
2.4修改配置文件位置
  • 1
  • 2
[root@hadoop04 cnpc]# cp /usr/share/mysql/my-default.cnf /etc/my.cnf
  • 1
  • 2
  1. 初始化MySQL及设置密码

    3.1初始化数据库

    [root@hadoop04 cnpc]# /usr/bin/mysql_install_db
  • 1
  • 2

3.2 启动数据库

    [root@hadoop04 cnpc]# service mysql start
    Starting MySQL.. SUCCESS! 
  • 1
  • 2
  • 3

3.3 查看rootp密码(尝试了很久发现5.6之后的版本开始root密码不为空,之前的root密码为空)

    [root@hadoop04 cnpc]# cat /root/.mysql_secret
    # The random password set for the root user at Wed Dec 16 05:31:22 2015 (local time): GkrEoaVae22gNoSR
  • 1
  • 2
  • 3

3.4登录数据库

     [root@hadoop04 cnpc]# mysql -uroot -pGkrEoaVae22gNoSR
  • 1
  • 2

3.5 修改root密码

    mysql> SET PASSWORD = PASSWORD('123456');
    Query OK, 0 rows affected (0.02 sec)
    mysql> quit
    Bye
  • 1
  • 2
  • 3
  • 4
  • 5

3.6 重新登录Ok

    [root@hadoop04 cnpc]# mysql -uroot -p123456
    mysql> show databases;
    +--------------------+
    | Database           |
    +--------------------+
    | information_schema |
    | mysql              |
    | performance_schema |
    | test               |
    +--------------------+
    4 rows in set (0.00 sec)
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12

4.设置允许远程登录

    mysql> use mysql;
    mysql> select host,user,password from user;
    +-----------+------+-------------------------------------------+
    | host      | user | password                                  |
    +-----------+------+-------------------------------------------+
    | localhost | root | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |
    | hadoop04  | root | *AA06F549C92AB6D05F3E5EF242304BC0870D3D90 |
    | 127.0.0.1 | root | *AA06F549C92AB6D05F3E5EF242304BC0870D3D90 |
    | ::1       | root | *AA06F549C92AB6D05F3E5EF242304BC0870D3D90 |
    +-----------+------+-------------------------------------------+
    4 rows in set (0.01 sec)
    mysql> update user set password=password('123456') where user='root';
    Query OK, 3 rows affected (0.00 sec)
    Rows matched: 4  Changed: 3  Warnings: 0

    mysql> update user set host='%' where user='root' and host='localhost';
    Query OK, 1 row affected (0.03 sec)
    Rows matched: 1  Changed: 1  Warnings: 0

    mysql> flush privileges;
    Query OK, 0 rows affected (0.00 sec)
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22

5.设置开机启动

    [root@hadoop04 cnpc]# chkconfig mysql on
    [root@hadoop04 cnpc]# chkconfig --list | grep  mysql
    mysql           0:off   1:off   2:on    3:on    4:on    5:on    6:off


  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

6.修改字符集和数据存储路径
配置/etc/my.cnf文件,修改数据存放路径、mysql.sock路径以及默认编码utf-8.

    [root@hadoop04 cnpc]# vi /etc/my.cnf

    # For advice on how to change settings please see
    # http://dev.mysql.com/doc/refman/5.6/en/server-configuration-defaults.html
    # *** DO NOT EDIT THIS FILE. It's a template which will be copied to the
    # *** default location during install, and will be replaced if you
    # *** upgrade to a newer version of MySQL.

    **#直接复制粘贴
    [client]
    password=123456
    port=3306
    default-character-set=utf8
    [mysqld]
    port=3306
    character_set_server=utf8
    character_set_client=utf8
    collation-server=utf8_general_ci
    #(注意linux下mysql安装完后是默认:表名区分大小写,列名不区分大小写; 0:区分大小写,1:不区分大小写)
    lower_case_table_names=1
    #(设置最大连接数,默认为 151,MySQL服务器允许的最大连接数16384; )
    max_connections=1000
    [mysql]
    default-character-set = utf8**


    [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

    # These are commonly set, remove the # and set as required.
    # basedir = .....
    # datadir = .....
    # port = .....
    # server_id = .....
    # socket = .....

    # 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

    sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53

7.MySQL的默认安装位置

    /var/lib/mysql/               #数据库目录
    /usr/share/mysql              #配置文件目录
    /usr/bin                     #相关命令目录
    /etc/init.d/mysql              #启动脚本
  • 1
  • 2
  • 3
  • 4
  • 5

8.查看字符集

    show variables like '%collation%';
    show variables like '%char%';
  • 1
  • 2
  • 3

9.MySql完全卸载

    [root@hadoop04 ~]# rpm -aq | grep -i mysql
    MySQL-devel-5.6.27-1.linux_glibc2.5.x86_64
    MySQL-server-5.6.27-1.linux_glibc2.5.x86_64
    MySQL-client-5.6.27-1.linux_glibc2.5.x86_64

    [root@hadoop04 ~]# rpm -e --nodeps MySQL-devel-5.6.27-1.linux_glibc2.5.x86_64
    [root@hadoop04 ~]# rpm -e --nodeps MySQL-server-5.6.27-1.linux_glibc2.5.x86_64
    [root@hadoop04 ~]# rpm -e --nodeps MySQL-client-5.6.27-1.linux_glibc2.5.x86_64
    [root@hadoop04 ~]# rpm -aq | grep -i mysql
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10

卸载完成!

你可能感兴趣的:(mysql,之rpm包安装卸载全过程详解)