大致步驟如下
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