Linux MySQL 壓縮包安裝手冊

0、說在前面的話

需要讀者具備一定的 Linux 基礎

1、 機器環境說明

A. root 用戶操作
B. 操作系統
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、創建 mysql 用戶

# useradd mysql

5、修改 mysql 安裝目錄權限

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

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

# vim /etc/my.cnf

修改為如下內容:
[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、初始化數據

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

8、啟動 mysqld 服務

# bin/mysqld_safe --user=mysql &

如果出現如下圖錯誤提示信息:

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

再次執行 # bin/mysqld_safe --user=mysql &

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

#   bin/mysql_secure_installation

會出現如下錯誤提示信息:
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 一番發現)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

配置好以后再次執行 # bin/mysql_secure_installation

出現如下操作提示:
默認沒有密碼直接 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.
設置root 用戶密碼 我這里設置的是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.
是否刪除測試數據庫
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.
刷新授權表使修改生效
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)

授權遠程登錄權限

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

11、簡化服務啟動

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 環境 + 開機自動啟動

a、配置環境變量
# vim /etc/profile

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

b、自啟動服務
# chkconfig mysql on
# chkconfig --list|grep mysql
mysql           0:off   1:off   2:on    3:on    4:on    5:on    6:off
                               [  OK  ]
最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容