【Linux】CentOS 7.4 安裝 MySQL 8.0.12 解壓版

安裝環境/工具

  一、Linux(CentOS 7.4版)html

  二、mysql-8.0.12-el7-x86_64.tar.gzmysql

安裝步驟

  參考:https://dev.mysql.com/doc/refman/8.0/en/installing.htmlsql

  一、下載mysql解壓版(mysql-8.0.12-el7-x86_64.tar.gz),下載地址http://dev.mysql.com/downloads/mysql/數據庫

  

    

    

  二、解壓mysql安裝文件vim

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

  三、複製解壓後的mysql到軟件目錄:服務器

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

  四、添加系統mysql組和mysql用戶:ide

  命令:groupadd mysql工具

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

  五、安裝數據庫

  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]
port=3306 # 設置mysql客戶端鏈接服務端時默認使用的端口

default-character-set=utf8
socket=/data/soft/mysql-8.0.12-el7-x86_64/data/mysql.sock



[mysqld]

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

  

  初始化數據庫後,記錄中出現了初始密碼,沒有初始密碼能夠去日誌中查找,用戶名: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

  七、添加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;

  

  九、查看數據庫user表,注意mysql 5.8密碼字段改成authentication_string。

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

  十、配置遠程登陸

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

  而後刷新權限命令:flush privileges;

  

  完成以上步驟便可遠程鏈接MySQL數據庫了

  十一、新增用戶

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

  十二、給用戶受權

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

  1三、若是是用navicat鏈接,因爲mysql8的加密方式不一樣,須要使用navicat的加密方式,修改密碼

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

相關文章
相關標籤/搜索