官網(wǎng)下載
mysql官網(wǎng)下載鏈接:https://dev./downloads/mysql/
- Select Operating System 中選擇 “Red Hat Enterprise Linux / Oracle Linux”
- Select OS Version 中選擇 “Red Hat Enterprise Linux / Oracle Linux 7(x86, 64-bit)”
- 點(diǎn)擊Download(mysql-8.0.17-1.el7.x86_64.rpm-bundle.tar)
CentOS7環(huán)境下的具體安裝步驟
- 檢測(cè)本地是否有mysql已存在的包:
rpm -qa | grep mysql
- 檢測(cè)本地是否有mariadb已存在的包:
rpm -qa | grep mariadb
如果存在,,則使用yum命令卸載:
rpm -e --nodeps mariadb-libs-5.5.56-2.el7.x86_64
- 創(chuàng)建一個(gè)文件夾,,上傳jar包到/opt/software/mysql:
mkdir /opt/software/mysql
上傳包有xftp等工具
- 解壓mysql jar包:
mkdir /opt/module/mysql
tar -xvf /opt/software/mysql-8.0.16-2.el7.x86_64.rpm-bundle.tar -C /opt/module/mysql
- 查看解壓后的文件:
ll /opt/module/mysql
- 利用rpm包安裝mysql:
如官網(wǎng)所述:
In most cases, you need to install the mysql-community-server, mysql-community-client, mysql-community-libs, mysql-community-common, and mysql-community-libs-compat packages to get a functional, standard MySQL installation. To perform such a standard, basic installation, go to the folder that contains all those packages (and, preferably, no other RPM packages with similar names), and issue the following command:
依次安裝MySQL的組件
rpm -ivh mysql-community-common-8.0.16-2.el7.x86_64.rpm
rpm -ivh mysql-community-libs-8.0.16-2.el7.x86_64.rpm --force --nodeps
- mysql-community-libs-compat
rpm -ivh mysql-community-libs-compat-8.0.16-2.el7.x86_64.rpm
rpm -ivh mysql-community-client-8.0.16-2.el7.x86_64.rpm --force --nodeps
rpm -ivh mysql-community-server-8.0.16-2.el7.x86_64.rpm --force --nodeps
安裝完成后 可以查看已經(jīng)安裝的組件:
rpm -qa | grep mysql
- 啟動(dòng)mysql(初次啟動(dòng)mysqld,,會(huì)自動(dòng)進(jìn)行初始化工作)
systemctl start mysqld
初始化后,,會(huì)產(chǎn)生臨時(shí)密碼,查詢指令如下:
cat /var/log/mysqld.log | grep password
- 登錄MySQL服務(wù):
mysql -uroot -p
輸入產(chǎn)生的臨時(shí)密碼
- 更改密碼
由于MySQL8.0 有密碼驗(yàn)證組件,,若希望設(shè)置簡單的密碼,,需要修改服務(wù)驗(yàn)證條件,可設(shè)置的驗(yàn)證條件如官網(wǎng)所示:
# 密碼檢查等級(jí),,0/LOW,、1/MEDIUM、2/STRONG
set global validate_password.policy=0;
# 密碼的最短長度
set global validate_password.length=6;
# 密碼至少要包含的小寫字母?jìng)€(gè)數(shù)和大寫字母?jìng)€(gè)數(shù)
set global validate_password.mixed_case_count=0;
# 設(shè)置密碼
ALTER USER 'root'@'localhost' IDENTIFIED BY 'your password';
- 修改遠(yuǎn)程登錄權(quán)限
USE mysql;
UPDATE mysql.user SET host = '%' WHERE user = 'root';
flush privileges;
SELECT host, user FROM user;
初始化MySQL發(fā)生錯(cuò)誤的解決方法
使用初始化指令
mysqld --initialize --user=mysql
若發(fā)生錯(cuò)誤,,可能由于 /etc/my.cnf 中datadir指定的文件夾未清除,,本機(jī)中為 /var/lib/mysql,具體的datadir查看本機(jī)配置文件中指定的路徑,。
vim /etc/my.cnf
刪除datadir指定的文件夾
rm -rf /var/lib/mysql
清楚 log-error 指定的日志文件中的內(nèi)容, 本機(jī)中為 /var/log/mysqld.log,,具體的datadir查看本機(jī)配置文件中指定的路徑。 注意,,如果刪除 /var/log/mysqld.log 了該文件,,需要重新創(chuàng)建該文件,并修改文件訪問權(quán)限
rm -f /var/log/mysqld.log
touch /var/log/mysqld.log
chmod 777 /var/log/mysqld.log
最后重新初始化即可,!
忘記數(shù)據(jù)庫root密碼
主要通過無密碼啟動(dòng)的方式啟動(dòng)mysqld服務(wù),,然后進(jìn)入數(shù)據(jù)庫清除原始密碼的加密值,然后再次重啟服務(wù),,進(jìn)入數(shù)據(jù)庫設(shè)置密碼。
- 修改配置文件并重啟服務(wù)
vim /etc/my.cnf
# 在my.cnf中最后一行添加 skip-grant-tables
skip-grant-tables
# 重啟服務(wù)
systemctl restart mysqld.service
- 進(jìn)入數(shù)據(jù)庫清除原始root密碼的加密記錄
# password直接回車
mysql -u root -p
# 清除記錄
UPDATE mysql.user SET authentication_string='' WHERE user='root';
SELECT host, user, authentication_string, plugin FROM mysql.user;
- 修改配置文件,,再次重啟服務(wù),,然后進(jìn)入數(shù)據(jù)庫設(shè)置密碼
vim /etc/my.cnf
刪除 skip-grant-tables
# 重啟服務(wù)
systemctl restart mysqld.service
# password直接回車
mysql -u root -p
# 設(shè)置root密碼 我的host項(xiàng)已經(jīng)修改為%了。如果沒有修改,,則使用:ALTER user 'root'@'localhost' IDENTIFIED BY '123456'
grant system_user on *.* to 'root';
ALTER user 'root'@'%' IDENTIFIED BY '123456';
# WITH mysql_native_password 這個(gè)可以根據(jù)自己需要的認(rèn)證方式修改(caching_sha2_password,、mysql_native_password 兩種)
ALTER user 'mysql.infoschema'@'localhost' IDENTIFIED WITH mysql_native_password BY '123456';
ALTER user 'mysql.session'@'localhost' IDENTIFIED WITH mysql_native_password BY '123456';
ALTER user 'mysql.sys'@'localhost' IDENTIFIED WITH mysql_native_password BY '123456';
# 完成修改,重啟服務(wù),。
systemctl restart mysqld.service
|