Centos8安裝mysql8的詳細過程(免安裝版/或者二進制包方式安裝)

二進制包方式安裝

一、首先檢查服務器上是否安裝有mysql:

第一步:查看mysql安裝版本
rpm -qa|grep -i mysql

第二步:卸載Mysql
rpm -ev –nodeps 【上一步查詢到的mysql版本名稱】

最後刪除關於mysql相關的文件夾:查找根目錄下所有者是mysql和有mysql名稱的文件
find / -user mysql
find / -name mysql
把查找出的目錄文件刪除:rm -rf 路徑

二、開始安裝配置mysql

mysql-8.0.30-linux-glibc2.12-x86_64.tar.xz

網址:MySQL :: Download MySQL Community Server (Archived Versions)

上傳到服務器上,解壓,然後改名,copy到想要的安裝目錄(/usr/local/)

目錄計劃:

安裝目錄:/usr/local/mysql

data 目錄:/data/mysql/data/

日志位置:/data/mysql/mysql_error.err

xz -d  tar xvf mysql-8.0.30-linux-glibc2.12-x86_64.tar.xz
tar xvf mysql-8.0.30-linux-glibc2.12-x86_64.tar
mv mysql-8.0.30-linux-glibc2.12-x86_64 mysql
mv mysql /usr/local/

創建mysql用戶和用戶組

groupadd mysql
useradd -r -g mysql -s /bin/false mysql

將安裝目錄所有者及所屬組改為mysql ,並創建相關文件夾

cd /usr/local/
chown -R mysql:mysql /usr/local/mysql/
ll
mkdir -p /data/mysql/{data,backup,scripts,binlog}
ll /data/mysql/
chown -R mysql:mysql /data/mysql/

添加環境變量,並修改my.cnf配置文件

echo "export PATH=$PATH:/usr/local/mysql/bin"  >>  /etc/profile
source /etc/profile
vi /etc/my.cnf
[mysqld]
user=mysql
port=3306
#basedir=/data/mysql
datadir = /data/mysql/data/
default_authentication_plugin=mysql_native_password
log_error=/data/mysql/mysql_error.err
max_connections=10000
max_connect_errors=10
character-set-server=utf8mb4
default-storage-engine=INNODB
default_authentication_plugin=mysql_native_password
[mysql]
default-character-set=utf8mb4

初始化mysql數據庫

mysqld --initialize --user=mysql

/data/mysql/mysql_error.err裡記錄瞭 mysql初始密碼

將mysql加入到服務,並設置開機自啟,啟動mysql

cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
chkconfig mysqld on
systemctl start mysqld 

連接mysql

遇到報錯

[root@localhost mysql]# mysql -uroot -p
mysql: error while loading shared libraries: libtinfo.so.5: cannot open shared object file: No such file or directory

解決方案:

[root@localhost mysql]# sudo ln -s /usr/lib64/libtinfo.so.6.1 /usr/lib64/libtinfo.so.5

再次連接SQL

[root@localhost mysql]# 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.30

Copyright (c) 2000, 2022, 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> alter user root@localhost identified by '111111';
Query OK, 0 rows affected (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> update user set host='%' where user='root';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 0
# 刷新權限
mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)
# 賦權限
mysql> grant all privileges on *.* to 'root'@'%' with grant option;
Query OK, 0 rows affected (0.00 sec)#刷新權限
mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)
mysql> quit

#刷新權限

systemctl restart mysql
or
service mysql restart

重啟服務且測試

systemctl restart mysqlorservice mysql restart

查看防火墻開放端口

  firewall-cmd –list-all

在防火墻中將3306端口開放

  firewall-cmd –zone=public –add-port=3306/tcp –permanent

  firewall-cmd –reload

  //–permanent為永久生效,沒有此參數 服務器重啟後配置失效

在Navicat上測試連接

重啟linux後測試自啟動(可選)
  reboot

測試mysql服務是否自啟動

  systemctl status mysql

參考文獻:

(1條消息) Linux下免安裝版本的mysql5.7

到此這篇關於Centos8安裝mysql8的詳細過程(免安裝版/或者二進制包方式安裝)的文章就介紹到這瞭,更多相關Centos8上安裝mysql8內容請搜索WalkonNet以前的文章或繼續瀏覽下面的相關文章希望大傢以後多多支持WalkonNet!

推薦閱讀: