首页 > 数据库技术 > 详细

CentOS 7 安装MySQL8

时间:2019-10-08 00:37:50      阅读:86      评论:0      收藏:0      [点我收藏+]

安装

  1. 下载Linux对应的MySQL https://dev.mysql.com/downloads/mysql/

    CentOS选择Red Hat Enterprise Linux

  2. 在/usr/local/目录下新建目录mysql

     cd /usr/local/
     mkdir mysql
     cd mysql/
  3. 打开文件传输工具将下载的压缩包 mysql-8.0.17-1.el7.x86_64.rpm-bundle.tar 放到此目录
    解压 tar -xvf mysql-8.0.17-1.el7.x86_64.rpm-bundle.tar

    解压出来8个文件

     mysql-community-client-8.0.17-1.el7.x86_64.rpm
     mysql-community-common-8.0.17-1.el7.x86_64.rpm
     mysql-community-devel-8.0.17-1.el7.x86_64.rpm
     mysql-community-embedded-compat-8.0.17-1.el7.x86_64.rpm
     mysql-community-libs-8.0.17-1.el7.x86_64.rpm
     mysql-community-libs-compat-8.0.17-1.el7.x86_64.rpm
     mysql-community-server-8.0.17-1.el7.x86_64.rpm
     mysql-community-test-8.0.17-1.el7.x86_64.rpm
  4. 检查是否有预装数据库mariadb rpm -qa | grep mariadb 及是否预装mysql

    检测出来了就移除 rpm -e mariadb-libs-..... --nodeps 根据检查出来的名字输入

  5. 安装

    • 安装 common rpm -ivh mysql-community-common-8.0.17-1.el7.x86_64.rpm --nodeps --force

    • 安装 libs rpm -ivh mysql-community-libs-8.0.17-1.el7.x86_64.rpm --nodeps --force
    • 安装 client rpm -ivh mysql-community-client-8.0.17-1.el7.x86_64.rpm --nodeps --force
    • 安装 server rpm -ivh mysql-community-server-8.0.17-1.el7.x86_64.rpm --nodeps --force
    • 查看已安装的包 rpm -qa | grep mysql

        [root@izuf63okxpwhhlr3bu263dz mysql]# rpm -qa | grep mysql
        mysql-community-libs-8.0.17-1.el7.x86_64
        mysql-community-server-8.0.17-1.el7.x86_64
        mysql-community-common-8.0.17-1.el7.x86_64
        mysql-community-client-8.0.17-1.el7.x86_64
  6. 初始化

    • 通过一下命令完成mysql初始化

        mysqld --initialize

      如果报如下错误信息:

        mysqld:error while loading shared libraries: libaio.so.1: cannot open shared object file: No shch file or directory

      则安装下 libaio.so.1

        # 方案1
        yum install -y libaio
      
        # 方案2,如果方案1安装后,继续初始化mysql没成功,则执行该方案
        yum install -y libaio.so.1
    • 授权服务

        # 给mysql目录授权,一般不用操作,root用户拥有所有权限
        chown mysql:mysql /var/lib/mysql -R;
      
        # 启动mysql服务
        systemctl start mysqld.service;
      
        # 配置开机启动
        systemctl enable mysqld;
    • 查看数据库默认密码 cat /var/log/mysqld.log | grep password

        [root@izuf63okxpwhhlr3bu263dz mysql]# cat /var/log/mysqld.log | grep password
        2019-10-07T08:45:06.207436Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: gfn,!V/j7tlz
    • 拿到查询出的密码进行数据库的登录 mysql -u root -p gfn,!V/j7tlz
    • 修改默认密码 alter user ‘root‘@‘localhost‘ identified with mysql_native_password by ‘root‘;
      修改后退出以修改后的密码重新登录
    • 授权远程访问

        create user 'root'@'%' identified with mysql_native_password by '123456';
        grant all privileges on *.* to 'root'@'%' with grant option;
        flush privileges;
    • 此时采用Navicat等可视化客户端可能无法连接,因为端口未对外开放

  7. 防火墙配置

     # 查看防火墙状态
     systemctl status firewalld
    
     # 启动防火墙,防火墙启动后,除了22端口对外能够访问,其他端口军不能使用,所以需要添加
     systemctl start firewalld
    
     # 添加端口
     firewall-cmd --zone=public --add-port=80/tcp --permanent
     firewall-cmd --zone=public --add-port=443/tcp --permanent
     firewall-cmd --zone=public --add-port=3306/tcp --permanent
    
     # 重新加载
     firewall-cmd --reload
  8. 其他

    • 查看MySQL配置文件

        # 默认的配置文件为: /etc/my.cnf
        cat /etc/my.cnf
    • 查看进程语句 ps -ef | grep mysql

大功告成

遗留问题

  • Linux下的MySQL数据库大小写敏感,所以SQL语句中的表名区分大小写
  • 忽略大小写配置

      $ vim /etc/my.cnf
      [mysqld]
      lower_case_table_names=1

但是在MySQL8 这样不行,网上有说要在初始化的时候设置才有效 --initialize --lower-case-table-names=1 但是我怎么试也不行,只要启动服务就报错

    [root@izuf63okxpwhhlr3bu263dz mysql]# systemctl start mysqld.service;
    Job for mysqld.service failed because the control process exited with error code. See "systemctl status mysqld.service" and "journalctl -xe" for details.

折腾半天只好让它大小写敏感去吧,反正我也不是运维

卸载

  1. 关闭mysql服务

     [root@izuf63okxpwhhlr3bu263dz mysql]# service mysqld stop
     Redirecting to /bin/systemctl stop  mysqld.service
  2. 查看安装的mysql

     [root@izuf63okxpwhhlr3bu263dz mysql]# rpm -qa | grep -i mysql
     mysql-community-libs-8.0.17-1.el7.x86_64
     mysql-community-server-8.0.17-1.el7.x86_64
     mysql-community-common-8.0.17-1.el7.x86_64
     mysql-community-client-8.0.17-1.el7.x86_64
  3. 卸载列出来的所有mysql

    rpm -ev mysql-community-......... --nodeps

  4. 删除mysql相关

     find / -name mysql
     rm -rf /var/lib/mysql/
     ......
  5. 删除my.cnf

    rm -rf /etc/my.cnf

  6. 检查卸载情况

    rpm -qa|grep -i mysql

为空,大功告成

CentOS 7 安装MySQL8

原文:https://www.cnblogs.com/yxmhl/p/11633047.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!