CentOS7離線安裝MySQL

服務(wù)器環(huán)境:

CentOS-7.4-x86_64-DVD-1708

MySQL版本:

mysql-5.7.27-linux-glibc2.12-x86_64.tar.gz

1谦铃,首先卸載Centos7自帶的Mariadb

# 查看系統(tǒng)自帶的Mariadb
[root@CDH-141 ~]# rpm -qa|grep mariadb
mariadb-libs-5.5.44-2.el7.centos.x86_64
# 卸載系統(tǒng)自帶的Mariadb(此時(shí)要根據(jù)實(shí)際情況去卸載)
[root@CDH-141 ~]# rpm -e --nodeps mariadb-libs-5.5.56-2.el7.x86_64

2须眷,檢查Msyql是否存在

# 檢查mysql是否存在
[root@CDH-141 ~]# rpm -qa | grep mysql
[root@CDH-141 ~]# 

3,查看用戶和組是否存在

(1),先檢查是否存在,如果不存在則創(chuàng)建

# 檢查mysql組和用戶是否存在士嚎,如無則創(chuàng)建
[root@CDH-141 ~]# cat /etc/group | grep mysql
[root@CDH-141 ~]# cat /etc/passwd | grep mysql 
# 創(chuàng)建mysql用戶組
[root@CDH-141 ~]# groupadd mysql
# 創(chuàng)建一個(gè)用戶名為mysql的用戶米奸,并加入mysql用戶組
[root@CDH-141 ~]# useradd -g mysql mysql
# 制定password 為111111
[root@CDH-141 ~]# passwd mysql
Changing password for user mysql.
New password:
BAD PASSWORD: The password is a palindrome
Retype new password:
passwd: all authentication tokens updated successfully.

4,下載mysql離線安裝包tar文件

官網(wǎng)下載地址:https://dev.mysql.com/downloads/mysql/5.7.html#downloads

版本選擇灌旧,可以選擇一下兩種方式:

1)使用Red Hat Enterprise Linux
Select Version:5.7.25
Select Operating System:Red Hat Enterprise Linux / Oracle Linux
Select OS Version:Red Hat Enterprise Linux 7 / Oracle Linux 7 (x86, 64-bit)
列表中下載:
Compressed TAR Archive:(mysql-5.7.25-el7-x86_64.tar.gz)

2)使用Linux - Generic
Select Version:5.7.25
Select Operating System:Linux - Generic
Select OS Version:Linux - Generic (glibc 2.12) (x86, 64-bit)
列表中下載:
Compressed TAR Archive:(mysql-5.7.25-linux-glibc2.12-x86_64.tar.gz)【本文中使用的是這個(gè)版本】
注意:上邊兩種方式找mysql離線安裝包的方式都可以绑咱。

5,上傳第四步下載的mysql TAR包

# 上傳mysql TAR包
# 或者直接使用XFTP進(jìn)行安裝
[root@CDH-141 ~]# rz
# 解壓mysql-5.7.25-linux-glibc2.12-x86_64.tar.gz

[root@CDH-141 local]# ls
bin  full-path-to-mysql-VERSION-OS  include  lib64    mysql-5.7.25-linux-glibc2.12-x86_64.tar.gz  share
etc  games                          lib      libexec  sbin                                 src
[root@CDH-141 local]#  tar -zxvf mysql-5.7.27-linux-glibc2.12-x86_64.tar.gz -C /usr/local/
mysql-5.7.25-lin
...
mysql-5.7.25-linux-glibc2.12-x86_64/share/install_rewriter.sql
mysql-5.7.25-linux-glibc2.12-x86_64/share/uninstall_rewriter.sql
mysql-5.7.25-linux-glibc2.12-x86_64/support-files/magic
mysql-5.7.25-linux-glibc2.12-x86_64/support-files/mysql.server
mysql-5.7.25-linux-glibc2.12-x86_64/docs/INFO_BIN
mysql-5.7.25-linux-glibc2.12-x86_64/docs/INFO_SRC
[root@localhost ~]# cd /usr/local/
[root@CDH-141 local]# ls
bin  full-path-to-mysql-VERSION-OS  include  lib64    mysql-5.7.25-linux-glibc2.12-x86_64.tar.gz  share
etc  games                          lib      libexec  mysql-5.7.25-linux-glibc2.12-x86_64  sbin                                        src
# 進(jìn)入/usr/local下枢泰,修改為mysql
[root@CDH-141 local]# mv mysql-5.7.27-linux-glibc2.12-x86_64/ mysql
[root@CDH-141 local]# ls
bin  etc  full-path-to-mysql-VERSION-OS  games  include  lib  lib64  libexec  mysql  mysql-5.7.25-linux-glibc2.12-x86_64.tar.gz  sbin  share  src

6描融,更改所屬的組和用戶

# 更改所屬的組和用戶
[root@CDH-141 ~]# cd /usr/local/
[root@CDH-141 local]# chown -R mysql mysql/
[root@CDH-141 local]# chgrp -R mysql mysql/
[root@CDH-141 local]# cd mysql/
[root@CDH-141 mysql]# mkdir data
[root@CDH-141 mysql]# chown -R mysql:mysql data

7,在/etc下創(chuàng)建my.cnf文件

# 編輯/etc/my.cnf
[root@CDH-141 mysql]# vi /etc/my.cnf
[mysql]
socket=/tmp/mysql.sock
# set mysql client default chararter
#default-character-set=utf8

[mysqld]
socket=/tmp/mysql.sock
# set mysql server port  
port = 3306 # 默認(rèn)是3306衡蚂,如果這里發(fā)現(xiàn)3306已經(jīng)被占用窿克,可以更改
# set mysql install base dir
basedir=/usr/local/mysql
# set the data store dir
datadir=/usr/local/mysql/data
# set the number of allow max connnection
max_connections=1024
# set server charactre default encoding
character-set-server=utf8
# the storage engine
default-storage-engine=INNODB
# 設(shè)置MySQL對(duì)表名等不區(qū)分大小寫
lower_case_table_names=1
max_allowed_packet=200M
explicit_defaults_for_timestamp=true
#阻止過多嘗試失敗的客戶端以防止暴力破解密碼的情況,與性能并無太大的關(guān)系
max_connect_errors=30
#此參數(shù)確定數(shù)據(jù)日志文件的大小,以M為單位毛甲,根據(jù)數(shù)據(jù)更新頻率調(diào)整年叮。
innodb_log_file_size=50
#指定大小的內(nèi)存來緩沖數(shù)據(jù)和索引,最大可以把該值設(shè)置成物理內(nèi)存的80%
innodb_buffer_pool_size=10G
key_buffer_size=16M
sql_mode=STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
# 配置GROUP_CONCAT拼接的字符串的長(zhǎng)度字節(jié)
group_concat_max_len = 102400


[mysql.server]
user=mysql
basedir=/usr/local/mysql

# 可以防止出現(xiàn)插入中文報(bào)錯(cuò);如果此時(shí)不生效玻募,可以強(qiáng)制在創(chuàng)建表的時(shí)候指定使用utf8的編碼集 
[client]
default-character-set = utf8

8,進(jìn)入mysql文件夾只损,并安裝mysql

# 進(jìn)入mysql
[root@CDH-141 local]# cd /usr/local/mysql
# 安裝mysql
[root@CDH-141 mysql]# bin/mysql_install_db --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data/
2019-03-08 18:11:07 [WARNING] mysql_install_db is deprecated. Please consider switching to mysqld --initialize
2019-03-08 18:11:24 [WARNING] The bootstrap log isn't empty:
2019-03-08 18:11:24 [WARNING] 2019-03-08T10:11:07.208602Z 0 [Warning] --bootstrap is deprecated. Please consider using --initialize instead

# 設(shè)置文件以及目錄的權(quán)限
[root@CDH-141 mysql]# cp ./support-files/mysql.server /etc/init.d/mysqld

9,啟動(dòng)MySQL

# 啟動(dòng)mysql
[root@CDH-141 mysql]# /etc/init.d/mysqld restart
 ERROR! MySQL server PID file could not be found!
Starting MySQL.Logging to '/usr/local/mysql/data/localhost.localdomain.err'.
 SUCCESS! 

10七咧,設(shè)置開機(jī)自啟動(dòng)

#設(shè)置開機(jī)啟動(dòng)
[root@CDH-141 mysql]# chkconfig --level 35 mysqld on
[root@CDH-141 mysql]# chkconfig --list mysqld

Note: This output shows SysV services only and does not include native
      systemd services. SysV configuration data might be overridden by native
      systemd configuration.

      If you want to list systemd services use 'systemctl list-unit-files'.
      To see services enabled on particular target use
      'systemctl list-dependencies [target]'.

mysqld          0:off   1:off   2:on    3:on    4:on    5:on    6:off

[root@CDH-141 mysql]# chkconfig --add mysqld
[root@CDH-141 mysql]# chkconfig --list mysqld

Note: This output shows SysV services only and does not include native
      systemd services. SysV configuration data might be overridden by native
      systemd configuration.

      If you want to list systemd services use 'systemctl list-unit-files'.
      To see services enabled on particular target use
      'systemctl list-dependencies [target]'.

mysqld          0:off   1:off   2:on    3:on    4:on    5:on    6:off
[root@CDH-141 mysql]# service mysqld status
MySQL running (26122)[  OK  ]
[root@CDH-141 mysql]#

11跃惫,修改環(huán)境變量配置文件

# 進(jìn)入/etc/profile文件夾
[root@CDH-141 mysql]# vi /etc/profile
修改/etc/profile,在最后添加如下內(nèi)容
# 修改/etc/profile文件
export MYSQL_HOME=/usr/local/mysql
export PATH=$MYSQL_HOME/bin:$PATH
# 使文件生效
[root@CDH-141 mysql]# source /etc/profile

12艾栋,獲得MySQL初始密碼

# 每個(gè)人的密碼是不一樣的爆存,隨機(jī)生成的
[root@CDH-141 mysql]#  cat /root/.mysql_secret  
# Password set for user 'root@localhost' at 2019-03-08 17:40:42
poc3u0mO_luv
[root@CDH-141 mysql]# 

13,修改密碼

[root@CDH-141 mysql]# mysql -uroot -p
Enter password: #此處填寫上邊獲取到的初始密碼‘poc3u0mO_luv’
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.25

Copyright (c) 2000, 2015, 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>  set PASSWORD = PASSWORD('111111@123');
Query OK, 0 rows affected, 1 warning (0.00 sec)

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

mysql> exit
Bye

# 驗(yàn)證登錄
[root@localhost mysql]# mysql -uroot -p111111@123
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 5
Server version: 5.7.27 MySQL Community Server (GPL)

Copyright (c) 2000, 2019, 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> 

14裹粤,添加遠(yuǎn)程訪問權(quán)限

注意:當(dāng)前的訪問權(quán)限是直接給root用戶添加的终蒂,如果在項(xiàng)目現(xiàn)場(chǎng)部署的時(shí)候,是不能使用root用戶的;

此時(shí)是有兩種方案的遥诉,分別做了整理:

## 方案1:直接給root用戶增加遠(yuǎn)程訪問權(quán)限
# 添加遠(yuǎn)程訪問權(quán)限
mysql> use mysql
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> update user set host='%' where user='root';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 0

mysql> select host,user from user;
+-----------+---------------+
| host      | user          |
+-----------+---------------+
| %         | root          |
| localhost | mysql.session |
| localhost | mysql.sys     |
+-----------+---------------+
3 rows in set (0.00 sec)

mysql>
--- 方案2:追加一個(gè)demo用戶拇泣,然后給demo用戶添加遠(yuǎn)程訪問的權(quán)限
mysql> use mysql
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
-- 此時(shí)是給所有用戶開放的,如果需要對(duì)不不同的用戶開發(fā)需要再單獨(dú)設(shè)置
mysql> update user set host='%' where user='demo';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 0

mysql> select host,user from user;
+-----------+---------------+
| host      | user          |
+-----------+---------------+
| %         | demo          |
| localhost | mysql.session |
| localhost | mysql.sys     |
+-----------+---------------+
3 rows in set (0.00 sec)

15矮锈,重啟MySQL使其生效

做上述操作之后霉翔,是需要重新啟動(dòng)MySQL,才能使其生效

# 重啟mysql
[root@CDH-141 mysql]# /etc/init.d/mysqld restart
Shutting down MySQL..[  OK  ]
Starting MySQL..[  OK  ]
[root@CDH-141 mysql]# 

## 重啟命令2
systemctl  start  mysql

16苞笨,如果連接失敗债朵,需要檢查防火墻

# 第一步:關(guān)閉防火墻
systemctl stop firewalld
#################
#############
####### 注意子眶,在實(shí)際中先關(guān)閉,確定是使用開發(fā)端口的方式實(shí)現(xiàn)序芦,還是直接移除臭杰,再執(zhí)行對(duì)應(yīng)的操作
##### 第二步:此時(shí)有兩種解決方案
# 方案1:移除防火墻
systemctl disable firewalld

# 方案2:開發(fā)3306端口
#  開放端口請(qǐng)根據(jù)實(shí)際訪問規(guī)則配置,這里只是單純開啟3306端口的訪問谚中,默認(rèn)全放行渴杆,在生產(chǎn)環(huán)境禁止開放所有IP訪問
# (1) 向防火墻添加 mysql 端口: 
firewall-cmd --zone=public --add-port=3306/tcp --permanent
# (2) 刷新防火墻規(guī)則: 
firewall-cmd --reload
# (3) 驗(yàn)證端口,查詢防火墻開放端口: 
firewall-cmd --zone=public --list-port
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個(gè)濱河市宪塔,隨后出現(xiàn)的幾起案子磁奖,更是在濱河造成了極大的恐慌,老刑警劉巖某筐,帶你破解...
    沈念sama閱讀 218,451評(píng)論 6 506
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件比搭,死亡現(xiàn)場(chǎng)離奇詭異,居然都是意外死亡南誊,警方通過查閱死者的電腦和手機(jī)身诺,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 93,172評(píng)論 3 394
  • 文/潘曉璐 我一進(jìn)店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來弟疆,“玉大人戚长,你說我怎么就攤上這事盗冷〉√Γ” “怎么了?”我有些...
    開封第一講書人閱讀 164,782評(píng)論 0 354
  • 文/不壞的土叔 我叫張陵仪糖,是天一觀的道長(zhǎng)柑司。 經(jīng)常有香客問我,道長(zhǎng)锅劝,這世上最難降的妖魔是什么攒驰? 我笑而不...
    開封第一講書人閱讀 58,709評(píng)論 1 294
  • 正文 為了忘掉前任,我火速辦了婚禮故爵,結(jié)果婚禮上玻粪,老公的妹妹穿的比我還像新娘。我一直安慰自己诬垂,他們只是感情好劲室,可當(dāng)我...
    茶點(diǎn)故事閱讀 67,733評(píng)論 6 392
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著结窘,像睡著了一般很洋。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上隧枫,一...
    開封第一講書人閱讀 51,578評(píng)論 1 305
  • 那天喉磁,我揣著相機(jī)與錄音谓苟,去河邊找鬼。 笑死协怒,一個(gè)胖子當(dāng)著我的面吹牛涝焙,可吹牛的內(nèi)容都是我干的。 我是一名探鬼主播孕暇,決...
    沈念sama閱讀 40,320評(píng)論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼纱皆,長(zhǎng)吁一口氣:“原來是場(chǎng)噩夢(mèng)啊……” “哼!你這毒婦竟也來了芭商?” 一聲冷哼從身側(cè)響起派草,我...
    開封第一講書人閱讀 39,241評(píng)論 0 276
  • 序言:老撾萬榮一對(duì)情侶失蹤,失蹤者是張志新(化名)和其女友劉穎铛楣,沒想到半個(gè)月后近迁,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體,經(jīng)...
    沈念sama閱讀 45,686評(píng)論 1 314
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡簸州,尸身上長(zhǎng)有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 37,878評(píng)論 3 336
  • 正文 我和宋清朗相戀三年鉴竭,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片岸浑。...
    茶點(diǎn)故事閱讀 39,992評(píng)論 1 348
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡搏存,死狀恐怖,靈堂內(nèi)的尸體忽然破棺而出矢洲,到底是詐尸還是另有隱情璧眠,我是刑警寧澤,帶...
    沈念sama閱讀 35,715評(píng)論 5 346
  • 正文 年R本政府宣布读虏,位于F島的核電站责静,受9級(jí)特大地震影響,放射性物質(zhì)發(fā)生泄漏盖桥。R本人自食惡果不足惜灾螃,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,336評(píng)論 3 330
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望揩徊。 院中可真熱鬧腰鬼,春花似錦、人聲如沸塑荒。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,912評(píng)論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽袜炕。三九已至本谜,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間偎窘,已是汗流浹背乌助。 一陣腳步聲響...
    開封第一講書人閱讀 33,040評(píng)論 1 270
  • 我被黑心中介騙來泰國(guó)打工溜在, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留,地道東北人他托。 一個(gè)月前我還...
    沈念sama閱讀 48,173評(píng)論 3 370
  • 正文 我出身青樓掖肋,卻偏偏與公主長(zhǎng)得像,于是被迫代替她去往敵國(guó)和親赏参。 傳聞我的和親對(duì)象是個(gè)殘疾皇子志笼,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 44,947評(píng)論 2 355

推薦閱讀更多精彩內(nèi)容