溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點(diǎn)擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

MySQL 5.7部署分類

發(fā)布時間:2020-04-22 14:05:14 來源:億速云 閱讀:279 作者:三月 欄目:MySQL數(shù)據(jù)庫

本文主要給大家介紹MySQL 5.7部署分類,其所涉及的東西,從理論知識來獲悉,有很多書籍、文獻(xiàn)可供大家參考,從現(xiàn)實(shí)意義來講,億速云累計(jì)多年的實(shí)踐經(jīng)驗(yàn)可分享給大家。                                                    

MySQL5.7部署可以分為rpm包部署、源碼包部署、二進(jìn)制包部署。

源碼包部署:優(yōu)點(diǎn)是靈活性較高,可以自定義編譯參數(shù),效率高,缺點(diǎn)是部署時間較長
二進(jìn)制包部署:優(yōu)點(diǎn)是事先已經(jīng)編譯好,部署較快,可以自定義一部分參數(shù),缺點(diǎn)是時間相比使用yum安裝,還是較長
rpm包部署:優(yōu)點(diǎn)是部署速度快,缺點(diǎn)是定制性差
一般沒有特殊要求時,可以使用yum包部署
下面開始使用二進(jìn)制包部署MySQL5.7.26二進(jìn)制包
下載地址:https://dev.mysql.com/downloads/mysql/5.7.html#downloads
在Select Operating System選項(xiàng)中選中”Linux Generic",在最下方的Linux - Generic (glibc 2.12) (x86, 64-bit), TAR項(xiàng)后方的download即可下載
1.添加MySQL數(shù)據(jù)庫運(yùn)行的用戶和用戶組

MySQL 5.7部署分類

groupadd -r mysql
useradd -r -g mysql mysql

2.此次MySQL部署的目錄為/application,將MySQL安裝包解壓到/application/mysql-5.7.26-linux-glibc2.12-x86_64目錄,并為此目錄創(chuàng)建軟鏈接

 ln -s /application/mysql-5.7.26-linux-glibc2.12-x86_64 /application/mysql

更改目錄權(quán)限
chown -R mysql:mysql /application/mysql-5.7.26-linux-glibc2.12-x86_64
3.初始化數(shù)據(jù)庫

/application/mysql-5.7.26-linux-glibc2.12-x86_64/bin/mysqld --initialize --user=mysql --basedir=/application/mysql --datadir=/application/mysql/data

[root@chanye application]# /application/mysql-5.7.26-linux-glibc2.12-x86_64/bin/mysqld --initialize --user=mysql --basedir=/application/mysql --datadir=/application/mysql/data
2019-06-18T08:35:49.103727Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2019-06-18T08:35:49.885283Z 0 [Warning] InnoDB: New log files created, LSN=45790
2019-06-18T08:35:49.944856Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2019-06-18T08:35:50.002905Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 138aa81a-91a4-11e9-8f49-005056813525.
2019-06-18T08:35:50.004044Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2019-06-18T08:35:50.004493Z 1 [Note] A temporary password is generated for root@localhost: O;iSA6z>SieK

記住最后一行的臨時密碼
4.創(chuàng)建RSA  private key

/application/mysql/bin/mysql_ssl_rsa_setup --datadir=/application/mysql/data
Generating a 2048 bit RSA private key
..........................................................................................+++
....+++
writing new private key to 'ca-key.pem'
-----
Generating a 2048 bit RSA private key
............................+++
.+++
writing new private key to 'server-key.pem'
-----
Generating a 2048 bit RSA private key
..........................................................................+++
...........................................................................................+++
writing new private key to 'client-key.pem'

5.添加mysql到開機(jī)自啟動

cp /application/mysql-5.7.26-linux-glibc2.12-x86_64/support-files/mysql.server /etc/init.d/mysqld

修改/etc/init.d/mysqld中的basedir和datadir

46 basedir=/application/mysql
 47 datadir=/application/mysql/data

加入開機(jī)自啟動

chkconfig mysqld on
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

修改全局配置文件將mysql可執(zhí)行路徑加入到PATH,在/etc/profile最后一行添加:

export PATH=/application/mysql/bin:$PATH

使用source /etc/profile使配置生效
刪掉系統(tǒng)自帶的/etc/my.cnf或者改名,在/application/mysql/目錄新建my.cnf,并且將文件屬性調(diào)整為mysql:mysql

[mysqld]
character-set-server=utf8
datadir=/application/mysql/data
socket=/application/mysql/mysql.sock
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
# Settings user and group are ignored when systemd is used.
# If you need to run mysqld under a different user or group,
# customize your systemd unit file for mariadb according to the
# instructions in http://fedoraproject.org/wiki/Systemd

#
# include all files from the config directory
#
!includedir /etc/my.cnf.d

[client]
character-set-server=utf8
socket=/application/mysql/mysql.sock

[mysql]
character-set-server=utf8
socket=/application/mysql/mysql.sock

6.啟動mysql
啟動mysql

/etc/init.d/mysqld start

此時使用初始化提供的密碼進(jìn)行登陸

# mysql -uroot -p
Enter password: 
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)

系統(tǒng)默認(rèn)的客戶端使用的mysql.sock文件是基于unix sock的,此時最簡便的辦法是創(chuàng)建一個軟鏈接

ln -s /application/mysql/mysql.sock /tmp/mysql.sock

如果不創(chuàng)建軟鏈接,使用mysql命令登陸的時候使用-S選項(xiàng),手工指定mysql.sock的位置也是可以登陸的
登陸成功后需要更改管理員密碼

alter user 'root'@'localhost' identified by '598545$kdOctamvsU';
flush privileges;

查看mysql狀態(tài)

mysql> status;
--------------
mysql  Ver 14.14 Distrib 5.7.26, for linux-glibc2.12 (x86_64) using  EditLine wrapper

Connection id:      4
Current database:   
Current user:       root@localhost
SSL:            Not in use
Current pager:      stdout
Using outfile:      ''
Using delimiter:    ;
Server version:     5.7.26 MySQL Community Server (GPL)
Protocol version:   10
Connection:     Localhost via UNIX socket
Server characterset:    utf8
Db     characterset:    utf8
Client characterset:    utf8
Conn.  characterset:    utf8
UNIX socket:        /application/mysql/mysql.sock
Uptime:         7 min 56 sec

Threads: 2  Questions: 14  Slow queries: 0  Opens: 116  Flush tables: 1  Open tables: 109  Queries per second avg: 0.029

--------------

看了以上介紹MySQL 5.7部署分類,希望能給大家在實(shí)際運(yùn)用中帶來一定的幫助。本文由于篇幅有限,難免會有不足和需要補(bǔ)充的地方,大家可以繼續(xù)關(guān)注億速云行業(yè)資訊板塊,會定期給大家更新行業(yè)新聞和知識,如有需要更加專業(yè)的解答,可在官網(wǎng)聯(lián)系我們的24小時售前售后,隨時幫您解答問題的。

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI