上期我們分享了CRMEB多商戶系統(tǒng)(Java)升級MySQL 8的完整攻略,其中提到一個常見問題——如果你的服務(wù)器內(nèi)存只有4G,或安裝了寶塔這類面板,可能直接安裝MySQL 8會失敗。
當時我們建議:可以通過命令行手動編譯安裝,再外鏈到面板進行管理。
是不是聽起來有點麻煩?別急,今天就是來助攻的!
這篇文章手把手帶你在CentOS服務(wù)器上編譯安裝MySQL 8,專治各種環(huán)境不符、內(nèi)存不足、安裝失敗。如果你也卡在這個環(huán)節(jié),趕緊往下看吧!
1、下載MySQL 8安裝包
官方地址:https://dev.mysql.com/downloads/mysql/
2、上傳、解壓MySQL
將下載好的MySQL包上傳到/usr/local/目錄下,根據(jù)包的后綴選擇解壓語句。
tar -zxvf mysql-8.0.43-linux-glibc2.28-x86\_64.tar.gz
或者
tar -xvf mysql-8.0.43-linux-glibc2.28-x86\_64.tar.xz
目錄改名:
mv mysql-8.0.43-linux-glibc2.28-x86\_64 mysql-8.0.43
#創(chuàng)建data文件夾 存儲文件
cd mysql-8.0.34
mkdir data
3、創(chuàng)建用戶組以及密碼
groupadd mysql
useradd -g mysql mysql
#授權(quán)用戶
chown -R mysql.mysql /usr/local/mysql-8.0.34
4、切換到bin目錄下,安裝MySQL
cd bin
./mysqld --user=mysql --lower\_case\_table\_names=1 --basedir=/usr/local/mysql-8.0.34 --datadir=/usr/local/mysql-8.0.34/data/ --initialize
Tips:??得到臨時密碼,這里的密碼記得保存??
5、編輯my.cnf文件
vi /etc/my.cnf
添加以下內(nèi)容:
[mysqld]
basedir=/usr/local/mysql-8.0/
datadir=/usr/local/mysql-8.0/data/
socket=/tmp/mysql.sock
character-set-server=UTF8MB4
symbolic-links=0
lower\_case\_table\_names=1
6、添加mysqld服務(wù)到系統(tǒng)
cd /usr/local/mysql-8.0.34
cp -a ./support-files/mysql.server /etc/init.d/mysql
#授權(quán)以及添加服務(wù)
chmod +x /etc/init.d/mysql
chkconfig --add mysql
7、啟動MySQL
systemctl start mysql
#查看啟動狀態(tài)
systemctl status mysql
#將mysql命令添加到服務(wù)
ln -s /usr/local/mysql-8.0/bin/mysql /usr/bin
8、登錄MySQL
mysql -uroot -p 密碼使用之前隨機生成的密碼
mysql -uroot -p
操作記錄
mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.34
Copyright (c) 2000, 2021, Oracle and/or its affiliates.
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>
9、修改root密碼
這里有兩種方式可以實現(xiàn):
第一種:
[root\@mysql-server \~]# mysql -uroot -p'woHtkMgau9,w' #登錄
mysql: \[Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.27
....
mysql> alter user 'root'@'localhost' identified by 'Yang\@123';
Query OK, 0 rows affected (0.01 sec)
mysql> flush privileges; //刷新權(quán)限表
Query OK, 0 rows affected (0.00 sec)
mysql> exit
Bye
\[root\@mysql-server \~]# mysql -uroot -p'Yang\@123'
mysql: \[Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.27 MySQL Community Server (GPL)
...
mysql> exit
Bye
第二種:
mysqladmin -u root -p'舊密碼' password '新密碼'
注意:修改密碼必須包含大小寫字母、數(shù)字和特殊符號元素,長度不能小于8位。
10、修改遠程鏈接并生效
#進入到mysql
use mysql;
update user set host='%' where user='root';
flush privileges;