安裝路徑:/application/mysql-5.7.18
1.前期準備
mysql依賴
| libaioyum install -y libaio |
創建用戶mysql,以該用戶的身份執行mysql
| useradd -s /bin/false -M mysql |
下載mysql二進制包并解壓
| cd /toolswget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.18-linux-glibc2.5-x86_64.tar.gztar -zxf mysql-5.7.18-linux-glibc2.5-x86_64.tar.gz -C /application/ |
切換到/application目錄,將mysql文件夾名改短,給mysql目錄做一個軟鏈接
| cd /application/mv mysql-5.7.18-linux-glibc2.5-x86_64/ mysql-5.7.18ln -s mysql-5.7.18/ mysql |
在mysql目錄下創建mysql-files,該文件夾權限為750,遞歸設置mysql目錄的所屬組和所屬用戶
| mkdir mysql/mysql-fileschmod 750 mysql/mysql-fileschown -R mysql:mysql mysql-5.7.18/ |
2.mysql目錄內操作
| cd mysql |
初始化數據庫
會在mysql目錄內生成一個data目錄,存放數據庫的目錄
| bin/mysqld --initialize --user=mysql --basedir=/application/mysql --datadir=/application/mysql/data |
返回結果最后一行的末尾有隨機密碼,我的記下來:wa0I:1w?V--a
| 2017-04-28T02:49:00.853710Z 1 [Note] A temporary password is generated for root@localhost: wa0I:1w?V--a |
想設置默認密碼為空則將--initialize選項替換為--initialize-insecure選項
| bin/mysqld --initialize-insecure --user=mysql --basedir=/application/mysql --datadir=/application/mysql/data |
安裝ssl
| bin/mysql_ssl_rsa_setup --datadir /application/mysql/data/ |
指定data目錄的路徑
更改所屬用戶和組
| chown -R root .chown -R mysql data mysql-files |
除了mysql目錄下的data目錄和mysql-files目錄所屬用戶不變,其他所有文件的所屬用戶改為root
修改配置文件
| sed -i 's/^datadir=//var//lib//mysql/datadir=//application//mysql//data/g' /etc/my.cnfsed -i 's/^socket=//var//lib//mysql//mysql.sock/socket=//tmp//mysql.sock/g' /etc/my.cnfsed -i 's/^log-error=//var//log//mariadb//mariadb.log/log-error=//application//mysql//data//err.log/g' /etc/my.cnfsed -i 's/^pid-file=//var//run//mariadb//mariadb.pid/pid-file=//application//mysql//data//mysql.pid/g' /etc/my.cnf |
等價于:
| vi /etc/my.cnfdatadir=/application/mysql/datasocket=/tmp/mysql.socklog-error=/application/mysql/data/err.logpid-file=/application/mysql/data/mysql.pid/etc/my.cnf Content:[mysqld]datadir=/application/mysql/datasocket=/tmp/mysql.sock# Disabling symbolic-links is recommended to prevent assorted security riskssymbolic-links=0# Settings user and group are ignored when systemd is used.# If you need to run mysqld under a different user or group,# customize your systemd unit file for mariadb according to the# instructions in http://fedoraproject.org/wiki/Systemd[mysqld_safe]log-error=/application/mysql/data/err.logpid-file=/application/mysql/data/mysql.pid## include all files from the config directory#!includedir /etc/my.cnf.d |