- 安裝環(huán)境:Centos7.2
- mysql版本:5.7.21
- 安裝方式:二進(jìn)制安裝
下載
- 官網(wǎng)下載地址:https://dev.mysql.com/downloads/mysql/
- wget下載:wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.21-linux-glibc2.12-x86_64.tar.gz
安裝前準(zhǔn)備
-
配置用戶和組
groupadd mysql useradd mysql -g mysql
-
配置好/etc/my.cnf配置文件(線上使用各種文件路徑要提前規(guī)劃好空盼,也可在安裝時(shí)指定悠瞬,如果測試用本步驟可以省略)
路徑名稱 cnf中關(guān)鍵字 規(guī)劃的地址 安裝目錄 basedir /opt/mysql/base 數(shù)據(jù)目錄 datadir /opt/mysql/data 日志目錄 log-error /opt/mysql/binlog/error.log
-
安裝依賴
yum install -y libaio libaio-devel
-
創(chuàng)建路徑
mkdir -p /opt/mysql/{data,binlog,base} #目錄賦權(quán) chown -R mysql:mysql /opt/mysql
安裝過程
```
cd 壓縮包所在路徑
#解壓壓縮包
tar -zxvf mysql-5.7.21-linux-glibc2.12-x86_64.tar.gz
cd mysql-5.7.21-linux-glibc2.12-x86_64
#將安裝包拷貝到安裝目錄
cp -r * /opt/mysql/base/
#初始化數(shù)據(jù)庫(執(zhí)行結(jié)果最后一行有進(jìn)入mysql的root密碼易阳,請注意保存,如果忘記保存可以在error.log里找到)
/opt/mysql/base/bin/mysqld --defaults-file=/etc/my.cnf --initialize --user=mysql --basedir=/opt/mysql/base/ --datadir=/opt/mysql/data/ --log-error=/opt/mysql/binlog/error.log --socket=/opt/mysql/mysql.sock
#啟動(dòng)數(shù)據(jù)庫(指定的參數(shù)如果在配置文件中已經(jīng)配置好乳愉,無需在下邊命令中指定,只需指定my.cnf路徑即可)
/opt/mysql/base/bin/mysqld_safe --defaults-file=/etc/my.cnf --basedir=/opt/mysql/base/ --datadir=/opt/mysql/data/ --log-error=/opt/mysql/binlog/error.log --socket=/opt/mysql/mysql.sock --pid-file=/opt/mysql/mysql.pid --user=mysql &
#為了方便調(diào)用灰羽,配置環(huán)境變量
echo "PATH=$PATH:/opt/mysql/base/bin">>/etc/profile
```
登陸和修改密碼
-
登陸
#如果忘記密碼從error.log中cat /opt/mysql/binlog/error.log |grep password 找到密碼 mysql -uroot -p 回車 輸入密碼 [root@localhost]# mysql -uroot -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 2 Server version: 5.7.21 Copyright (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.
-
修改密碼
#執(zhí)行sql alter user root@localhost identified by 'your password';
以上就是mysql數(shù)據(jù)庫二進(jìn)制安裝的全部過程午笛。