CentOS7下安装mysql-5.7.24
文章目錄
- 一:安裝前期準備
- 1、檢查是否已經安裝過mysql
- 2、查詢所有mysql對應的文件夾
- 3、下載linux版本的mysql安裝包
- 二:安裝mysql
- 1、解壓文件
- 2、將解壓后的文件重新命名
- 3、在/usr/local/mysql目錄下創建data目錄
- 4、編譯安裝并初始化mysql
- 5、配置文件my.cnf
- 6、啟動mysql(這一步先看完再操作少走彎路)
- 7、添加軟連接,并重啟動mysql
- 8、登錄mysql
- 9、開放遠程連接
- 10、開機自啟
- 11、外部工具連接mysql
一:安裝前期準備
1、檢查是否已經安裝過mysql
[root@localhost /]# rpm -qa | grep mysql
如果已經安裝的有的化,需要先把之前的刪除了
因為,我這個是新裝的虛擬機,因為是空的。刪除之后記得查看。
2、查詢所有mysql對應的文件夾
[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刪除完了之后再檢查一下看看還有沒有
[root@hadoop-master ~]# whereis mysql mysql:[root@hadoop-master ~]# find / -name mysql [root@hadoop-master ~]#3、下載linux版本的mysql安裝包
打開目錄
[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當然也可以去官網下載: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目錄下創建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 # 設置忽略大小寫 lower_case_table_names = 1 # 指定編碼 character-set-server=utf8 collation-server=utf8_general_ci # 開啟ip綁定 bind-address = 0.0.0.0 #設置sql語句的最大長度為64M max_allowed_packet=64M [mysqld_safe] log-error=/var/log/mysqld.log pid-file=/var/run/mysqld/mysqld.pid #指定客戶端連接mysql時的socket通信文件路徑 [client] socket=/usr/local/mysql/mysql.sock default-character-set=utf86、啟動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).發現報錯了,根據提示我們需要把寫權限Create writable for user 'mysql'.
創建myslq組和mysql用戶
更改mysql目錄下所有的目錄及文件夾所屬的用戶組和用戶,以及權限
root@hadoop-master data]# chown -R mysql:mysql /usr/local/mysql [root@hadoop-master data]# chmod -R 755 /usr/local/mysql本人走彎路了,其實上面創建mysql用戶的步驟可以提前在步驟4之前執行,如果遇到下面的異常
[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/ 目錄下的所有內容,然后繼續往下走
[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記住這個初始化密碼:=4tlBRlrbObB
繼續啟動mysql
[root@hadoop-master bin]# /usr/local/mysql/support-files/mysql.server start Starting MySQL. SUCCESS!看到Starting MySQL. SUCCESS代表啟動服務成功了
7、添加軟連接,并重啟動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)我們這里使用了密碼重置,將數據庫root賬戶密碼重置:
set password for root@localhost = password('root')9、開放遠程連接
如果不開放,只能自己機器127.0.0.1里玩了,外部的連不上的。
mysql>use mysql; msyql>update user set user.Host='%' where user.User='root'; mysql>flush privileges;10、開機自啟
1、將服務文件拷貝到init.d下,并重命名為mysql [root@localhost /]# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld 2、賦予可執行權限 [root@localhost /]# chmod +x /etc/init.d/mysqld 3、添加服務 [root@localhost /]# chkconfig --add mysqld 4、顯示服務列表 [root@localhost /]# chkconfig --list顯示結果:
[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注:該輸出結果只顯示 SysV 服務,并不包含 原生 systemd 服務。SysV 配置數據 可能被原生 systemd 配置覆蓋。 要列出 systemd 服務,請執行 'systemctl list-unit-files'。查看在具體 target 啟用的服務請執行'systemctl list-dependencies [target]'。mysqld 0:關 1:關 2:開 3:開 4:開 5:開 6:關 netconsole 0:關 1:關 2:關 3:關 4:關 5:關 6:關 network 0:關 1:關 2:開 3:開 4:開 5:開 6:關11、外部工具連接mysql
如果不成功,大概率就是防火墻沒開放3306端口,根據如下指令,將端口添加
如果沒有iptables命令,使用如下命令安裝即可
[root@hadoop-master bin]# yum install iptables-services至此,安裝結束了。如果對你有幫助,請點贊支持下,謝謝。
總結
以上是生活随笔為你收集整理的CentOS7下安装mysql-5.7.24的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: MYSQL语法:左连接、右连接、内连接、
- 下一篇: Mysql:AVG()函数如何去除0值做