一、環境準備
1.1 操作系統版本
1
2
|
[root@rhel76 ~]# cat /etc/redhat-release red hat enterprise linux server release 7.6 (maipo) |
1.2 磁盤空間
1
2
3
4
5
6
7
8
9
10
11
|
[root@rhel76 ~]# df -th filesystem type size used avail use% mounted on /dev/mapper/rhel-root xfs 32g 4.6g 27g 15% / devtmpfs devtmpfs 2.1g 0 2.1g 0% /dev tmpfs tmpfs 2.1g 0 2.1g 0% /dev/shm tmpfs tmpfs 2.1g 14m 2.1g 1% /run tmpfs tmpfs 2.1g 0 2.1g 0% /sys/fs/cgroup /dev/sda1 xfs 996m 172m 825m 18% /boot /dev/mapper/rhel-u01 xfs 30g 34m 30g 1% /u01 tmpfs tmpfs 413m 4.1k 413m 1% /run/ user /42 tmpfs tmpfs 413m 46k 413m 1% /run/ user /0 |
1.3 關閉防火墻
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
|
[root@rhel76 ~]# systemctl status firewalld ● firewalld.service - firewalld - dynamic firewall daemon loaded: loaded (/usr/lib/systemd/system/firewalld.service; enabled; vendor preset: enabled) active: active (running) since tue 2021-11-23 23:46:04 utc; 9min ago docs: man:firewalld(1) main pid: 9621 (firewalld) tasks: 2 cgroup: /system.slice/firewalld.service └─9621 /usr/bin/python -es /usr/sbin/firewalld --nofork --nopid nov 23 23:46:03 rhel76 systemd[1]: starting firewalld - dynamic firewall daemon... nov 23 23:46:04 rhel76 systemd[1]: started firewalld - dynamic firewall daemon. [root@rhel76 ~]# systemctl stop firewalld [root@rhel76 ~]# systemctl disable firewalld removed symlink /etc/systemd/system/multi- user .target.wants/firewalld.service. removed symlink /etc/systemd/system/dbus-org.fedoraproject.firewalld1.service. |
1.4 關閉 selinux
1
2
3
4
5
6
7
8
9
10
11
12
13
|
[root@rhel76 ~]# getenforce enforcing [root@rhel76 ~]# cp /etc/selinux/config /etc/selinux/config_` date + "%y%m%d_%h%m%s" ` [root@rhel76 ~]# sed -i 's/selinux\=enforcing/selinux\=disabled/g' /etc/selinux/config 以上修改完后重啟 [root@rhel76 ~]# reboot [root@rhel76 ~]# getenforce disabled [root@rhel76 ~]# sestatus selinux status: disabled |
1.5 host解析
1
2
3
4
5
6
7
8
|
[root@rhel76 ~]# cat /etc/hosts 127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 ::1 localhost localhost.localdomain localhost6 localhost6.localdomain6 192.168.6.81 rhel76 [root@rhel76 ~]# hostname rhel76 |
1.6 mysql下載
1
2
|
https://dev.mysql.com/downloads/mysql/ md5: 0bdd171cb8464ba32f65f7bf58bc9533 |
二、 yum安裝及配置
2.1 掛載本地光盤鏡像
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
|
[root@rhel76 ~]# mkdir -p /mnt/dvd/ [root@rhel76 ~]# df -th filesystem type size used avail use% mounted on /dev/mapper/rhel-root xfs 32g 4.7g 27g 15% / devtmpfs devtmpfs 2.1g 0 2.1g 0% /dev tmpfs tmpfs 2.1g 0 2.1g 0% /dev/shm tmpfs tmpfs 2.1g 14m 2.1g 1% /run tmpfs tmpfs 2.1g 0 2.1g 0% /sys/fs/cgroup /dev/sda1 xfs 996m 172m 825m 18% /boot /dev/mapper/rhel-u01 xfs 30g 34m 30g 1% /u01 tmpfs tmpfs 413m 21k 413m 1% /run/ user /0 tmpfs tmpfs 413m 13k 413m 1% /run/ user /42 /dev/sr0 iso9660 4.5g 4.5g 0 100% /run/media/root/rhel-7.6 server.x86_64 [root@rhel76 ~]# mount /dev/sr0 /mnt/dvd mount: /dev/sr0 is write-protected, mounting read - only you have mail in /var/spool/mail/root |
2.2 配置yum源
1
2
3
4
5
6
7
|
[root@rhel76 ~]# cd /etc/yum.repos.d/ [root@rhel76 yum.repos.d]# cat >> /etc/yum.repos.d/redhat.repo << "eof" > [rhel7] > name =jeames repo > baseurl=file:///mnt/dvd/ > gpgcheck=0 > eof |
2.3 安裝依賴包
1
2
3
4
5
6
7
8
9
10
11
|
[root@rhel76 ~]# yum -y groupinstall "development tools" loaded plugins: fastestmirror, product-id, search-disabled-repos, subscription-manager this system is not registered with an entitlement server. you can use subscription-manager to register. there is no installed groups file. maybe run: yum groups mark convert (see man yum) loading mirror speeds from cached hostfile warning: group development does not have any packages to install. maybe run: yum groups mark install (see man yum) no packages in any requested group available to install or update [root@rhel76 ~]# yum -y install ncurses ncurses-devel openssl-devel bison gcc gcc-c++ make |
三、卸載mariadb
1
2
3
4
|
[root@rhel76 ~]# rpm -qa |grep mariadb mariadb-libs-5.5.60-1.el7_5.x86_64 [root@rhel76 ~]# rpm -e --nodeps mariadb-libs-5.5.60-1.el7_5.x86_64 |
四、安裝 mysql
4.1 用戶及目錄創建
1
|
注:可以部署多個實例,通過端口區分root 用戶操作:mkdir -p /mysql/data/mysql3306mkdir -p /mysql/app/mkdir -p /mysql/conf/mkdir -p /mysql/data/mysql3306/pid/mkdir -p /mysql/data/mysql3306/socket/mkdir -p /mysql/data/mysql3306/log/mkdir -p /mysql/data/mysql3306/binlog/mkdir -p /mysql/data/mysql3306/errlogmkdir -p /mysql/data/mysql3306/relaylog/mkdir -p /mysql/data/mysql3306/slowlog/mkdir -p /mysql/data/mysql3306/tmp/ |
4.2 用戶及組
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
[root@rhel76 ~]# groupadd mysql [root@rhel76 ~]# useradd -g mysql mysql [root@rhel76 ~]# chown -r mysql:mysql /mysql [root@rhel76 ~]# passwd mysql changing password for user mysql. new password : bad password : the password is shorter than 8 characters retype new password : passwd: all authentication tokens updated successfully. [root@rhel76 ~]# cat /etc/ group | grep mysql mysql:x:1001: [root@rhel76 ~]# cat /etc/passwd | grep mysql mysql:x:1001:1001::/home/mysql:/bin/bash |
4.3 上傳軟件包并解壓
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
[root@rhel76 ~]# cp mysql-8.0.27-linux-glibc2.12-x86_64.tar.xz /mysql/app [root@rhel76 ~]# chown -r mysql:mysql /mysql mysql用戶操作 [root@rhel76 ~]# su - mysql md5 值驗證,保證下載到的軟件包無破損無木馬 [mysql@rhel76 ~]$ cd /mysql/app [mysql@rhel76 app]$ ll total 1168588 -rw-r --r-- 1 mysql mysql 1196633756 nov 24 00:49 mysql-8.0.27-linux-glibc2.12-x86_64.tar.xz [mysql@rhel76 app]$ md5sum mysql-8.0.27-linux-glibc2.12-x86_64.tar.xz 0bdd171cb8464ba32f65f7bf58bc9533 mysql-8.0.27-linux-glibc2.12-x86_64.tar.xz 解壓軟件包并重命名 [mysql@rhel76 app]$ tar xvf mysql-8.0.27-linux-glibc2.12-x86_64.tar.xz [mysql@rhel76 app]$ mv mysql-8.0.27-linux-glibc2.12-x86_64 mysql8.0.27 [mysql@rhel76 app]$ ll total 1168588 drwxrwxr-x 9 mysql mysql 129 nov 24 00:54 mysql8.0.27 -rw-r --r-- 1 mysql mysql 1196633756 nov 24 00:49 mysql-8.0.27-linux-glibc2.12-x86_64.tar.xz |
五.環境變量配置
1
2
3
4
5
6
7
8
|
cat >> /home/mysql/.bash_profile << "eof" mysql_home=/mysql/app/mysql8.0.27 path=$path:$home/. local /bin:$home/bin:$mysql_home/bin eof source ~/.bash_profile which mysql |
六.創建參數文件
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
由于是二進制文件安裝,數據庫參數文件需要自己配置 cat >> /mysql/conf/my3306.cnf << "eof" [mysqld] server_id = 80273306 default -storage-engine= innodb basedir=/mysql/app/mysql8.0.27 datadir=/mysql/data/mysql3306/data/ socket=/mysql/data/mysql3306/socket/mysql.sock log-error=/mysql/data/mysql3306/log/mysqld.log pid-file=/mysql/data/mysql3306/pid/mysqld.pid port=3306 default -time_zone= '+8:00' default_authentication_plugin=mysql_native_password # 加此參數可遠程登陸 transaction_isolation= read - committed max_connections=1500 back_log=500 wait_timeout=1800 max_user_connections=800 innodb_buffer_pool_size=1024m innodb_log_file_size=512m innodb_log_buffer_size=40m slow_query_log= on long_query_time=5 # log settings # slow_query_log = on slow_query_log_file = /mysql/data/mysql3306/slowlog/slow3306.log log_error = /mysql/data/mysql3306/errlog/err3306.log log_error_verbosity = 3 log_bin = /mysql/data/mysql3306/binlog/mysql_bin log_bin_index = /mysql/data/mysql3306/binlog/mysql_binlog. index general_log_file = /data/mysql/mysql3306/generallog/general.log log_queries_not_using_indexes = 1 log_slow_admin_statements = 1 expire_logs_days = 90 binlog_expire_logs_seconds = 2592000 #30d long_query_time = 2 min_examined_row_limit = 100 log_throttle_queries_not_using_indexes = 1000 innodb_flush_log_at_trx_commit=1 eof |
七.數據庫初始化
1
2
3
|
mysql用戶操作: mysqld --defaults-file=/mysql/conf/my3306.cnf --initialize --user=mysql --basedir=/mysql/app/mysql8.0.27 --datadir=/mysql/data/mysql3306/data/ 注意:以上同一行執行 |
八.啟動mysql
1
2
3
4
|
[mysql@rhel76 ~]$ mysqld_safe --defaults-file=/mysql/conf/my3306.cnf --user=mysql & [1] 21406 [mysql@rhel76 ~]$ 2021-11-24t06:14:23.240372z mysqld_safe logging to '/mysql/data/mysql3306/errlog/err3306.log' . 2021-11-24t06:14:23.296992z mysqld_safe starting mysqld daemon with databases from /mysql/data/mysql3306/data |
九.登陸mysql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
第一次登錄 mysql 時,需要到錯誤日志下找初始化密碼,我這里的密碼為:-(qy5aj9t,=a 使用 socket 加密碼登錄進去后,無法查詢任何東西,提示先要修改 root 密碼。 [mysql@rhel76 ~]$ cat /mysql/data/mysql3306/errlog/err3306.log | grep password 2021-11-24t06:12:14.610657z 0 [note] [my-010309] [server] auto generated rsa key files through --sha256_password_auto_generate_rsa_keys are placed in data directory. 2021-11-24t06:12:14.610686z 0 [note] [my-010308] [server] skipping generation of rsa key pair through --caching_sha2_password_auto_generate_rsa_keys as key files are present in data directory. 2021-11-24t06:12:14.615367z 6 [note] [my-010454] [server] a temporary password is generated for root@localhost: -(qy5aj9t,=a 2021-11-24t06:14:26.153958z 0 [note] [my-010308] [server] skipping generation of rsa key pair through --sha256_password_auto_generate_rsa_keys as key files are present in data directory. 2021-11-24t06:14:26.153979z 0 [note] [my-010308] [server] skipping generation of rsa key pair through --caching_sha2_password_auto_generate_rsa_keys as key files are present in data directory. [mysql@rhel76 ~]$ mysql -uroot -p enter password : error 2002 (hy000): can 't connect to local mysql server through socket ' /tmp/mysql.sock ' (2) ##此處通過sock登陸 [mysql@rhel76 ~]$ mysql -uroot -p -p 3306 -s /mysql/data/mysql3306/socket/mysql.sock enter password: welcome to the mysql monitor. commands end with ; or \g. your mysql connection id is 8 server version: 8.0.27 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> status error 1820 (hy000): you must reset your password using alter user statement before executing this statement. |
十.修改密碼
1
|
mysql> alter user root@ 'localhost' identified by 'root' ;query ok, 0 rows affected (0.01 sec)mysql> status --------------mysql ver 8.0.27 for linux on x86_64 (mysql community server - gpl)connection id: 8current database:current user: root@localhostssl: not in usecurrent pager: stdoutusing outfile: ''using delimiter: ;server version: 8.0.27protocol version: 10connection: localhost via unix socketserver characterset: utf8mb4db characterset: utf8mb4client characterset: utf8mb4conn. characterset: utf8mb4unix socket: /mysql/data/mysql3306/socket/mysql.sockbinary data as: hexadecimaluptime: 8 min 0 secthreads: 2 questions: 7 slow queries: 0 opens: 398 flush tables: 3 open tables: 36 queries per second avg: 0.014-------------- |
十一.遠程登陸設置
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
使用如下語句創建 root 用戶是無法通過 navicat 等客戶端登錄的, 由于從 mysql8 開始,身份驗證插件發生改變, 默認的 “caching_sha2_password” 不允許遠程登錄, 故需將此插件修改為 “mysql_native_password” 便可登錄。 mysql> create user root@ '%' identified with mysql_native_password by 'root' ; mysql> grant all on *.* to root@ '%' with grant option ; mysql> flush privileges ; mysql> select user ,host,plugin from mysql. user ; + ------------------+-----------+-----------------------+ | user | host | plugin | + ------------------+-----------+-----------------------+ | root | % | mysql_native_password | | mysql.infoschema | localhost | caching_sha2_password | | mysql.session | localhost | caching_sha2_password | | mysql.sys | localhost | caching_sha2_password | | root | localhost | mysql_native_password | + ------------------+-----------+-----------------------+ 5 rows in set (0.00 sec) |
到此這篇關于linux7.6二進制安裝mysql8.0.27詳細操作步驟的文章就介紹到這了,更多相關linux7.6二進制安裝mysql8.0.27內容請搜索服務器之家以前的文章或繼續瀏覽下面的相關文章希望大家以后多多支持服務器之家!
原文鏈接:https://blog.csdn.net/weixin_41645135/article/details/121526797