1. 程式人生 > >centos環境下安裝mysql-8.0.12

centos環境下安裝mysql-8.0.12

安裝包請自行在官網下載

https://dev.mysql.com/downloads/mysql/

 

 

一:安裝相關依賴包

yum  -y  install  gcc  gcc-c++  ncurses-devel  perl

 

二:環境配置

新增系統mysql組和mysql使用者:

groupadd mysql

useradd -r -g mysql -s /bin/false mysql

 

將mysql命令加進環境變數

開啟profile

vim /etc/profile

PATH=/tools/mysql-8.0.12-el7-x86_64/bin:$PATH
export PATH

讀取profile配置

source /etc/profile

 

三:安裝mysql

解壓安裝包

mysql目錄結構

  

 

目錄 目錄的內容
bin mysqld伺服器,客戶端和實用程式
docs 資訊格式的MySQL手冊
man Unix手冊頁
include 包含(標題)檔案
lib 圖書館
share 用於資料庫安裝的錯誤訊息,字典和SQL
support-files 其他支援檔案

 

修改當前目錄擁有者為mysql使用者:

chown -R mysql:mysql ./

 

配置mysql配置檔案

vim  /etc/my.cnf

[client]
port=3306 # 設定mysql客戶端連線服務端時預設使用的埠

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

 

[mysqld]

basedir=/tools/mysql-8.0.12-el7-x86_64 # 設定mysql的安裝目錄
datadir=/tools/mysql-8.0.12-el7-x86_64/data

socket=/tools/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

 

初始化資料目錄,包括mysql包含初始MySQL授權表的 資料庫,該表確定如何允許使用者連線到伺服器     

bin/mysqld

--initialize  -insecure  --user=mysql    (不設定密碼)

 

複製啟動指令碼

cp support-files/mysql.server /etc/init.d/mysql

啟動資料庫

 /etc/init.d/mysql  start

 

修改root密碼

進入mysql

mysql  -u  root   -p

 

ALTER USER 'root'@'localhost' IDENTIFIED BY 'passowrd' ;

ALTER USER 'root'@'%' IDENTIFIED BY 'passowrd' ;

flush privileges;

 

MySQL8.0的使用者授權和之前有所區別,老版本的常用授權語句在8.0中會報錯:

MySQL8.0之前版本:

GRANT ALL ON *.* TO `wangwei`@`127.0.0.1` IDENTIFIED BY 'passowrd' WITH GRANT OPTION;

MySQL8.0版本:

CREATE USER `wangwei`@`127.0.0.1` IDENTIFIED BY 'passowrd';

GRANT ALL ON *.* TO `wangwei`@`127.0.0.1` WITH GRANT OPTION;