卸載
- 卸載之前請確保數(shù)據(jù)都備份好了阿括细!
查看是否安裝mysql
rpm -qa | grep -i mysql
挨個卸載: rpm -e –nodeps 包名
rpm -e –nodeps mysql-community-libs-8.0.16-2.el7.x86_64
查找之前老版本mysql的目錄脯爪、并且刪除老版本mysql的文件和庫
find / -name mysql
挨個刪除
rm -rf /var/lib/mysql
rm -rf /usr/lib64/mysql
...
- 注意:卸載后/etc/my.cnf不會刪除霍骄,需要進行手工刪除
rm -rf /etc/my.cnf
檢查一遍
rpm -qa | grep -i mysql
find / -name mysql
安裝(8.0)
添加MySQL Yum存儲庫
進入Yum Repository下載頁面選擇我們需要的版本豪椿,點擊Download
進入下載頁面篮昧。
一般選這個
進入下載頁面可以拿到下載地址
下載到機器上
wget https://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm
安裝存儲庫
yum localinstall mysql80-community-release-el7-3.noarch.rpm
安裝mysql
通過以下命令安裝mysql
yum install mysql-community-server
啟動MySQL服務(wù)器
使用以下命令啟動MySQL服務(wù)器:
service mysqld start
使用以下命令檢查MySQL服務(wù)器的狀態(tài):
service mysqld status
修改mysql配置文件
vim /etc/my.cnf
給出一個簡單的作參考
# 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)建新表時將使用的默認(rèn)存儲引擎
default-storage-engine=INNODB
# 設(shè)置協(xié)議認(rèn)證方式(重點啊)
default_authentication_plugin=mysql_native_password
# 默認(rèn)時區(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
# 密碼驗證強度
# 默認(rèn)為:MEDIUM
# 要求至少包含1個數(shù)字字符壳坪,1個小寫字符暇昂,1個大寫字符和1個特殊(非字母數(shù)字)字符
# 非測試環(huán)境請勿添加此項
validate_password.policy=LOW
# 密碼驗證長度莺戒,默認(rèn):8
# 非測試環(huán)境請勿添加此項
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ù)據(jù)庫
use mysql;
# 查看用戶信息
select host, user from user;
# 修改root用戶訪問限制
update user set host='%' where user='root';
# 刷新權(quán)限
FLUSH PRIVILEGES;
# 查看用戶信息
select host, user from user;
- 注意: 默認(rèn)情況下root用戶對應(yīng)的host是localhost澄暮,圖中是因為我已經(jīng)修改過了名段。
修改密碼
ALTER USER 'root'@'%' IDENTIFIED BY '123456'
FLUSH PRIVILEGES;
不需要遠程登錄
修改密碼
ALTER USER 'root'@'localhost' IDENTIFIED BY '123456'
FLUSH PRIVILEGES;