I feel that installing nginx and php is relatively simple, but mysql is more troublesome
The introduction on the official website is not very detailed. For example, there is no distinction between work and root users, the installation steps cannot be followed, the permissions of each directory, etc.
There is a very detailed blog of Zhang Yan, but it has not been updated for a long time.
雖然MySQL可以用命令行安裝,但是會(huì)對一些細(xì)節(jié)和不可控性不了解,所以選擇源碼安裝
最新版本需要用boost庫,所以要下載 mysql 和 boost, 下載鏈接如下:
http://dev.mysql.com/downloads/mysql/
選擇source code,下載最后兩個(gè)安裝包: mysql-5.7.14.tar.gz, mysql-boost-5.7.14.gz
http://cdn.mysql.com//Downloads/MySQL-5.7/mysql-boost-5.7.14.tar.gz
http://cdn.mysql.com//Downloads/MySQL-5.7/mysql-5.7.14.tar.gz
1 安裝MySQL
1.1 下載
wget http://cdn.mysql.com//Downloads/MySQL-5.7/mysql-boost-5.7.14.tar.gz
wget http://cdn.mysql.com//Downloads/MySQL-5.7/mysql-5.7.14.tar.gz
1.2 解壓
先解壓mysql-5.7.14.tar.gz, 然后再解壓mysql-boost-5.7.14.tar.gz
這樣能保證boost能解壓到mysql-5.7.14/boost目錄下
tar -xvf mysql-5.7.14.tar.gz
tar -xvf mysql-boost-5.7.14.tar.gz
1.3 安裝
1.3.1 安裝MySQL必須庫
apt-get update
apt-get install bison openssl libncurses5-dev perl cmake
1.3.2 編譯安裝
進(jìn)入目錄安裝
cd mysql-5.7.14
cmake . \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_DATADIR=/opt/data/mysql/data \
-DMYSQL_UNIX_ADDR=/tmp/mysql.sock \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DWITH_EXTRA_CHARSETS=all \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_MEMORY_STORAGE_ENGINE=1 \
-DWITH_READLINE=1 \
-DENABLED_LOCAL_INFILE=1 \
-DMYSQL_USER=mysql \
-DWITH_BOOST=boost
make && make install
2.配置MySQL
根據(jù)步驟1,MySQL安裝在/usr/local/mysql目錄下
cd /usr/local/mysql
ls
可以查看mysql目錄
2.1 創(chuàng)建MySQL用戶
groupadd mysql
useradd mysql -g mysql
2.2 創(chuàng)建MySQL數(shù)據(jù)目錄,用來存儲(chǔ)MySQL數(shù)據(jù)
mkdir -p /opt/data/mysql/data # 存放MySQL數(shù)據(jù)庫數(shù)據(jù)
mkdir -p /opt/data/mysql/log # 存放MySQL日志,查看日常操作log和異常
mkdir -p /opt/data/mysql/bin-log # 存放MySQL bin log日志,用來同步數(shù)據(jù)
chown -R mysql:mysql /opt/data/mysql # root用戶將mysql目錄歸mysql用戶所有
2.3 配置MySQL
cd /usr/local/mysql
cp support-files/my-default.cnf /etc/my.cnf # 將my-default.cnf文件復(fù)制到/etc目錄下,并命名為my.cnf
vim /etc/my.cnf # 打開my.cnf, 添加如下配置:
[mysqld]
character_set_server=utf8
server_id = 1
port = 3306
innodb_buffer_pool_size = 128M
basedir = /usr/local/mysql
datadir = /opt/data/mysql/data
socket = /tmp/mysql.sock
pid-file = /opt/data/mysql/mysql.pid
log-bin = /opt/data/mysql/bin-log/mysql-bin
sync-binlog = 1
general_log = 1
log-error = /opt/data/mysql/log/mysql_err.log
general_log_file = /opt/data/mysql/log/mysql.log
[mysql]
default-character-set=utf8
2.4 初始化MySQL
cd /usr/local/mysql
bin/mysqld --defaults-file=/etc/my.cnf --user=mysql --initialize
打開/opt/data/mysql/log/mysql.log, 查找初始化密碼
2016-07-05T08:31:20.363565Z 1 [Note] A temporary password is generated for root@localhost: 9arAj*:r047g
登陸
bin/mysql -u root -p 9arAj*:r047g
不修改密碼不能操作
mysql> show databases;
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
修改密碼
mysql> SET PASSWORD = PASSWORD('123456');
mysql> ALTER USER 'root'@'localhost' PASSWORD EXPIRE NEVER;
mysql> flush privileges;
2.5 配置MySQL執(zhí)行路勁
vim /root/.bashrc # 打開.bashrc文件,并記錄一下內(nèi)容
export PATH=$PATH:/usr/local/mysql/bin/
保存,退出
source /root/.bashrc
執(zhí)行一下命令檢驗(yàn)是否準(zhǔn)確
mysql -uroot -p123456
Mysql has great support for Linux. You only need to execute at least 3 commands to install it successfully.
Here is a tutorial to install Mysql in CentOS 7
https://www.obneer.com/how-to...