佳木斯湛栽影视文化发展公司

主頁 > 知識(shí)庫 > Redhat7.3安裝MySQL8.0.22的詳細(xì)教程(二進(jìn)制安裝)

Redhat7.3安裝MySQL8.0.22的詳細(xì)教程(二進(jìn)制安裝)

熱門標(biāo)簽:地方門戶網(wǎng)站 Linux服務(wù)器 AI電銷 呼叫中心市場需求 百度競價(jià)排名 鐵路電話系統(tǒng) 網(wǎng)站排名優(yōu)化 服務(wù)外包

一、MySQL安裝包下載

官網(wǎng)地址:https://dev.mysql.com/downloads/mysql/

下載步驟:

過濾操作系統(tǒng)版本

選擇歸檔安裝包

下載后,上傳并md5校驗(yàn)安裝包是否與上圖官方提供的值一致,確保傳輸過程安裝包無損害

[root@MyDB1 ~]# cd /usr/local/software/
[root@MyDB1 software]# md5sum mysql-8.0.22-el7-x86_64.tar.gz 
52e312605f66aaaa0efcd272b9fc0a1f mysql-8.0.22-el7-x86_64.tar.gz

解壓安裝包

[root@MyDB1 software]# tar -zxvf mysql-8.0.22-el7-x86_64.tar.gz
[root@MyDB1 software]# ln -s mysql-8.0.22-el7-x86_64/ mysql			#創(chuàng)建鏈接,方便操作

二、MySQL卸載說明

  • 只有rpm安裝方式是需要卸載舊版本的mysql,二進(jìn)制安裝和編譯安裝不需要,但是要注意端口沖突
  • rpm若不卸載舊版本,在安裝時(shí),它會(huì)提示你mysql已安裝,此時(shí)是無法再次安裝的,只有通過yum更新版本
  • 為了保證后續(xù)操作不會(huì)產(chǎn)生其他沖突,我們卸載原有的mysql

注:在卸載舊的MySQL之前,注意備份數(shù)據(jù)

[root@MyDB1 ~]# rpm -qa|grep mysql								#查看是否已安裝mysql數(shù)據(jù)庫
[root@MyDB1 ~]# rpm -qa|grep mysql|xargs rpm -e --nodeps					#卸載mysql	
[root@MyDB1 software]# rpm -qa|grep mariadb-libs|xargs rpm -e --nodeps		#卸載mariadb

三、創(chuàng)建用戶和組

新建組和用戶

[root@MyDB1 ~]# groupadd -g 2000 mysql
[root@MyDB1 ~]# useradd -u 2000 -g mysql -c "MySQL Server" -s /sbin/nologin mysql
[root@MyDB1 ~]# cat /etc/group|grep mysql
mysql:x:2000:
[root@MyDB1 ~]# cat /etc/passwd|grep mysql
mysql:x:2000:2000:Mysql software:/home/mysql:/sbin/nologin

注:若組和用戶已存在,則刪除系統(tǒng)默認(rèn)組和用戶,再次創(chuàng)建!

刪除組和用戶

[root@MyDB1 ~]# userdel mysql					#刪除用戶同時(shí)會(huì)刪除相應(yīng)的組

賦權(quán)給mysql路徑

[root@MyDB1 ~]# cd /usr/local/software/
[root@MyDB1 software]# chown -R mysql:mysql mysql*

初始化之前的目錄結(jié)構(gòu)

注:此時(shí)是沒有data目錄

四、MySQL初始化

初始化之前先編輯好配置文件

[root@MyDB1 ~]# vi /etc/my.cnf
[root@MyDB1 ~]# cat /etc/my.cnf


內(nèi)容如下:(其他的根據(jù)實(shí)際需求配置)
[mysqld]
basedir = /usr/local/software/mysql
datadir = /usr/local/software/mysql/data
log_error = /usr/local/software/mysql/mysql-error.log
port = 3306
socket = /usr/local/software/mysql/mysqld.sock
pid_file = /usr/local/software/mysql/mysqld.pid

character-set-server=utf8
lower_case_table_names=1
max_connections=1000
sql_mode='STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION'

[mysql]
default-character-set=utf8

[client]
default-character-set=utf8

初始化開始

[root@MyDB1 ~]# /usr/local/software/mysql/bin/mysqld --initialize --user=mysql --basedir=/usr/local/software/mysql --datadir=/usr/local/software/mysql/data

初始化過程,輸出日志文件中有root用戶的臨時(shí)密碼

初始化之后的目錄結(jié)構(gòu)

五、MySQL啟動(dòng)服務(wù)

方式1——init.d: 啟動(dòng)服務(wù)

[root@MyDB1 ~]# cp /usr/local/software/mysql/support-files/mysql.server /etc/init.d/mysqld
[root@MyDB1 ~]# /etc/init.d/mysqld start

驗(yàn)證服務(wù)

[root@MyDB1 ~]# ps -ef|grep mysql

解釋說明

圖中有兩個(gè)進(jìn)程,一個(gè)主進(jìn)程,一個(gè)守護(hù)進(jìn)程。當(dāng)mysql意外停止時(shí),守護(hù)進(jìn)程會(huì)自動(dòng)重啟mysql服務(wù)

演示demo

[root@MyDB1 ~]# kill -9 75341						#直接殺死進(jìn)程

方式2——systemctl: 編輯啟動(dòng)配置文件

[root@MyDB1 subsys]# vi /etc/systemd/system/mysqld.service


內(nèi)容如下:(缺點(diǎn):當(dāng)kill掉時(shí),無法自動(dòng)啟動(dòng)恢復(fù))
[Unit]
Description=MySQL Server
Documentation=man:mysqld(8)
Documentation=http://dev.mysql.com/doc/refman/en/using-systemd.html
Documentation=https://www.freedesktop.org/software/systemd/man/systemd.unit.html
After=network.target
After=syslog.target
[Install]
WantedBy=multi-user.target
[Service]
User=mysql
Group=mysql
LimitNOFILE = 5000
ExecStart=/usr/local/software/mysql/bin/mysqld --defaults-file=/etc/my.cnf

啟動(dòng)服務(wù)

[root@MyDB1 ~]# systemctl start mysqld.service
[root@MyDB1 ~]# systemctl status mysqld.service

六、安全效率優(yōu)化

啟動(dòng)權(quán)限限制

[root@MyDB1 ~]# cd /usr/local/software/mysql/bin/
[root@MyDB1 bin]# chmod 700 mysqld mysqld_safe 
[root@MyDB1 bin]# ll mysqld mysqld_safe 
-rwx------. 1 mysql mysql 441010738 Sep 24 03:42 mysqld
-rwx------. 1 mysql mysql  29157 Sep 24 03:18 mysqld_safe

注:現(xiàn)在只要root用戶才能夠啟動(dòng)停止MySQL服務(wù)!

服務(wù)隨系統(tǒng)啟動(dòng)

systemctl enable mysqld.service
systemctl list-unit-files|grep mysql

七、配置環(huán)境變量

[root@MyDB1 ~]# vi /etc/profile

追加內(nèi)容如下:
MYSQL_HOME=/usr/local/software/mysql
export PATH=.:$PATH:$MYSQL_HOME/bin

[root@MyDB1 ~]# source /etc/profile						#重新加載,生效!

八、修改root初始密碼

創(chuàng)建socket鏈接

[root@MyDB1 ~]# ln -s /usr/local/software/mysql/mysqld.sock /tmp/mysql.sock

使用臨時(shí)密碼登錄

[root@MyDB1 ~]# mysql -uroot -p
Enter password: 
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 10
Server version: 8.0.22

Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> 

注:當(dāng)臨時(shí)密碼含有特使符號(hào)時(shí),可能命令行輸入會(huì)產(chǎn)生歧義。此時(shí),交互時(shí)輸入密碼即可!

修改root密碼

mysql> alter user root@'localhost' identified by 'MyDB12@com';
Query OK, 0 rows affected (0.00 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

注:MySQL8密碼必須符合一定復(fù)雜度,否則無法修改;退出當(dāng)前會(huì)話后,重啟登錄生效!

九、配置mysql遠(yuǎn)程登錄

  • 關(guān)閉防火墻或開放MySQL端口
  • 查看允許訪問MySQL的用戶和地址
mysql> select user,host from mysql.user;
+------------------+-----------+
| user    | host  |
+------------------+-----------+
| mysql.infoschema | localhost |
| mysql.session | localhost |
| mysql.sys  | localhost |
| root    | localhost |
+------------------+-----------+
4 rows in set (0.00 sec)

遇到的問題

mysql> grant all privileges on *.* to root@'%' identified by 'MyDB12@com';
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use
 near 'identified by 'MyDB12@com'' at line 1

注:該錯(cuò)誤并不是語法錯(cuò)誤,是因?yàn)閙ysql該版本不支持直接創(chuàng)建用戶和賦權(quán),而需要分別實(shí)現(xiàn)

創(chuàng)建遠(yuǎn)程登錄用戶

mysql> create user 'root'@'%' identified by 'MyDB12@com';
Query OK, 0 rows affected (0.01 sec)

賦權(quán)

mysql> grant all privileges on *.* to 'root'@'%';
Query OK, 0 rows affected (0.01 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)

到此這篇關(guān)于Redhat7.3安裝MySQL8.0.22(二進(jìn)制安裝)的文章就介紹到這了,更多相關(guān)Redhat7.3安裝MySQL8.0.22內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

您可能感興趣的文章:
  • Mysql8.0.22解壓版安裝教程(小白專用)
  • 超詳細(xì)MySQL8.0.22安裝及配置教程
  • 阿里云centos7安裝mysql8.0.22的詳細(xì)教程

標(biāo)簽:黃山 仙桃 崇左 湖南 蘭州 衡水 銅川 湘潭

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《Redhat7.3安裝MySQL8.0.22的詳細(xì)教程(二進(jìn)制安裝)》,本文關(guān)鍵詞  ;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無關(guān)。
  • 相關(guān)文章
  • 收縮
    • 微信客服
    • 微信二維碼
    • 電話咨詢

    • 400-1100-266
    华阴市| 黄浦区| 麻城市| 错那县| 晴隆县| 黄石市| 楚雄市| 郁南县| 虎林市| 阳泉市| 南郑县| 诸暨市| 武胜县| 阜平县| 略阳县| 崇明县| 鹤庆县| 曲周县| 永川市| 萨迦县| 永清县| 江永县| 博客| 葵青区| 浮山县| 龙江县| 荆门市| 鹰潭市| 新余市| 西乌珠穆沁旗| 上饶市| 南岸区| 中江县| 宜君县| 淄博市| 响水县| 繁峙县| 平阳县| 固始县| 麦盖提县| 奈曼旗|