1、下載並上傳mysql rpm安裝包
tar -xvf mysql-8.4.3-1.el7.x86_64.rpm-bundle.tar
2、按照如下順序執行安裝;如果有依賴缺少,執行yum -y install 依賴名稱
rpm -ivh mysql-community-common-8.4.3-1.el7.x86_64.rpm rpm -ivh mysql-community-client-plugins-8.4.3-1.el7.x86_64.rpm rpm -ivh mysql-community-libs-8.4.3-1.el7.x86_64.rpm rpm -ivh mysql-community-client-8.4.3-1.el7.x86_64.rpm rpm -ivh mysql-community-icu-data-files-8.4.3-1.el7.x86_64.rpm rpm -ivh mysql-community-server-8.4.3-1.el7.x86_64.rpm
3、修改配置檔案
vi /etc/my.cnf
在[mysqld]組下新增如下內容
datadir=/data/program/mysql/data ##這個目錄根據自己的實際情況而定 port=3306 sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION character-set-server=utf8 collation-server=utf8_general_ci lower_case_table_names=1 max_connections = 10000 mysql_native_password=ON skip-grant-tables ##修改完密碼後登出掉該行,重啟mysql
4、安裝完成後會有mysql:mysql的使用者;如果沒有則手動新增mysql組和mysql使用者
chown -R mysql:mysql /data/program/mysql/data ##my.cnf中的datadir目錄
5、啟動mysql,檢視路徑下是否有mysql資料檔案
systemctl start mysqld
6、檢視臨時生成的密碼,登陸後修改密碼
cat /var/log/mysqld.log | grep 'temp'
mysql -uroot -p flush privileges; alter user 'root'@'localhost' identified with mysql_native_password by 'new_password';//新密碼最低8位、大小寫、特殊字元 flush privileges;
7、註釋掉my.cnf裡面的skip-grant-tables,然後重新啟動mysql
systemctl restart mysqld
8、新增遠端訪問使用者root或者其他名,建議使用別的名稱
mysql -uroot -p #輸入修改後的密碼 use mysql; create user 'root'@'%' identified with mysql_native_password by '新密碼'; grant all privileges on *.* to 'root'@'%'; flush privileges;
9、加入開機啟動
systemctl enable mysqld
10、遠端連線測試