zoukankan      html  css  js  c++  java
  • 【Linux】CentOS 7.4 安装 MySQL 8.0.12 解压版

    安装环境/工具

      1、Linux(CentOS 7.4版)

      2、mysql-8.0.12-el7-x86_64.tar.gz

    安装步骤

      参考:https://dev.mysql.com/doc/refman/8.0/en/installing.html

      1、下载mysql解压版(mysql-8.0.12-el7-x86_64.tar.gz),下载地址http://dev.mysql.com/downloads/mysql/

      

        

        

      2、解压mysql安装文件

      命令:tar zxvf mysql-8.0.12-el7-x86_64.tar.gz

      3、复制解压后的mysql到软件目录:

      命令:cp -r mysql-8.0.12-el7-x86_64 /data/soft/

      4、添加系统mysql组和mysql用户:

      命令:groupadd mysql

      命令:useradd -r -g mysql -s /bin/false mysql

      5、安装数据库

      a、进入安装mysql软件目录:

      命令: cd /data/soft/mysql-8.0.12-el7-x86_64

      mysql目录结构
      

    目录目录的内容
    bin mysqld服务器,客户端和实用程序
    docs 信息格式的MySQL手册
    man Unix手册页
    include 包含(标题)文件
    lib 图书馆
    share 用于数据库安装的错误消息,字典和SQL
    support-files 其他支持文件

     

      

      b、修改当前目录拥有者为mysql用户:

     

      命令: chown -R mysql:mysql ./

     

      c、配置mysql配置文件,命令:vim /etc/my.cnf

     1 [client]
     2 default-character-set=utf8
     3 socket=/data/soft/mysql-8.0.12-el7-x86_64/data/mysql.sock
     4 
     5 [mysqld]
     6 
     7 # 设置mysql客户端连接服务端时默认使用的端口
     8 port=3306 
     9 
    10 basedir=/data/soft/mysql-8.0.12-el7-x86_64 # 设置mysql的安装目录
    11 datadir=/data/soft/mysql-8.0.12-el7-x86_64/data
    12 
    13 socket=/data/soft/mysql-8.0.12-el7-x86_64/data/mysql.sock
    14 
    15 # Disabling symbolic-links is recommended to prevent assorted security risks
    16 symbolic-links=0
    17 
    18 # Settings user and group are ignored when systemd is used.
    19 # If you need to run mysqld under a different user or group,
    20 # customize your systemd unit file for mariadb according to the
    21 # instructions in http://fedoraproject.org/wiki/Systemd
    22 
    23 [mysqld_safe]
    24 log-error=/data/log/mysql-log/error.log
    25 pid-file=/data/soft/mysql-8.0.12-el7-x86_64/data/mysql.pid
    26 
    27 #
    28 # include all files from the config directory
    29 #
    30 !includedir /etc/my.cnf.d

     

      d、创建日志文件(:wq保存退出,创建一个空文件即可),并且授权:

      命令:  vim /data/log/mysql-log/error.log 

      命令:  chown mysql:mysql /data/log/mysql-log/error.log 

      e、初始化数据目录,包括mysql包含初始MySQL授权表的 数据库,该表确定如何允许用户连接到服务器     

      命令:bin/mysqld --initialize --user=mysql

      若出现:./bin/mysqld: error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory

      因为没有安装libaio 库,MySQL依赖于libaio 库,安装libaio 库
      命令:yum search libaio

      命令:yum install libaio

      

      初始化数据库后,记录中出现了初始密码,没有初始密码可以去日志中查找,用户名:root,密码:!+Ejv-)lu0r>

      f、如果您希望服务器能够部署并自动支持安全连接,请使用 mysql_ssl_rsa_setup实用程序创建默认的SSL和RSA文件

      命令:bin/mysql_ssl_rsa_setup

      6.添加开机启动mysql服务和启动mysql服务

      添加mysql服务

      命令:cp support-files/mysql.server /etc/init.d/mysql

      启动mysql服务

      命令:service mysql start

         关闭mysql服务

      命令:service mysql stop

      添加开机启动服务

      命令:chkconfig --add mysql

      7、添加mysql系统命令,修改系统文件,添加内容,是内容生效。

      修改系统文件命令:vim /etc/profile 

      

      内容生效命令:source /etc/profile

      8.修改mysql的root用户密码,root初始密码为在日志中上面有提到

      a、进入数据库命令:mysql -u root -p

      

      b、修改密码命令:alter user 'root'@'localhost' identified by 'newpassword';

      

      c、刷新权限命令:flush privileges;

      

      退出数据库,即可用root用户和新密码登录数据库

      d、退出数据库

      命令:quit;

      

      9、查看数据库user表,注意mysql 5.8密码字段改为authentication_string。

      命令:select host,user,authentication_string from user;

      10、配置远程登录

      修改远程登登录命令:update user set `Host` = '%' where `User` = 'root' limit 1;

      然后刷新权限命令:flush privileges;

      

      完成以上步骤即可远程连接MySQL数据库了

      11、新增用户

      命令:create user 'test'@'%' identified by '123456';

      12、给用户授权

      命令:grant all privileges on *.* to test@'%' with grant option;

      13、如果是用navicat连接,由于mysql8的加密方式不同,需要使用navicat的加密方式,修改密码

      命令:alter user 'test'@'%' identified with mysql_native_password by '123456';

     

  • 相关阅读:
    PHP排序问题
    正则表达式——获取指定IP的物理地址
    两款网站页面翻译插件
    正则表达式应用之提炼歌词
    PHP 读取网页文件
    PHP正则表达式——匹配多行
    正则表达式——获取指定IP的物理地址(二)
    用百度音乐Widget从此不在为找MP3外链而烦恼
    I Saw Thee Weep
    POJ 3281 Dining
  • 原文地址:https://www.cnblogs.com/h--d/p/9556758.html
Copyright © 2011-2022 走看看