1. 程式人生 > >MySQL 5.7.19 CentOS 7 安裝

MySQL 5.7.19 CentOS 7 安裝

sed mysql variable 若有 views copy 文件 inux 現在

Linux的版本有很多,因此下載mysql時,需要註意下載對應Linux版本的MySql數據庫文件。以下方法也適合centOS 7 的mysql 5.7.* 版本的安裝。安裝方法我整理為16步。

1:下載centOS7對應的MySQL版本(通用版的Generic)

[[email protected] soft]# wget https://cdn.mysql.com//Downloads/MySQL-5.7/mysql-5.7.19-linux-glibc2.12-x86_64.tar.gz

百度雲分享下載:http://pan.baidu.com/s/1eSiXD6M

2:在/usr/local/下新建mysql目錄

[[email protected] local]# touch /usr/local/mysql

3:解壓文件到mysql目錄下

[[email protected] soft]# tar -xvf mysql-5.7.19-linux-glibc2.12-x86_64.tar.gz-C /usr/local/mysql

4:檢查庫文件是否有刪除,若有便刪除(Linux系統自帶的)

[[email protected] mysql]# rpm -qa | grep mysql

刪除

[[email protected] mysql]# rm -e –-nodeps mysql-libs-5.1.52.x86_64

(我遇到查詢不到庫文件但卻仍可以刪除的情況)

5:檢查mysql組和用戶是否存在,如無創建

[[email protected] ~]# cat /etc/group | grep mysql

mysql:x:490:

[[email protected] ~]# cat /etc/passwd |grep mysql

mysql:x:496:490::/home/mysql:/bin/bash

以上為默認存在的情況,如無,執行添加命令:

[[email protected] ~]#groupadd mysql

[[email protected] ~]#useradd -r -g mysql mysql

//useradd -r參數表示mysql用戶是系統用戶,不可用於登錄系統

6:在mysql下添加data目錄

[[email protected] mysql]# mkdir data

7:更改mysql目錄下所有的目錄及文件夾所屬組合用戶

[[email protected] ~]# cd /usr/local/

[[email protected] local]# chown -R mysql mysql/

[[email protected] local]# chgrp -R mysql mysql/

[[email protected] local]# cd mysql/

[[email protected] local]# ls -l

(修改成功後可看到原組和用戶root修改成了mysql)

8:安裝和初始化數據庫

(1)

[[email protected] mysql]# bin/mysql_install_db --user=mysql -- basedir=/usr/local/mysql/--datadir=/data/mysql/

(2)

接下來進入/usr/local/mysql/support-files/目錄下

查看是否存在my-default.cnf文件,如果存在直接copy到/etc/my.cnf文件中

[[email protected] mysql]# cp -a ./support-files/my-default.cnf/etc/my.cnf

如果不存在my-default.cnf文件

則在/etc/目錄下創建my.cnf

// 在文件中寫入

[html] view plain copy
  1. #[mysql]
  2. #basedir=/usr/local/mysql/
  3. #datadir=/data/mysql/

(3)

[[email protected] mysql]# cd bin/

[[email protected] bin]# ./mysqld_safe --user=mysql &

9:啟動mysql

[[email protected] bin]# service mysql start或者 [[email protected] bin]# systemctl start mysqld.service

[[email protected] bin]# /etc/init.d/mysqld restart

10:設置開機自啟動

[[email protected] bin]# chkconfig --level 35 mysqld on

11:登錄mysql

[[email protected] bin]# ./mysql -u root -p

Enter password:

(此處密碼看第12步)

12:查看系統自動生成的密碼

[[email protected] bin]# cat /root/.mysql_secret

# Password set for user ‘[email protected]‘ at 2017-08-13 16:54:06

0#n)?iduvHOt

13:修改mysql密碼

mysql> set password=password(‘root’)

14:遠程登錄權限

mysql> grant all privileges on *.* to‘root‘ @‘%‘ identified by ‘root‘;

mysql> flush privileges;

mysql> quit

15:開啟3306端口

[[email protected] ~]# firewall-cmd --permanent --zone=public --add-port=3306/tcp

[[email protected] ~]# firewall-cmd --reload

[[email protected] ~]# firewall-cmd --query-port=3306/tcp

16:修改mysql無訪問關閉mysql時間(默認8小時)[此步驟無需求可忽略]

查詢

mysql> show global variables like ‘wait_timeout‘;

修改

mysql> set global wait_timeout=388000;

End 現在即可遠程登錄了技術分享

MySQL 5.7.19 CentOS 7 安裝