CentOS 7 安装MySQL8

安装

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

    CentOS选择Red Hat Enterprise Linuxmysql

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

    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个文件vim

    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 根据检查出来的名字输入tcp

  5. 安装ide

    • 安装 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 --forceurl

    • 安装 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

为空,大功告成

相关文章
相关标签/搜索