Linux下安裝MySQL 5.7

來源:互聯網
上載者:User

標籤:mysql linux 資料庫

本次分享如何在Linux下安裝MySQL 5.7

作業系統版本:RedHat/CentOS 6.6 X64

MySQL版本:5.7.11

安裝方式:二進位

MySQL:http://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.11-linux-glibc2.5-x86_64.tar.gz


安裝過程:

[[email protected] ~]# mkdir /data/dbwyzc -p

1、建立MySQL安裝目錄


2、建立一個不允許登入的MySQL使用者及組

[[email protected] ~]# groupadd mysql

[[email protected] ~]# useradd -g mysql -s /sbin/nologin -d /data/mysql mysql

Creating mailbox file: File exists

[[email protected] ~]# id mysql

uid=500(mysql) gid=500(mysql) groups=500(mysql)


3、解壓下載下來的MySQL安裝包

[[email protected] ~]# mv /root/Desktop/mysql-5.7.11-linux-glibc2.5-x86_64.tar.gz /data/mysql/

[[email protected] ~]# cd /data/mysql/

[[email protected] mysql]# tar xf mysql-5.7.11-linux-glibc2.5-x86_64.tar.gz 

[[email protected] mysql]# ls

mysql-5.7.11-linux-glibc2.5-x86_64  mysql-5.7.11-linux-glibc2.5-x86_64.tar.gz

做個軟串連到/usr/local/mysql

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

[[email protected] local]# ln -s /data/mysql/mysql-5.7.11-linux-glibc2.5-x86_64 mysql

[[email protected] local]# ls -l mysql

lrwxrwxrwx. 1 root root 46 Mar 24 02:43 mysql -> /data/mysql/mysql-5.7.11-linux-glibc2.5-x86_64


4、建立datadir及日誌儲存路徑

[[email protected] local]# cd /data/dbwyzc/

[[email protected] dbwyzc]# ls

[[email protected] dbwyzc]# mkdir {data,logs}


5、授權

[[email protected] dbwyzc]# chown -R mysql.mysql /data/dbwyzc/

[[email protected] dbwyzc]# chown -R mysql.mysql /usr/local/mysql/


6、因為是選擇從MySQL壓縮包中初始化MySQL,不是直接安裝MySQL,需手動解決找不到mysql命令的問題

[[email protected] dbwyzc]# echo ‘export PATH=$PATH:/usr/local/mysql/bin‘ >> /etc/profile

[[email protected] dbwyzc]# source !$

source /etc/profile


7、關閉防火牆及selinux

[[email protected] dbwyzc]# chkconfig iptables off

[[email protected] dbwyzc]# vi /etc/sysconfig/selinux 

SELINUX=disabled


8、修改my.cnf

[[email protected] dbwyzc]# vi /etc/my.cnf 

[client]

port=3306

socket=/tmp/mysql.sock


[mysqld]

user=mysql

basedir=/usr/local/mysql

datadir=/data/dbwyzc/data

socket=/tmp/mysql.sock

log-error=/data/dbwyzc/logs/mysqld.log

pid-file=/data/dbwyzc/mysqld.pid


9、初始化MySQL

在5.7中,推薦使用mysqld --initialize對資料庫進行初始化(mysql_install_db已經不再推薦使用),在初始化時如果加上--initialize-insecure,則會建立空密碼的 [email protected] 帳號,否則會建立帶密碼的 [email protected] 帳號,密碼直接寫在 log-error 記錄檔中

[[email protected] mysql]# cd bin/

[[email protected] bin]# mysqld --defaults-file=/etc/my.cnf --user=mysql --initialize --initialize-insecure

[[email protected] bin]# ls /data/dbwyzc/data/

auto.cnf        ibdata1      ib_logfile1  performance_schema

ib_buffer_pool  ib_logfile0  mysql        sys

[[email protected] bin]# ls /data/dbwyzc/logs/

mysqld.log

[[email protected] bin]# cat /data/dbwyzc/logs/mysqld.log 

2016-03-23T20:45:41.774933Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).

2016-03-23T20:45:43.665168Z 0 [Warning] InnoDB: New log files created, LSN=45790

2016-03-23T20:45:43.939168Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.

2016-03-23T20:45:44.025867Z 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: 368bbcd5-f138-11e5-aad0-000c29f650ca.

2016-03-23T20:45:44.029664Z 0 [Warning] Gtid table is not ready to be used. Table ‘mysql.gtid_executed‘ cannot be opened.

2016-03-23T20:45:44.031662Z 1 [Warning] [email protected] is created with an empty password ! Please consider switching off the --initialize-insecure option.


10、添加使用service快速啟動MySQL

[[email protected] bin]# cd ../

[[email protected] mysql]# ls support-files/

magic  my-default.cnf  mysqld_multi.server  mysql-log-rotate  mysql.server

[[email protected] mysql]# cp support-files/mysql.server /etc/init.d/mysql

[[email protected] mysql]# service mysql start

Starting MySQL.                                            [  OK  ]


之後給root使用者佈建個密碼:

[[email protected] mysql]# mysql


mysql> set password=password(‘mysql123‘);


不要被上面繁瑣的操作步驟所迷惑,這種方法是我們搭建測試環境及MySQL多執行個體環境用到的最多的一種安裝方法,其操作對於熟練掌握Linux簡單命令的人來說已經非常簡單了,最重要的是,使用二進位的安裝方法,可以讓我們在安裝MySQL的過程中瞭解到MySQL各檔案的位置、作用、MySQL初始化的時候都做了哪些工作等。


更多精彩MySQL內容 請關注我哦!

650) this.width=650;" src="http://qr.liantu.com/api.php?bg=ffffff&fg=000000&gc=000000&el=L&text=http%3A%2F%2Fwap.wyzc.com%2Freg%2F%3Ftg%3D3006123630" style="border:none;" />


Linux下安裝MySQL 5.7

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.