卸載
- 卸載之前請(qǐng)確保數(shù)據(jù)都備份好了阿!
查看是否安裝mysql
rpm -qa | grep -i mysql

image.png
挨個(gè)卸載: rpm -e –nodeps 包名
rpm -e –nodeps mysql-community-libs-8.0.16-2.el7.x86_64
查找之前老版本mysql的目錄、并且刪除老版本mysql的文件和庫(kù)
find / -name mysql

挨個(gè)刪除
rm -rf /var/lib/mysql
rm -rf /usr/lib64/mysql
...
- 注意:卸載后/etc/my.cnf不會(huì)刪除,需要進(jìn)行手工刪除
rm -rf /etc/my.cnf
檢查一遍
rpm -qa | grep -i mysql
find / -name mysql
安裝(8.0)
添加MySQL Yum存儲(chǔ)庫(kù)
進(jìn)入Yum Repository下載頁(yè)面選擇我們需要的版本,點(diǎn)擊Download進(jìn)入下載頁(yè)面。
一般選這個(gè)

image.png
進(jìn)入下載頁(yè)面可以拿到下載地址

image.png
下載到機(jī)器上
wget https://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm
安裝存儲(chǔ)庫(kù)
yum localinstall mysql80-community-release-el7-3.noarch.rpm
安裝mysql
通過以下命令安裝mysql
yum install mysql-community-server
啟動(dòng)MySQL服務(wù)器
使用以下命令啟動(dòng)MySQL服務(wù)器:
service mysqld start
使用以下命令檢查MySQL服務(wù)器的狀態(tài):
service mysqld status
修改mysql配置文件
vim /etc/my.cnf
給出一個(gè)簡(jiǎn)單的作參考
# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/8.0/en/server-configuration-defaults.html#
[mysqld]
#
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
#
# Remove the leading "# " to disable binary logging
# Binary logging captures changes between backups and is enabled by
# default. It's default setting is log_bin=binlog
# disable_log_bin
#
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M
#
# Remove leading # to revert to previous value for default_authentication_plugin,
# this will increase compatibility with older clients. For background, see:
# https://dev.mysql.com/doc/refman/8.0/en/server-system-variables.html#sysvar_default_authentication_plugin
# default-authentication-plugin=mysql_native_password
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
# 允許最大連接數(shù)
max_connections=20
# 服務(wù)端使用的字符集默認(rèn)為8比特編碼的latin1字符集
character-set-server=utf8mb4
# 創(chuàng)建新表時(shí)將使用的默認(rèn)存儲(chǔ)引擎
default-storage-engine=INNODB
# 設(shè)置協(xié)議認(rèn)證方式(重點(diǎn)啊)
default_authentication_plugin=mysql_native_password
# 默認(rèn)時(shí)區(qū)
default-time_zone = '+8:00'
# 去掉group限制
sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION
# 密碼驗(yàn)證強(qiáng)度
# 默認(rèn)為:MEDIUM
# 要求至少包含1個(gè)數(shù)字字符,1個(gè)小寫字符,1個(gè)大寫字符和1個(gè)特殊(非字母數(shù)字)字符
# 非測(cè)試環(huán)境請(qǐng)勿添加此項(xiàng)
validate_password.policy=LOW
# 密碼驗(yàn)證長(zhǎng)度,默認(rèn):8
# 非測(cè)試環(huán)境請(qǐng)勿添加此項(xiàng)
validate_password.length=6
[mysql]
# 設(shè)置mysql客戶端默認(rèn)字符集
default-character-set=utf8mb4
重啟mysql
systemctl restart mysqld
修改密碼
查看默認(rèn)密碼
grep 'temporary password' /var/log/mysqld.log

如果有多行,以最下面一條為準(zhǔn)。
登錄mysql
mysql -uroot -p
然后輸入上面看到的臨時(shí)密碼,小技巧可以使用在中文輸入法下輸入,密碼會(huì)在輸入法的框框中看得到
需要遠(yuǎn)程登錄
# 切換數(shù)據(jù)庫(kù)
use mysql;
# 查看用戶信息
select host, user from user;
# 修改root用戶訪問限制
update user set host='%' where user='root';
# 刷新權(quán)限
FLUSH PRIVILEGES;
# 查看用戶信息
select host, user from user;

image.png
- 注意: 默認(rèn)情況下root用戶對(duì)應(yīng)的host是localhost,圖中是因?yàn)槲乙呀?jīng)修改過了。
修改密碼
ALTER USER 'root'@'%' IDENTIFIED BY '123456'
FLUSH PRIVILEGES;
不需要遠(yuǎn)程登錄
修改密碼
ALTER USER 'root'@'localhost' IDENTIFIED BY '123456'
FLUSH PRIVILEGES;