1. 程式人生 > 其它 >Centos7安裝mysql8

Centos7安裝mysql8

mysql8設定遠端訪問
安裝mysql
# 從國內映象下載mysql8
wget https://mirrors.tuna.tsinghua.edu.cn/mysql/yum/mysql80-community-el7/mysql80-community-release-el7-3.noarch.rpm

# 安裝
yum install mysql80-community-release-el7-3.noarch.rpm

# 下載完成後,yum安裝
yum install mysql-server

# 檢視是否開機啟動
systemctl list-unit-files|grep mysql
#mysqld.service                                enabled 	開機啟動
#[email protected]                               disabled

# 如果不是開機啟動,設定開機啟動
systemctl enable mysqld.service
#啟動mysql
systemctl start mysqld.service

# 初始化mysql
mysqld --initialize

# 檢視初始化root密碼
grep 'temporary password' /var/log/mysqld.log
#[root@localhost hao]# grep 'temporary password' /var/log/mysqld.log 
#2021-09-06T09:14:23.235555Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: 8JmeNwgQd-DZ

# 登入
mysql -u root -p
# 出現下面提示後輸入上面密碼:8JmeNwgQd-DZ
Enter password:
配置mysql
# 修改初始化密碼
alter user 'root'@'localhost' identified by '這裡輸入新密碼';

# 如果搭建測試環境,可以修改密碼策略,設定簡易密碼
# 檢視密碼策略
show variables like 'validate_password%';

# 設定密碼複雜度為低
set global validate_password.policy=0;

#設定密碼長度
set global validate_password.length=1;

# 建立新使用者,這裡如果執行create user 'user01'@'localhost' identified by '123456'; 只允許本地訪問
create user 'user01'@'%' identified by '123456';

# 使用者授權
grant all on *.* to 'user01'@'%';

現在可以用使用者user01遠端連線資料庫,遠端連線一定要設定serverTimeZone=Asia/Shanghai