[centos] 環境安裝之 mysql離線版壓縮包(mysql-5.7.16-linux-glibc2.5-x86_64.tar)

大致步驟如下

1.下載
2.檢查系統有無mysql
3.創建 mysql用戶
4.解壓jar包
5.更改所有文件權限爲mysql:mysql
6.複製配置文件到/etc/my.cnf並編輯
7.複製mysqld服務到/etc/init.d/mysqld
8.運行 ./bin/mysqld –initialize
9.啓動服務(出現.pid文件錯誤用chown -R mysql:mysql /usr/local/mysql/data即可)
10.用mysqld –initialize 產生的密碼登錄mysql
11修改密碼

具體爲:


下載:http://dev.mysql.com/downloads/mysql/#downloads


rpm -qa |grep mysql

有則刪除:yum remove pkg


創建用戶

groupadd mysql 
useradd -r -g mysql mysql

解壓

tar xvf mysql-5.7.16-linux-glibc2.5-x86_64.tar

移動

mv mysql-5.7.16-linux-glibc2.5-x86_64 /usr/local/mysql/

然後進入目錄

cd /usr/local/mysql

複製配置文件

cp support-files/my-default.cnf /etc/my.cnf

有覆蓋提示輸入:yes

編輯my.cnf文件

vi /etc/my.cnf

我的是:

# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html
# * DO NOT EDIT THIS FILE. It’s a template which will be copied to the
# * default location during install, and will be replaced if you
# * upgrade to a newer version of MySQL.

[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 leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin

# These are commonly set, remove the # and set as required.
basedir =/usr/local/mysql
datadir =/usr/local/mysql/data
# port = …..
# server_id = …..
# socket = …..

# 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

然後把mysqld服務安裝

cp support-files/mysql.server /etc/init.d/mysqld

然後初始化數據庫

./bin/mysqld --initialize

這一步會產生一個隨機密碼(也可能會出錯,很多種錯誤,我不列舉,本來就是給自己看,如果你有問題歡迎截圖來回復,我是失敗了n次才成功,很多錯誤都見過)


如果初始化成功了,那麼就開啓服務吧

service mysqld start

這裏可能會出現的錯誤有:

The server quit without updating PID file (/usr/local/mysql/data/snsgou.pid).

這個是因爲權限不夠吧!因爲至始至終,mysql文件夾下的data文件夾都不是我們創建的,也就是自動創建的!
所以需要重新給下權限:

chown mysql:mysql /usr/local/mysql/data

接着在重啓電腦(爲了關閉mysqld進程..我不會kill -9 殺進程,老是殺錯,還是重啓實在),然後在重新 service mysqld start 試試!


歡迎回復討論mysql的安裝!據說centos7用yum安裝是MariaDB!有空討論!還有yum換成網易的源可以見菜鳥教程:http://www.runoob.com/linux/linux-yum.html

發佈了62 篇原創文章 · 獲贊 23 · 訪問量 8萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章