溫馨提示×

溫馨提示×

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

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

linux下多個mysql5.7.19安裝的方法

發(fā)布時間:2021-03-02 10:32:39 來源:億速云 閱讀:274 作者:清風 欄目:MySQL數(shù)據(jù)庫

這篇“l(fā)inux下多個mysql5.7.19安裝的方法”除了程序員外大部分人都不太理解,今天小編為了讓大家更加理解“l(fā)inux下多個mysql5.7.19安裝的方法”,給大家總結(jié)了以下內(nèi)容,具有一定借鑒價值,內(nèi)容詳細步驟清晰,細節(jié)處理妥當,希望大家通過這篇文章有所收獲,下面讓我們一起來看看具體內(nèi)容吧。

什么是Linux系統(tǒng)

Linux是一種免費使用和自由傳播的類UNIX操作系統(tǒng),是一個基于POSIX的多用戶、多任務(wù)、支持多線程和多CPU的操作系統(tǒng),使用Linux能運行主要的Unix工具軟件、應(yīng)用程序和網(wǎng)絡(luò)協(xié)議。

環(huán)境:centos 6.5

1-下載

linux下多個mysql5.7.19安裝的方法

2-跳過登陸

linux下多個mysql5.7.19安裝的方法

3-1安裝多個數(shù)據(jù)庫需要配置自己的my.cnf,如果只安裝一個,系統(tǒng)沒有安裝過直接這個命令就可以

shell> groupadd mysql
shell> useradd -r -g mysql -s /bin/false mysql
shell> cd /usr/local
shell> tar zxvf /path/to/mysql-VERSION-OS.tar.gz
shell> ln -s full-path-to-mysql-VERSION-OS mysql
shell> cd mysql
shell> mkdir mysql-files
查看下有沒有data目錄如果沒有的話增加個命令(mkdir data)
shell> chmod 750 mysql-files
shell> chown -R mysql .
shell> chgrp -R mysql .
shell> bin/mysql_install_db --user=mysql # MySQL 5.7.5
shell> bin/mysqld --initialize --user=mysql # MySQL 5.7.6 and up
shell> bin/mysql_ssl_rsa_setup # MySQL 5.7.6 and up
shell> chown -R root .
shell> chown -R mysql data mysql-files
shell> bin/mysqld_safe --user=mysql &
# Next command is optional
shell> cp support-files/mysql.server /etc/init.d/mysql.server

安裝好了就可以直接跳到登陸 步驟5

下面說安裝多個mysql情況:

3-2安裝多個數(shù)據(jù)庫需要安照如下命令:

1-增加配置文件 my.cnf (在mysql目錄下命令touch my.cnf):

下面配置文件可以直接使用粘貼復制進去

然后創(chuàng)建log文件 /xcxyz/log/mysql/error.log

[mysqld]
basedir= /usr/local/mysql-5.7.19-3307
datadir = /usr/local/mysql-5.7.19-3307/data
port = 3307
character-set-server=utf8
server_id = 11
#該socket最好指定,不指定的話默認的話 是使用的默認的socket文件 而且登陸數(shù)據(jù)庫的時候會有我下面的問題
socket = /tmp/mysql3307.sock 
log-error = /xcxyz/log/mysql/error.log
pid-file = /usr/local/mysql-5.7.19-3307/data/mysql-5.7.19-3307.pid

2-執(zhí)行如下命令

2-1增加用戶 組 我的用戶和組都使用的是mysqlosf這個隨意

shell> groupadd mysql
shell> useradd -r -g mysql -s /bin/false mysql
shell> cd /usr/local
shell> tar zxvf /path/to/mysql-VERSION-OS.tar.gz

2-2建立軟連接:

shell> ln -s full-path-to-mysql-VERSION-OS mysql
shell> cd mysql
shell> mkdir mysql-files

查看下有沒有data目錄如果沒有的話增加個命令(mkdir data)

2-3授權(quán)當前目錄:

shell> chmod 750 mysql-files
shell> chown -R mysqlosf .
shell> chgrp -R mysqlosf .

2-4編譯

bin/mysqld --defaults-file=/usr/local/full-path-to-mysql-VERSION-OS/my.cnf --initialize --user=mysqlosf  

查看日志輸出:vi /xcxyz/log/mysql/error.log
2017-07-24T03:13:47.933684Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2017-07-24T03:13:49.979892Z 0 [Warning] InnoDB: New log files created, LSN=45790
2017-07-24T03:13:50.262941Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2017-07-24T03:13:50.330756Z 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: 1d702294-701e-11e7-98a1-00163e30bbf6.
2017-07-24T03:13:50.340474Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2017-07-24T03:13:50.344419Z 1 [Note] A temporary password is generated for root@localhost: jZpgHhigx5>i(特別重要一會初始化密碼)

2-5建立密鑰

shell> bin/mysql_ssl_rsa_setup --defaults-file=/usr/local/mysql-5.7.19-3307/my.cnf

linux下多個mysql5.7.19安裝的方法

2-6重新授權(quán)分配

shell> chown -R root .
shell> chown -R mysql data mysql-files

2-7啟動后臺mysql

bin/mysqld_safe --defaults-file=/usr/local/full-path-to-mysql-VERSION-OS/my.cnf --user=mysqlosf &

linux下多個mysql5.7.19安裝的方法

Next command is optional

shell> cp support-files/mysql.server /etc/init.d/mysql.server

2-8查看mysql是否啟動 ps -ef | grep mysql

4登陸mysql修改密碼使用剛才的臨時密碼

linux下多個mysql5.7.19安裝的方法

我這里又出問題了哈哈,始終登陸不上去

Access denied for user 'root'@'localhost' (using password:YES)解決方法最下面

如果登陸上去了可以直接使用剛才的臨時密碼登陸并且設(shè)置密碼

5-登錄MySQL之后,要求立即修改密碼,否則不能進行任何操作。執(zhí)行下面的命令修改'root'@'localhost'的密碼:

SET PASSWORD = PASSWORD('root');
 ALTER USER 'root'@'localhost' PASSWORD EXPIRE NEVER; 
flush privileges;

6-為了可以遠程登錄,增加一個'root'@'%'賬號:

grant all privileges on *.* to 'root'@'%' identified by 'root' with grant option;

7-本地測試連接

按照上面的辦法,繼續(xù)解壓安裝mysql-5.7.19-linux-glibc2.5-x86_64.tar.gz,并且配置為3308,3309端口,就可以安裝多個mysql了。

解決方案安裝好了登陸不上去:
如果像我上面一樣的話
原因是如下紅色框內(nèi)的英文 我的是第二個mysql需要指定socket和port,英文意思就是說 如果你沒有指定socket的話那么會選擇默認的 因為我們安裝多個mysql 所以這個必須指定

mysql --socket=/tmp/mysql3307.sock --port=3307 -uroot -p

linux下多個mysql5.7.19安裝的方法

如果這里不小心丟失了密碼了或者密碼過期了那么可以通過這個方式重置密碼:

linux下多個mysql5.7.19安裝的方法

5-重置密碼:

5-1關(guān)閉進程

kill `cat /usr/local/mysql-5.7.19-3307/data/mysql-5.7.19-3307.pid`

5-2創(chuàng)建文件mysql-init

linux下多個mysql5.7.19安裝的方法

5-2-1文件內(nèi)容

第一種內(nèi)容:

ALTER USER 'root'@'localhost' IDENTIFIED BY 'mysqlosf';

linux下多個mysql5.7.19安裝的方法

保存內(nèi)容之后啟動

復制代碼 代碼如下:

bin/mysqld_safe --defaults-file=/usr/local/mysql-5.7.19-3307/my.cnf  --init-file=/usr/local/mysql-5.7.19-3307/mysql-init    --user=mysqlosf     &

如果上述內(nèi)容不成功選擇第二種內(nèi)容

UPDATE mysql.user
 SET authentication_string = PASSWORD('MyNewPass'), password_expired = 'N'
 WHERE User = 'root' AND Host = 'localhost';
FLUSH PRIVILEGES;

linux下多個mysql5.7.19安裝的方法

保存內(nèi)容之后啟動

復制代碼 代碼如下:

bin/mysqld_safe --defaults-file=/usr/local/mysql-5.7.19-3307/my.cnf  --init-file=/usr/local/mysql-5.7.19-3307/mysql-init   --user=mysqlosf     &

linux下多個mysql5.7.19安裝的方法

感謝你的閱讀,希望你對“l(fā)inux下多個mysql5.7.19安裝的方法”這一關(guān)鍵問題有了一定的理解,具體使用情況還需要大家自己動手實驗使用過才能領(lǐng)會,快去試試吧,如果想閱讀更多相關(guān)知識點的文章,歡迎關(guān)注億速云行業(yè)資訊頻道!

向AI問一下細節(jié)

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

AI