【Linux】CentOS 7.4 安装 MySQL 8.0.12 解压版

时间:2023-03-09 15:54:12
【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/

  【Linux】CentOS 7.4 安装 MySQL 8.0.12 解压版

    【Linux】CentOS 7.4 安装 MySQL 8.0.12 解压版

    

  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

 [client]
default-character-set=utf8
socket=/data/soft/mysql-8.0.12-el7-x86_64/data/mysql.sock [mysqld] # 设置mysql客户端连接服务端时默认使用的端口
port=3306 basedir=/data/soft/mysql-8.0.12-el7-x86_64 # 设置mysql的安装目录
datadir=/data/soft/mysql-8.0.12-el7-x86_64/data socket=/data/soft/mysql-8.0.12-el7-x86_64/data/mysql.sock # Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0 # Settings user and group are ignored when systemd is used.
# If you need to run mysqld under a different user or group,
# customize your systemd unit file for mariadb according to the
# instructions in http://fedoraproject.org/wiki/Systemd [mysqld_safe]
log-error=/data/log/mysql-log/error.log
pid-file=/data/soft/mysql-8.0.12-el7-x86_64/data/mysql.pid #
# include all files from the config directory
#
!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

  【Linux】CentOS 7.4 安装 MySQL 8.0.12 解压版

  初始化数据库后,记录中出现了初始密码,没有初始密码可以去日志中查找,用户名: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

  【Linux】CentOS 7.4 安装 MySQL 8.0.12 解压版

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

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

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

  【Linux】CentOS 7.4 安装 MySQL 8.0.12 解压版

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

  【Linux】CentOS 7.4 安装 MySQL 8.0.12 解压版

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

  【Linux】CentOS 7.4 安装 MySQL 8.0.12 解压版

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

  d、退出数据库

  命令:quit;

  【Linux】CentOS 7.4 安装 MySQL 8.0.12 解压版

  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;

  【Linux】CentOS 7.4 安装 MySQL 8.0.12 解压版

  完成以上步骤即可远程连接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';