1. 下載源包
wget https://dev.mysql.com/get/Downloads/MySQL-8.0.20/mysql-8.0.20-linux-glibc2.12-x86_64.tar.xz
2. 解壓tar包绘雁,移動(dòng)到 /usr/local
tar -xvf mysql-8.0.20-linux-glibc2.12-x86_64.tar.xz
mv mysql-8.0.20-linux-glibc2.12-x86_64 /usr/local/mysql
3. 修改mysql 安裝目錄權(quán)限
chmod -R 755 /usr/local/mysql
4. 創(chuàng)建mysql 數(shù)據(jù)存儲(chǔ)目錄并授權(quán)
mkdir -p /data/mysql
chmod 777 /data/mysql
5.編輯配置文件
vim /etc/my.cnf
配置如下:
[mysqld]
bind-address=0.0.0.0
port=3306
user=mysql
basedir=/usr/local/mysql
datadir=/data/mysql
socket=/tmp/mysql.sock
#socket=/data/mysql/mysql.sock
log-error=/data/mysql/mysql.err
pid-file=/data/mysql/mysql.pid
##character config
character_set_server=utf8mb4
symbolic-links=0
explicit_defaults_for_timestamp=true
interactive_timeout=28800
wait_timeout=28800
max_connect_errors=9999
[mysqld_safe]
log-error=/data/mysql/mariadb.log
pid-file=/data/mysql/mariadb.pid
#
# include all files from the config directory
#
!includedir /etc/my.cnf.d
6.創(chuàng)建用戶 &用戶組
groupadd mysql
useradd -g mysql mysql
7.初始化mysql恨憎,拿到零時(shí)密碼
./bin/mysqld --initialize --user=mysql --datadir=/data/mysql --basedir=/usr/local/mysql
cat /data/mysql/mysql.err
8.注冊(cè)mysql 啟動(dòng)服務(wù)并啟動(dòng)
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql
service mysql start
9.登錄并修改密碼
./bin/mysql -u root -h 127.0.0.1 - P13306 -p testPaww
ALTER USER 'root'@'localhost' IDENTIFIED BY 'testPaww';
FLUSH PRIVILEGES;
9.開(kāi)放遠(yuǎn)程連接
use mysql;
update user set user.Host='%' where user.User='root';
flush privileges;
10. 創(chuàng)建用戶并授權(quán)
CREATE USER 'eagle'@'%' IDENTIFIED BY 'testPaww';
GRANT all ON *.* TO 'eagle'@'%';