轉(zhuǎn)自:http://www.reibang.com/p/85bc42af03e7
- CentOS8.x已安裝MySQL8.0.17
- 系統(tǒng)為:CentOS8.0.1905
- 最終安裝MySQL版本:5.7.29
一尊残、卸載MySQL8
1缓待、查看版本
mysql --version
2野舶、查看安裝的包
rpm -qa | grep mysql
3、卸載已安裝MySQL8
rpm -qa | grep mysql | xargs rpm -e --nodeps
刪除MySQL配置文件及其目錄
rm -rf /etc/my.cnf /etc/my.cnf.d
二、離線安裝指定版本的MySQL
1纤勒、安裝必要的包
yum install libncurses*
2、官網(wǎng)下載tar包
官網(wǎng)地址:https://dev.mysql.com/downloads/mysql/
(Looking for the latest GA version?)
Select Version: 5.7.29
Select Operating System: Source Code
Select OS Version: Generic Linux(Architecture Independent)
或者使用以下命令下載
cd /usr/local/src
wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.29-el7-x86_64.tar.gz
將離線下載的tar上傳至/usr/local/src
目錄下
3、創(chuàng)建安裝賬戶
mkdir /usr/local/mysql
useradd -s /bin/false -d /usr/local/mysql mysql
4诅愚、安裝過程
# 此過程有點(diǎn)長,耐心等待
tar -xvzf mysql-5.7.21-el7-x86_64.tar.gz -C /usr/local/mysql/
cd /usr/local/mysql/mysql-5.7.21-el7-x86_64/
mv * ../
cd ..
rmdir mysql-5.7.21-el7-x86_64/
mkdir data
chown -R mysql.mysql ../mysql
cd bin
./mysqld --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --initialize
安裝完成后在最后會(huì)顯示root密碼
拷貝可執(zhí)行配置文件
cd /usr/local/mysql
cp ../support-files/mysql.server /etc/init.d/mysqld
5劫映、配置過程
MySQL配置文件/etc/my.cnf
中內(nèi)容如下:
[mysqld]
port = 3306
basedir = /usr/local/mysql
datadir=/usr/local/mysql/data
socket=/tmp/mysql.sock
pid-file=/usr/local/mysql/data/mysql.pid
log-error=/usr/local/mysql/data/error.log
character_set_server=utf8
user=mysql
max_connections=1500
symbolic-links=0
# 東八區(qū)時(shí)區(qū)违孝,北京時(shí)區(qū)
default-time-zone = '+8:00'
sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
# 導(dǎo)入包允許的大小設(shè)置
max_allowed_packet=1024M
# 忽略表名大小寫;1表示忽略大小寫,0表示解析大小寫
lower_case_table_names=1
!includedir /etc/my.cnf.d
6、啟動(dòng)服務(wù)并登陸
常用命令
# 啟動(dòng)命令
service mysqld start 或者 /etc/init.d/mysqld start
# 停止命令
service mysqld stop 或者 /etc/init.d/mysqld stop
# 重啟命令
service mysqld restart 或者 /etc/init.d/mysqld restart
登陸命令
./bin/mysql -u root -p'zisTBE)I8*/0'
7泳赋、修改密碼并允許遠(yuǎn)程連接
mysql> set password=password('123456');
mysql> use mysql;
mysql> update user set host='%' where user='root';
mysql> flush privileges;
如果遠(yuǎn)程還連接不上雌桑,看下是否防火墻開啟了?
8祖今、添加環(huán)境變量
vim /etc/profile
# mysql
PATH=/usr/local/mysql/bin:$PATH
保存退出后校坑,使用
source /etc/profile
使其生效。
三千诬、MySQL自啟
# 查看MySQL是否自啟
systemctl is-enabled mysqld
如下圖耍目,顯示disabled
,MySQL默認(rèn)非自啟
# 開啟自啟
systemctl enable mysqld
如下圖
四徐绑、防火墻放行3306端口
如果你的防火墻已經(jīng)關(guān)閉邪驮,可忽略此操作。
# 永久開放3306端口
firewall-cmd --permanent --zone=public --add-port=3306/tcp
# 重啟防火墻
systemctl restart firewalld
# 檢測設(shè)定是否生效
iptables -nL | grep 3306
五傲茄、其他問題
問題1:yum倉庫無法更新問題
在使用yum repolist
列出倉庫中的包時(shí)毅访,出現(xiàn)Error: Failed to synchronize cache for repo 'AppStream'
由于其原有的默認(rèn)的源配置文件被我刪除過沮榜,然后CentOS8換過阿里的源,在卸載MySQL8之后重新安裝后出現(xiàn)上述問題喻粹;解決參照:CentOS8使用阿里源蟆融。
將原來文件中
$releasever
替換為8.0.1905
,將$basearch
替換為x86_64
磷斧,然后再使用yum clean all && yum makecache
即可
正常的CentOS-Base.repo
內(nèi)容如下
# CentOS-Base.repo
#
# The mirror system uses the connecting IP address of the client and the
# update status of each mirror to pick mirrors that are updated to and
# geographically close to the client. You should use this for CentOS updates
# unless you are manually picking other mirrors.
#
# If the mirrorlist= does not work for you, as a fall back you can try the
# remarked out baseurl= line instead.
#
#
[base]
name=CentOS-8.0.1905 - Base - mirrors.aliyun.com
failovermethod=priority
baseurl=https://mirrors.aliyun.com/centos/8.0.1905/BaseOS/x86_64/os/
http://mirrors.aliyuncs.com/centos/8.0.1905/BaseOS/x86_64/os/
http://mirrors.cloud.aliyuncs.com/centos/8.0.1905/BaseOS/x86_64/os/
gpgcheck=1
gpgkey=https://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-Official
#additional packages that may be useful
[extras]
name=CentOS-8.0.1905 - Extras - mirrors.aliyun.com
failovermethod=priority
baseurl=https://mirrors.aliyun.com/centos/8.0.1905/extras/x86_64/os/
http://mirrors.aliyuncs.com/centos/8.0.1905/extras/x86_64/os/
http://mirrors.cloud.aliyuncs.com/centos/8.0.1905/extras/x86_64/os/
gpgcheck=1
gpgkey=https://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-Official
#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-8.0.1905 - Plus - mirrors.aliyun.com
failovermethod=priority
baseurl=https://mirrors.aliyun.com/centos/8.0.1905/centosplus/x86_64/os/
http://mirrors.aliyuncs.com/centos/8.0.1905/centosplus/x86_64/os/
http://mirrors.cloud.aliyuncs.com/centos/8.0.1905/centosplus/x86_64/os/
gpgcheck=1
enabled=0
gpgkey=https://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-Official
[PowerTools]
name=CentOS-8.0.1905 - PowerTools - mirrors.aliyun.com
failovermethod=priority
baseurl=https://mirrors.aliyun.com/centos/8.0.1905/PowerTools/x86_64/os/
http://mirrors.aliyuncs.com/centos/8.0.1905/PowerTools/x86_64/os/
http://mirrors.cloud.aliyuncs.com/centos/8.0.1905/PowerTools/x86_64/os/
gpgcheck=1
enabled=0
gpgkey=https://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-Official
[AppStream]
name=CentOS-8.0.1905 - AppStream - mirrors.aliyun.com
failovermethod=priority
baseurl=https://mirrors.aliyun.com/centos/8.0.1905/AppStream/x86_64/os/
http://mirrors.aliyuncs.com/centos/8.0.1905/AppStream/x86_64/os/
http://mirrors.cloud.aliyuncs.com/centos/8.0.1905/AppStream/x86_64/os/
gpgcheck=1
gpgkey=https://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-Official
作者:靜美書齋
鏈接:http://www.reibang.com/p/ee018b20a6e6
來源:簡書
著作權(quán)歸作者所有振愿。商業(yè)轉(zhuǎn)載請(qǐng)聯(lián)系作者獲得授權(quán),非商業(yè)轉(zhuǎn)載請(qǐng)注明出處弛饭。
本人遇到的問題:
tar -zxvf mysql-5.7.32-linux-glibc2.12-x86_64.tar.gz -C /usr/local/
ln -s mysql-5.7.32-linux-glibc2.12-x86_64/ mysql
./bin/mysqld --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --initialize
錯(cuò)誤:
error while loading shared libraries: libncurses.so.5: cannot open shared object file: No such file or directory
解決辦法:
ln -s /usr/lib64/libncurses.so.6.1 /usr/lib64/libncurses.so.5
錯(cuò)誤:
error while loading shared libraries: libtinfo.so.5: cannot open shared object file: No such file or directory
解決辦法:
ln -s /usr/lib64/libtinfo.so.6.1 /usr/lib64/libtinfo.so.5
alter user 'root'@'localhost' identified by 'bpm,.123';