Linux MySQL 壓縮包安裝手冊

0沸版、說在前面的話

需要讀者具備一定的 Linux 基礎(chǔ)

1昏鹃、 機器環(huán)境說明

A. root 用戶操作
B. 操作系統(tǒng)
image.png

2、MySQL 安裝版本說明

使用的是 Linux 通用版本下載:
下載地址:https://dev.mysql.com/downloads/mysql/5.6.html#downloads
或者
直接下載:wget https://cdn.mysql.com//Downloads/MySQL-5.6/mysql-5.6.36-linux-glibc2.5-x86_64.tar.g

3寡键、解壓并重命名壓縮包

# tar zxf mysql-5.6.36-linux-glibc2.5-x86_64.tar.gz
# mv mysql-5.6.36-linux-glibc2.5-x86_64 mysql

4、創(chuàng)建 mysql 用戶

# useradd mysql

5雪隧、修改 mysql 安裝目錄權(quán)限

#  chown -R mysql:mysql /usr/local/mysql

6西轩、修改配置文件并拷貝到 mysql 安裝目錄(/usr/local/mysql/)

# vim /etc/my.cnf

修改為如下內(nèi)容:
[mysqld]
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
socket=/usr/local/mysql/mysql.sock
user=mysql
symbolic-links=0
[mysql]
socket=/usr/local/mysql/mysql.sock
[mysqld_safe]
pid-file=/usr/local/mysql/mysqld.pid
log-error=/usr/local/mysql/mysqld.log

# cp /etc/my.cnf /usr/local/mysql/

7、初始化數(shù)據(jù)

# cd  /usr/local/mysql
# ./scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --user=mysql

8脑沿、啟動 mysqld 服務(wù)

# bin/mysqld_safe --user=mysql &

如果出現(xiàn)如下圖錯誤提示信息:

image.png
,可以通過手動創(chuàng)建 mysqld.log日志文件然后權(quán)限替換回來即可解決藕畔,具體操作如下:# touch /usr/local/mysql/mysqld.log
image.png

再次執(zhí)行 # bin/mysqld_safe --user=mysql &

9、mysql 初始化配置去除隱患

#   bin/mysql_secure_installation

會出現(xiàn)如下錯誤提示信息:
Enter current password for root (enter for none): ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)

(翻墻Google 一番發(fā)現(xiàn))Caused:Since I have set the mysqld socket to /usr/local/mysql/mysql.sock in /etc/my.cnf as the following, not the default path /tmp/mysql.sock.
Fixed:
I added one more line “/usr/local/mysql/mysql.sock” into /usr/local/mysql/bin/mysql_secure_installation at make_config section as the following. Then the problem got fixed.
解決方案:
# vim /usr/local/mysql/bin/mysql_secure_installation

image.png

配置好以后再次執(zhí)行 # bin/mysql_secure_installation

出現(xiàn)如下操作提示:
默認沒有密碼直接 enter 回車即可
Enter current password for root (enter for none):
OK, successfully used password, moving on...

Setting the root password ensures that nobody can log into the MySQL
root user without the proper authorisation.
設(shè)置root 用戶密碼 我這里設(shè)置的是123456
Set root password? [Y/n] y
New password:
Re-enter new password:
Password updated successfully!
Reloading privilege tables..

By default, a MySQL installation has an anonymous user, allowing anyone
to log into MySQL without having to have a user account created for
them. This is intended only for testing, and to make the installation
go a bit smoother. You should remove them before moving into a
production environment.
刪除匿名用戶
Remove anonymous users? [Y/n] y
... Success!

Normally, root should only be allowed to connect from 'localhost'. This
ensures that someone cannot guess at the root password from the network.
是否允許 root 遠程登錄
Disallow root login remotely? [Y/n] n
... skipping.
By default, MySQL comes with a database named 'test' that anyone can
access. This is also intended only for testing, and should be removed
before moving into a production environment.
是否刪除測試數(shù)據(jù)庫
Remove test database and access to it? [Y/n] n
... skipping.

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.
刷新授權(quán)表使修改生效
Reload privilege tables now? [Y/n] y
... Success!
All done! If you've completed all of the above steps, your MySQL
installation should now be secure.
Thanks for using MySQL!
Cleaning up...

10庄拇、配置 root 用戶遠程登陸

# bin/mysql -uroot -p

Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 10
Server version: 5.6.36 MySQL Community Server (GPL)
Copyright (c) 2000, 2017, 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> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| test |
+--------------------+
4 rows in set (0.00 sec)
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> select user,host,password from user;
+------+-----------+-------------------------------------------+
| user | host | password |
+------+-----------+-------------------------------------------+
| root | localhost | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |
| root | bigdata01 | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |
| root | 127.0.0.1 | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |
| root | ::1 | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |
+------+-----------+-------------------------------------------+
4 rows in set (0.00 sec)

授權(quán)遠程登錄權(quán)限

mysql> GRANT ALL PRIVILEGES ON . TO 'root'@'%' IDENTIFIED BY PASSWORD '*6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9' WITH GRANT OPTION ;
mysql> flush privileges;

11注服、簡化服務(wù)啟動

a.查看啟動進程
# pgrep mysql              
29227
29408
# kill -9 29227 29408
# pgrep mysql
b.簡化形式
# cd support-files  
# ./mysql.server start
Starting MySQL.                                            [  OK  ]
# ./mysql.server stop

# cp mysql.server /etc/init.d/mysql
# service mysql start
Starting MySQL.                                            [  OK  ]
# service mysql stop
Shutting down MySQL..   

12、配置 mysql 環(huán)境 + 開機自動啟動

a措近、配置環(huán)境變量
# vim /etc/profile

export MYSQL_HOME="/software/mysql-5.6.21"
export PATH="$PATH:$MYSQL_HOME/bin"

b溶弟、自啟動服務(wù)
# chkconfig mysql on
# chkconfig --list|grep mysql
mysql           0:off   1:off   2:on    3:on    4:on    5:on    6:off
                               [  OK  ]
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個濱河市瞭郑,隨后出現(xiàn)的幾起案子可很,更是在濱河造成了極大的恐慌,老刑警劉巖凰浮,帶你破解...
    沈念sama閱讀 217,277評論 6 503
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件我抠,死亡現(xiàn)場離奇詭異苇本,居然都是意外死亡,警方通過查閱死者的電腦和手機菜拓,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 92,689評論 3 393
  • 文/潘曉璐 我一進店門瓣窄,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人纳鼎,你說我怎么就攤上這事俺夕。” “怎么了贱鄙?”我有些...
    開封第一講書人閱讀 163,624評論 0 353
  • 文/不壞的土叔 我叫張陵劝贸,是天一觀的道長。 經(jīng)常有香客問我逗宁,道長映九,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 58,356評論 1 293
  • 正文 為了忘掉前任瞎颗,我火速辦了婚禮件甥,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘哼拔。我一直安慰自己引有,他們只是感情好,可當(dāng)我...
    茶點故事閱讀 67,402評論 6 392
  • 文/花漫 我一把揭開白布倦逐。 她就那樣靜靜地躺著譬正,像睡著了一般。 火紅的嫁衣襯著肌膚如雪檬姥。 梳的紋絲不亂的頭發(fā)上导帝,一...
    開封第一講書人閱讀 51,292評論 1 301
  • 那天,我揣著相機與錄音穿铆,去河邊找鬼您单。 笑死,一個胖子當(dāng)著我的面吹牛荞雏,可吹牛的內(nèi)容都是我干的虐秦。 我是一名探鬼主播,決...
    沈念sama閱讀 40,135評論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼凤优,長吁一口氣:“原來是場噩夢啊……” “哼悦陋!你這毒婦竟也來了?” 一聲冷哼從身側(cè)響起筑辨,我...
    開封第一講書人閱讀 38,992評論 0 275
  • 序言:老撾萬榮一對情侶失蹤俺驶,失蹤者是張志新(化名)和其女友劉穎,沒想到半個月后棍辕,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體暮现,經(jīng)...
    沈念sama閱讀 45,429評論 1 314
  • 正文 獨居荒郊野嶺守林人離奇死亡还绘,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 37,636評論 3 334
  • 正文 我和宋清朗相戀三年,在試婚紗的時候發(fā)現(xiàn)自己被綠了栖袋。 大學(xué)時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片拍顷。...
    茶點故事閱讀 39,785評論 1 348
  • 序言:一個原本活蹦亂跳的男人離奇死亡,死狀恐怖塘幅,靈堂內(nèi)的尸體忽然破棺而出昔案,到底是詐尸還是另有隱情,我是刑警寧澤电媳,帶...
    沈念sama閱讀 35,492評論 5 345
  • 正文 年R本政府宣布踏揣,位于F島的核電站,受9級特大地震影響匾乓,放射性物質(zhì)發(fā)生泄漏捞稿。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點故事閱讀 41,092評論 3 328
  • 文/蒙蒙 一钝尸、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧搂根,春花似錦珍促、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,723評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽。三九已至仁卷,卻和暖如春穴翩,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背锦积。 一陣腳步聲響...
    開封第一講書人閱讀 32,858評論 1 269
  • 我被黑心中介騙來泰國打工芒帕, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留,地道東北人丰介。 一個月前我還...
    沈念sama閱讀 47,891評論 2 370
  • 正文 我出身青樓背蟆,卻偏偏與公主長得像,于是被迫代替她去往敵國和親哮幢。 傳聞我的和親對象是個殘疾皇子带膀,可洞房花燭夜當(dāng)晚...
    茶點故事閱讀 44,713評論 2 354

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