CentOS7下安装mysql-5.7.24
文章目錄
- 一:安裝前期準(zhǔn)備
- 1、檢查是否已經(jīng)安裝過(guò)mysql
- 2、查詢所有mysql對(duì)應(yīng)的文件夾
- 3、下載linux版本的mysql安裝包
- 二:安裝mysql
- 1、解壓文件
- 2、將解壓后的文件重新命名
- 3、在/usr/local/mysql目錄下創(chuàng)建data目錄
- 4、編譯安裝并初始化mysql
- 5、配置文件my.cnf
- 6、啟動(dòng)mysql(這一步先看完再操作少走彎路)
- 7、添加軟連接,并重啟動(dòng)mysql
- 8、登錄mysql
- 9、開(kāi)放遠(yuǎn)程連接
- 10、開(kāi)機(jī)自啟
- 11、外部工具連接mysql
一:安裝前期準(zhǔn)備
1、檢查是否已經(jīng)安裝過(guò)mysql
[root@localhost /]# rpm -qa | grep mysql
如果已經(jīng)安裝的有的化,需要先把之前的刪除了
因?yàn)?#xff0c;我這個(gè)是新裝的虛擬機(jī),因?yàn)槭强盏摹h除之后記得查看。
2、查詢所有mysql對(duì)應(yīng)的文件夾
[root@hadoop-master ~]# whereis mysql mysql: /usr/lib64/mysql /usr/share/mysql [root@hadoop-master ~]# find / -name mysql /etc/selinux/targeted/active/modules/100/mysql /usr/lib64/mysql /usr/share/mysql [root@hadoop-master ~]#刪除上面的目錄或者文件
[root@hadoop-master ~]# rm -rf /usr/lib64/mysql /usr/share/mysql /etc/selinux/targeted/active/modules/100/mysql刪除完了之后再檢查一下看看還有沒(méi)有
[root@hadoop-master ~]# whereis mysql mysql:[root@hadoop-master ~]# find / -name mysql [root@hadoop-master ~]#3、下載linux版本的mysql安裝包
打開(kāi)目錄
[root@hadoop-master local]# cd /usr/local下載安裝包到此目錄
[root@localhost /]# wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.24-linux-glibc2.12-x86_64.tar.gz當(dāng)然也可以去官網(wǎng)下載:https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.24-linux-glibc2.12-x86_64.tar.gz
二:安裝mysql
1、解壓文件
[root@hadoop-master local]# tar xzvf mysql-5.7.24-linux-glibc2.12-x86_64.tar.gz2、將解壓后的文件重新命名
[root@hadoop-master local]# mv mysql-5.7.24-linux-glibc2.12-x86_64 mysql3、在/usr/local/mysql目錄下創(chuàng)建data目錄
[root@hadoop-master local]# mkdir /usr/local/mysql/data4、編譯安裝并初始化mysql
特別注意日志輸出的末尾處是mysql的初始化密碼,一定要記住。
[root@hadoop-master bin]# cd /usr/local/mysql/bin [root@hadoop-master bin]# ./mysqld --initialize --user=root --datadir=/usr/local/mysql/data --basedir=/usr/local/mysql編譯輸出日志:
我這里的mysql的root賬戶初始化密碼就是:_H5X-*gQI_hD
5、配置文件my.cnf
[root@hadoop-master bin]# vi /etc/my.cnf[mysqld] [mysqld] port=3306 datadir=/usr/local/mysql/data socket=/usr/local/mysql/mysql.sock user=mysql max_connections=151 # Disabling symbolic-links is recommended to prevent assorted security risks symbolic-links=0 # 設(shè)置忽略大小寫 lower_case_table_names = 1 # 指定編碼 character-set-server=utf8 collation-server=utf8_general_ci # 開(kāi)啟ip綁定 bind-address = 0.0.0.0 #設(shè)置sql語(yǔ)句的最大長(zhǎng)度為64M max_allowed_packet=64M [mysqld_safe] log-error=/var/log/mysqld.log pid-file=/var/run/mysqld/mysqld.pid #指定客戶端連接mysql時(shí)的socket通信文件路徑 [client] socket=/usr/local/mysql/mysql.sock default-character-set=utf86、啟動(dòng)mysql(這一步先看完再操作少走彎路)
[root@hadoop-master bin]# /usr/local/mysql/support-files/mysql.server start Starting MySQL.2020-08-02T15:58:23.384616Z mysqld_safe error: log-error set to '/var/log/mariadb/mariadb.log', however file don't exists. Create writable for user 'mysql'.ERROR! The server quit without updating PID file (/usr/local/mysql/data/hadoop-master.pid).發(fā)現(xiàn)報(bào)錯(cuò)了,根據(jù)提示我們需要把寫權(quán)限Create writable for user 'mysql'.
創(chuàng)建myslq組和mysql用戶
更改mysql目錄下所有的目錄及文件夾所屬的用戶組和用戶,以及權(quán)限
root@hadoop-master data]# chown -R mysql:mysql /usr/local/mysql [root@hadoop-master data]# chmod -R 755 /usr/local/mysql本人走彎路了,其實(shí)上面創(chuàng)建mysql用戶的步驟可以提前在步驟4之前執(zhí)行,如果遇到下面的異常
[root@hadoop-master local]# cd /usr/local/mysql/bin/ [root@hadoop-master bin]# ./mysqld --initialize --user=mysql --datadir=/usr/local/mysql/data --basedir=/usr/local/mysql 2020-08-02T16:32:14.093255Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details). 2020-08-02T16:32:14.094353Z 0 [ERROR] --initialize specified but the data directory has files in it. Aborting. 2020-08-02T16:32:14.094373Z 0 [ERROR] Aborting可以直接清空/usr/local/mysql/data/ 目錄下的所有內(nèi)容,然后繼續(xù)往下走
[root@hadoop-master mysql]# cd /usr/local/mysql/bin [root@hadoop-master bin]# ./mysqld --initialize --user=mysql --datadir=/usr/local/mysql/data --basedir=/usr/local/mysql 2020-08-02T16:35:03.336722Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details). 2020-08-02T16:35:03.440657Z 0 [Warning] InnoDB: New log files created, LSN=45790 2020-08-02T16:35:03.470791Z 0 [Warning] InnoDB: Creating foreign key constraint system tables. 2020-08-02T16:35:03.528707Z 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: 1dc1c1cb-d4de-11ea-9c65-000c29f03fc4. 2020-08-02T16:35:03.529393Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened. 2020-08-02T16:35:03.530486Z 1 [Note] A temporary password is generated for root@localhost: =4tlBRlrbObB記住這個(gè)初始化密碼:=4tlBRlrbObB
繼續(xù)啟動(dòng)mysql
[root@hadoop-master bin]# /usr/local/mysql/support-files/mysql.server start Starting MySQL. SUCCESS!看到Starting MySQL. SUCCESS代表啟動(dòng)服務(wù)成功了
7、添加軟連接,并重啟動(dòng)mysql
添加軟連接主要是為了更加方便使用mysql命令
[root@hadoop-master bin]# ln -s /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql [root@hadoop-master bin]# ln -s /usr/local/mysql/bin/mysql /usr/bin/mysql [root@hadoop-master bin]# service mysql restart Shutting down MySQL.. SUCCESS! Starting MySQL. SUCCESS!8、登錄mysql
使用的初始密碼就是上面的:=4tlBRlrbObB
[root@hadoop-master bin]# mysql -u root -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 2 Server version: 5.7.24Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.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> set password for root@localhost = password('root'); Query OK, 0 rows affected, 1 warning (0.00 sec)我們這里使用了密碼重置,將數(shù)據(jù)庫(kù)root賬戶密碼重置:
set password for root@localhost = password('root')9、開(kāi)放遠(yuǎn)程連接
如果不開(kāi)放,只能自己機(jī)器127.0.0.1里玩了,外部的連不上的。
mysql>use mysql; msyql>update user set user.Host='%' where user.User='root'; mysql>flush privileges;10、開(kāi)機(jī)自啟
1、將服務(wù)文件拷貝到init.d下,并重命名為mysql [root@localhost /]# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld 2、賦予可執(zhí)行權(quán)限 [root@localhost /]# chmod +x /etc/init.d/mysqld 3、添加服務(wù) [root@localhost /]# chkconfig --add mysqld 4、顯示服務(wù)列表 [root@localhost /]# chkconfig --list顯示結(jié)果:
[root@hadoop-master bin]# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld [root@hadoop-master bin]# chmod +x /etc/init.d/mysqld [root@hadoop-master bin]# chkconfig --add mysqld [root@hadoop-master bin]# chkconfig --list注:該輸出結(jié)果只顯示 SysV 服務(wù),并不包含 原生 systemd 服務(wù)。SysV 配置數(shù)據(jù) 可能被原生 systemd 配置覆蓋。 要列出 systemd 服務(wù),請(qǐng)執(zhí)行 'systemctl list-unit-files'。查看在具體 target 啟用的服務(wù)請(qǐng)執(zhí)行'systemctl list-dependencies [target]'。mysqld 0:關(guān) 1:關(guān) 2:開(kāi) 3:開(kāi) 4:開(kāi) 5:開(kāi) 6:關(guān) netconsole 0:關(guān) 1:關(guān) 2:關(guān) 3:關(guān) 4:關(guān) 5:關(guān) 6:關(guān) network 0:關(guān) 1:關(guān) 2:開(kāi) 3:開(kāi) 4:開(kāi) 5:開(kāi) 6:關(guān)11、外部工具連接mysql
如果不成功,大概率就是防火墻沒(méi)開(kāi)放3306端口,根據(jù)如下指令,將端口添加
如果沒(méi)有iptables命令,使用如下命令安裝即可
[root@hadoop-master bin]# yum install iptables-services至此,安裝結(jié)束了。如果對(duì)你有幫助,請(qǐng)點(diǎn)贊支持下,謝謝。
總結(jié)
以上是生活随笔為你收集整理的CentOS7下安装mysql-5.7.24的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: MYSQL语法:左连接、右连接、内连接、
- 下一篇: CentOS7安装JDK1.8简单体验(