一、到mysql官網下載安裝包
下載地址:https://dev.mysql.com/downloads/mysql/5.6.html#downloadshtml
選擇如下截圖中的版本java
二、下載後上傳到linux中
三、安裝
卸載系統自帶的mariadb
[root@localhost soft]# rpm -qa | grep mariadb mariadb-libs-5.5.56-2.el7.x86_64 [root@localhost soft]# [root@localhost soft]# [root@localhost soft]# rpm -e --nodeps mariadb-libs-5.5.56-2.el7.x86_64
刪除/etc目錄下的my.cnf
[root@localhost soft]# rm /etc/my.cnf rm: 沒法刪除"/etc/my.cnf": 沒有那個文件或目錄 [root@localhost soft]#
有可能自己就不存在這個文件。node
建立mysql用戶組
[root@localhost soft]# groupadd mysql
建立一個用戶名爲mysql的用戶並加入mysql用戶組
[root@localhost soft]# useradd -g mysql mysql
解壓安裝包到/usr/local/目錄下
tar -xvf mysql-5.6.43-linux-glibc2.12-x86_64.tar.gz -C /usr/local/
切換到/usr/local目錄下,並查看
[root@localhost soft]# cd /usr/local/ [root@localhost local]# ls bin etc games include java lib lib64 libexec mysql-5.6.43-linux-glibc2.12-x86_64 redis sbin share src [root@localhost local]# [root@localhost local]#
將解壓好的文件夾重命名爲mysql
[root@localhost local]# mv mysql-5.6.43-linux-glibc2.12-x86_64/ mysql [root@localhost local]# ls bin etc games include java lib lib64 libexec mysql redis sbin share src [root@localhost local]#
copy一份/usr/local/mysql/support-files/下的my-default.cnf文件到/etc下
cp /usr/local/mysql/support-files/my-default.cnf /etc/my.cnf
配置/etc目錄下的my.cnf文件
經過vi編輯器,編輯my.cnf的代碼以下mysql
[mysql] # 設置mysql客戶端默認字符集 default-character-set=utf8 [mysqld] skip-name-resolve #設置3306端口 port = 3306 # 設置mysql的安裝目錄 basedir=/usr/local/mysql # 設置mysql數據庫的數據的存放目錄 datadir=/usr/local/mysql/data # 容許最大鏈接數 max_connections=200 # 服務端使用的字符集默認爲8比特編碼的latin1字符集 character-set-server=utf8 # 建立新表時將使用的默認存儲引擎 default-storage-engine=INNODB lower_case_table_name=1 max_allowed_packet=16M
進入安裝mysql軟件目錄,並執行如下命令
[root@localhost mysql]# cd /usr/local/mysql/ [root@localhost mysql]# chown -R mysql:mysql ./ [root@localhost mysql]# ./scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data/ -bash: ./scripts/mysql_install_db: /usr/bin/perl: 壞的解釋器: 沒有那個文件或目錄 [root@localhost mysql]# [root@localhost mysql]#
若是報上面的錯誤,那麼須要安裝perl
yum install perl
安裝完成後,再次執行./scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data/
[root@localhost mysql]# ./scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data/ FATAL ERROR: please install the following Perl modules before executing ./scripts/mysql_install_db: Data::Dumper [root@localhost mysql]# [root@localhost mysql]#
若是報上面的錯誤,那麼須要安裝autoconf
yum install autoconf
安裝完成後,再次執行上面的那個命令。
安裝完成後,修改當前data目錄的擁有者爲mysql用戶
[root@localhost mysql]# chown -R mysql:mysql data
到此數據庫安裝完畢!
四、配置
授予my.cnf權限
chmod 644 /etc/my.cnf
設置開機自啓動服務控制腳本
複製啓動腳本到資源目錄
[root@localhost mysql]# cp ./support-files/mysql.server /etc/rc.d/init.d/mysqld
增長mysqld服務控制腳本執行權限
chmod +x /etc/rc.d/init.d/mysqld
將mysqld服務加入到系統服務
chkconfig --add mysqld
檢查mysqld服務是否已經生效
chkconfig --list mysqld
結果相似以下linux
[root@localhost mysql]# chkconfig --list mysqld 注:該輸出結果只顯示 SysV 服務,並不包含 原生 systemd 服務。SysV 配置數據 可能被原生 systemd 配置覆蓋。 要列出 systemd 服務,請執行 'systemctl list-unit-files'。 查看在具體 target 啓用的服務請執行 'systemctl list-dependencies [target]'。 mysqld 0:關 1:關 2:開 3:開 4:開 5:開 6:關 [root@localhost mysql]#
代表mysqld服務已經生效,在二、三、四、5運行級別隨系統啓動而自動啓動,之後可使用service命令控制mysql的啓動和中止redis
命令爲:service mysqld start和service mysqld stop
啓動mysqld
[root@localhost mysql]# service mysqld start Warning: World-writable config file '/etc/my.cnf' is ignored Starting MySQL.Warning: World-writable config file '/etc/my.cnf' is ignored Warning: World-writable config file '/etc/my.cnf' is ignored Logging to '/usr/local/mysql/data/localhost.localdomain.err'. . SUCCESS! [root@localhost mysql]#
將mysql的bin目錄加入PATH環境變量,編輯 ~/.bash_profile文件
在文件最後添加以下信息:sql
export PATH=$PATH:/usr/local/mysql/bin
保存並退出。數據庫
使修改的內容當即生效
source ~/.bash_profile
以root帳戶登陸mysql,默認是沒有密碼的
[root@localhost mysql]# mysql -uroot -p Warning: World-writable config file '/etc/my.cnf' is ignored Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 1 Server version: 5.6.43 MySQL Community Server (GPL) Copyright (c) 2000, 2019, 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>
要求輸入密碼的時候,直接回車。bash
設置root帳戶的密碼
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 password=password('root') where user='root' and host='localhost'; 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>
設置遠程主機登陸
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'root' WITH GRANT OPTION; Query OK, 0 rows affected (0.00 sec) mysql>
開啓3306端口
[root@localhost mysql]# systemctl start firewalld [root@localhost mysql]# firewall-cmd --zone=public --add-port=3306/tcp --permanent success [root@localhost mysql]# firewall-cmd --reload success
到此爲止,在Centos 7上安裝mysql5.6就完成了。dom