linux上安装MySQL

环境:centos7   mysql8.0.18

编译安装参见:https://www.cnblogs.com/fanshudada/p/9781794.html

下面使用rpm安装

一、下载mysql服务软件包

  地址:https://dev.mysql.com/downloads/mysql/

  rpm package:是某个特定的包,比如server,client,devle等    
  rpm bundle:是该版本所有包的集合                                         
  Compressed TAR Archive,是源码,必须用源码方式安装  

  Compatibility Libraries:兼容库  

  Shared Libraries:共享库  

  Development Libraries:开发库  

  Test Suite:测试套件

  Client Utilities:客户端工具

  下载时注意选则好对应的版本

 

二、安装

  相关依赖包:openssl  openssl-devel  libaio    libaio-devel

  (1)rpm -ivh  mysql-community-libs-8.0.18-1.el7.x86_64

  报错信息:

  error: Failed dependencies:

  mariadb-libs is obsoleted by mysql-community-libs-8.0.18-1.el7.x86_64

  原因:mariadb-libs和 mysql-community-libs冲突

  解决办法:卸载mariadb-libs

  a.查询mariadb-libs的包名

  [root@izm5e8nyz28va3a786y465z src]# rpm -qa |grep mariadb

  mariadb-libs-5.5.64-1.el7.x86_64

  b.卸载该包

   [root@izm5e8nyz28va3a786y465z src]# rpm -ev mariadb-libs-5.5.64-1.el7.x86_64 或   rpm -ev --nodeps  包名  (不卸载相关依赖)

    error: Failed dependencies:

    libmysqlclient.so.18()(64bit) is needed by (installed) postfix-2:2.10.1-7.el7.x86_64
    libmysqlclient.so.18(libmysqlclient_18)(64bit) is needed by (installed) postfix-2:2.10.1-7.el7.x86_64

    报错原因:postfix是mariadb 的依赖包,要先卸载它

    [root@izm5e8nyz28va3a786y465z src]# rpm -qa |grep postfix

    postfix-2.10.1-7.el7.x86_64
    [root@izm5e8nyz28va3a786y465z src]# rpm -ev postfix-2.10.1-7.el7.x86_64
    error: Failed dependencies:
    /usr/sbin/sendmail is needed by (installed) redhat-lsb-core-4.1-27.el7.centos.1.x86_64
    [root@izm5e8nyz28va3a786y465z src]# rpm -qa |grep redhat-lsb
    redhat-lsb-core-4.1-27.el7.centos.1.x86_64
    redhat-lsb-submod-security-4.1-27.el7.centos.1.x86_64
    [root@izm5e8nyz28va3a786y465z src]# rpm -ev redhat-lsb-core-4.1-27.el7.centos.1.x86_64
    Preparing packages...
    redhat-lsb-core-4.1-27.el7.centos.1.x86_64

    [root@izm5e8nyz28va3a786y465z src]# rpm -ev postfix-2.10.1-7.el7.x86_64

    Preparing packages...
    postfix-2:2.10.1-7.el7.x86_64

    上述步骤成功卸载掉mariadb-libs的依赖
    [root@izm5e8nyz28va3a786y465z src]# rpm -ev mariadb-libs-5.5.64-1.el7.x86_64
    Preparing packages...
    mariadb-libs-1:5.5.64-1.el7.x86_64

    继续安装:

    [root@izm5e8nyz28va3a786y465z src]# rpm -ivh mysql-community-libs-8.0.18-1.el7.x86_64.rpm
    warning: mysql-community-libs-8.0.18-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
    Preparing... ################################# [100%]
    Updating / installing...
    1:mysql-community-libs-8.0.18-1.el7################################# [100%]

    mysql-community-libs-8.0.18-1.el7包安装成功

    (2) rpm -ivh mysql-community-common-8.0.18-1.el7.x86_64.rpm

    (3) rpm -ivh mysql-community-client-8.0.18-1.el7.x86_64.rpm

    (4) rpm -ivh mysql-community-server-8.0.18-1.el7.x86_64.rpm 

      error: Failed dependencies:

      libaio.so.1()(64bit) is needed by mysql-community-server-8.0.18-1.el7.x86_64

      libaio.so.1(LIBAIO_0.1)(64bit) is needed by mysql-community-server-8.0.18-1.el7.x86_64
      libaio.so.1(LIBAIO_0.4)(64bit) is needed by mysql-community-server-8.0.18-1.el7.x86_64

      解决依赖关系:

      [root@izm5e8nyz28va3a786y465z src]# yum list |grep libaio

      libaio.i686 0.3.109-13.el7 base
      libaio.x86_64 0.3.109-13.el7 base
      libaio-devel.i686 0.3.109-13.el7 base
      libaio-devel.x86_64 0.3.109-13.el7 base

      查询到4个相关的依赖包,只需安装libaio.x86_64    libaio-devel.x86_64

      yum  -y install  libaio.x86_64    libaio-devel.x86_64

      [root@izm5e8nyz28va3a786y465z src]# rpm -ivh mysql-community-server-8.0.18-1.el7.x86_64.rpm 

      warning: mysql-community-server-8.0.18-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
      Preparing... ################################# [100%]
      Updating / installing...
        1:mysql-community-server-8.0.18-1.e################################# [100%]

    (5)rpm -ivh mysql-community-devel-8.0.18-1.el7.x86_64.rpm 

      error: Failed dependencies:

      pkgconfig(openssl) is needed by mysql-community-devel-8.0.18-1.el7.x86_64

      解决依赖关系:

      yum  -y  install  openssl  openssl-devel

      [root@izm5e8nyz28va3a786y465z src]# rpm -ivh mysql-community-devel-8.0.18-1.el7.x86_64.rpm 

      warning: mysql-community-devel-8.0.18-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
      Preparing... ################################# [100%]
      Updating / installing...
      1:mysql-community-devel-8.0.18-1.el################################# [100%]

    至此Mysql安装成功

    小结:1. 卸载掉冲突组件  mariadb

        rpm -ev redhat-lsb-core-4.1-27.el7.centos.1.x86_64  postfix-2.10.1-7.el7.x86_64   mariadb-libs-5.5.64-1.el7.x86_64

       2.安装相关依赖:

        yum  -y  install  openssl  openssl-devel  libaio    libaio-devel

 

三、mysql服务设置

   1.启动mysql服务:systemctl start mysqld.service

    查看MySQL服务是否启动:netstat -tunpl |grep mysqld

    

   2.登录MySQL修改密码

    (1)登录mysql

    2种方法:跳过密码验证登录   或    查看初始密码登录

     a.查看初始密码登录

    cat  /var/log/mysqld.log

    ...   2019-11-11T14:28:57.523108Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: ,2sg6>HrQdF!    

    标红加粗部分为初始密码    mysql -uroot  -p    键入密码可以登录MySQL

    b.跳过密码验证登录

    修改my.cnf文件,在[mysqld]区域下加入skip-grant-tables  重启MySQL

    [root@izm5e8nyz28va3a786y465z ~]# find / -name my.cnf
    /etc/my.cnf

    [root@izm5e8nyz28va3a786y465z ~]# vim /etc/my.cnf     

    [root@izm5e8nyz28va3a786y465z run]# systemctl restart mysqld.service

    [root@izm5e8nyz28va3a786y465z run]# mysql   #可直接登录MySQL

    注意:修改密码后,将my.cnf文件内容还原

    (2)修改密码,2sg6>HrQdF!sf

    mysql> alter user 'root'@'localhost' identified by 'root123'; 

    ERROR 1819 (HY000): Your password does not satisfy the current policy requirements

    原因:密码设置的太过简单,初始密码方针:必须包含数字、大写字母、小写字母、特殊符号、长度8位以上。

    mysql> flush privileges;

  3.设置字符编码(从MySQL8.0开始,默认字符集就是utf8mb4 了) 

    # 当前session 

    set session character_set_server='utf8';

    set session collation_server='utf8_bin';

    set names 'utf8'; 

    # 全局

    set global character_set_server='utf8'; 

    set global collation_server='utf8_bin';

    #配置文件(/etc/my.cnf)

    [client]

    default-character-set = utf8mb4  #客户端字符编码

    [mysqld]

    character-set-server = utf8mb4  #服务端字符编码

    查看默认字符集:

    show global variables like '%character_set%';

    查看支持的字符集:

    show character  set;

  4.设置远程登录用户和密码

     1.设置已有用户远程登录

      update  user  set  Host='%'  where  User='root';

      flush  privileges;

     2.新建远程登录用户

      mysql> create user 'xiaobai' identified by 'Abc1234!';

      mysql> grant all privileges on *.* to 'xiaobai'@'%' with grant option;

      mysql>flush  privileges;

      连接失败,提示  验证插件'caching_sha2_password'不能loade

      原因:新版本的MySQL使用的是caching_sha2_password验证方式,但此时的navicat还没有支持这种验证方式

      解决办法:更改加密方式

        查看用户加密方式:

        mysql> select user,plugin from user where user='root';
        +------+-----------------------+
        | user | plugin |
        +------+-----------------------+
        | root | caching_sha2_password |
        +------+-----------------------+

        更改加密方式:

        mysql> alter user 'root'@'%' identified by ',2sg6>HrQdF!sf' password expire never;    #设置密码永不过期(此步非必须)

        mysql>  ALTER USER 'root'@'%' identified with mysql_native_password BY ',2sg6>HrQdF!sf';  #设置为老的加密方式

        mysql> select user,plugin from user where user='root';    #加密方式已修改成功
        +------+-----------------------+
        | user | plugin |
        +------+-----------------------+
        | root | mysql_native_password |
        +------+-----------------------+

         刷新权限:flush  privileges    #可连接成功

       

 

 

 

 

 

 

 

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值