Centos7——原始碼安裝Mysql
#解壓安裝包
[[email protected] Mysql]# tar -xf mysql-5.7.18.tar.gz
[[email protected] Mysql]# tar -xf mysql-boost-5.7.18.tar.gz
注意:要加壓兩個壓縮檔案,當解壓boots時,若mysql安裝包與boots在同一目錄下,解壓後會自動放到安裝包內,若兩個壓縮包不在同一路徑下,需要將boots解壓到mysql安裝包內
#檢查是否掛載映象,若無掛載,手工掛載即可
[[email protected] tmp]# mount /dev/cdrom /mnt
安裝依賴包
[
#新建使用者組和使用者
[[email protected] Mysql]# groupadd -r mysql && useradd -r -g mysql -s /sbin/nologin -M mysql
#進入到mysql解壓目錄
[[email protected] mysql-5.7.18]# pwd
/tmp/mysql-5.7.18
#預編譯及安裝
cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql
-DMYSQL_DATADIR=/usr/local/mysql/data
-DDEFAULT_CHARSET=all
-DDEFAULT_CHARSET=utf8
-DDEFAULT_COLLATION=utf8_general_ci
-DWITH_INNOBASE_STORAGE_ENGINE=1
-DWITH_MYISAM_STORAGE_ENGINE=1
-DMYSQL_USER=mysql
-DMYSQL_TCP_PORT=3306
-DWITH_BOOST=boost/boost_1_59_0/
-DENABLED_LOCAL_INFILE=1
-DWITH_PARTITION_STORAGE_ENGINE=1
-DMYSQL_UNIX_ADDR=/usr/local/mysql/myqld.sock
-DWITH_EMBEDDED_SERVER=1
make
make install
#設定啟動指令碼,開機自啟動
[[email protected] mysql]# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql
[[email protected] mysql]# chmod +x /etc/init.d/mysql
[[email protected] mysql]# chown -R mysql:mysql /usr/local/mysql/
#修改etc目錄下my.cnf檔案,並初始化資料庫
修改內容如下:
[mysqld]
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
socket=/usr/local/mysql/mysqld.sock
[mysqld_safe]
log-error=/usr/local/mysql/mysql.log
pid-file=/usr/local/mysql/mysql.pid
[mysql]
no-auto-rehash
socket=/usr/local/mysql/mysqld.sock
儲存並退出
初始化資料庫
/usr/local/mysql/bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
2018-06-15T17:02:11.941364Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2018-06-15T17:02:13.999695Z 0 [Warning] InnoDB: New log files created, LSN=45790
2018-06-15T17:02:14.376291Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2018-06-15T17:02:14.503974Z 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: da19952b-70bd-11e8-9a0a-52540087766e.
2018-06-15T17:02:14.527680Z 0 [Warning] Gtid table is not ready to be used. Table ‘mysql.gtid_executed’ cannot be opened.
2018-06-15T17:02:14.528187Z 1 [Note] A temporary password is generated for [email protected]: 5fTwU/o/lkio
注意:初始化後,自動生成密碼
#配置環境變數並啟動服務
[[email protected] mysql]# vim /etc/profile
編輯環境變數,輸入以下內容:
PATH=/usr/local/mysql/bin:$PATH
export PATH
重新整理生效
[[email protected] mysql]# source /etc/profile
#啟動資料庫
[[email protected] mysql]# service mysql start
注意:若是啟動時出現這個問題,是mysql.log沒有,手工建立一個
Starting MySQL.2018-06-15T17:09:16.784027Z mysqld_safe error: log-error set to ‘/usr/local/mysql/mysql.log’, however file don’t exists. Create writable for user ‘mysql’.
ERROR! The server quit without updating PID file (/usr/local/mysql/data/kvm122102.pid).
手工建立mysql.log步驟如下:
[[email protected] mysql-5.7.18]# cd /usr/local/mysql/
[[email protected] mysql]# ls -l
total 40
drwxr-xr-x 2 mysql mysql 4096 Jun 15 12:47 bin
-rw-r–r-- 1 mysql mysql 17987 Mar 18 2017 COPYING
drwxr-x— 5 mysql mysql 147 Jun 15 13:02 data
drwxr-xr-x 2 mysql mysql 55 Jun 15 12:46 docs
drwxr-xr-x 3 mysql mysql 4096 Jun 15 12:46 include
drwxr-xr-x 4 mysql mysql 191 Jun 15 12:47 lib
drwxr-xr-x 4 mysql mysql 30 Jun 15 12:46 man
drwxr-xr-x 10 mysql mysql 4096 Jun 15 12:48 mysql-test
-rw-r–r-- 1 mysql mysql 2478 Mar 18 2017 README
drwxr-xr-x 28 mysql mysql 4096 Jun 15 12:48 share
drwxr-xr-x 2 mysql mysql 90 Jun 15 12:48 support-files
[[email protected] mysql]# touch mysql.log
[[email protected] mysql]# chown -R mysql:mysql mysql.log
[[email protected] mysql]# ls -l
total 40
drwxr-xr-x 2 mysql mysql 4096 Jun 15 12:47 bin
-rw-r–r-- 1 mysql mysql 17987 Mar 18 2017 COPYING
drwxr-x— 5 mysql mysql 147 Jun 15 13:02 data
drwxr-xr-x 2 mysql mysql 55 Jun 15 12:46 docs
drwxr-xr-x 3 mysql mysql 4096 Jun 15 12:46 include
drwxr-xr-x 4 mysql mysql 191 Jun 15 12:47 lib
drwxr-xr-x 4 mysql mysql 30 Jun 15 12:46 man
-rw-r–r-- 1 mysql mysql 0 Jun 15 13:10 mysql.log
drwxr-xr-x 10 mysql mysql 4096 Jun 15 12:48 mysql-test
-rw-r–r-- 1 mysql mysql 2478 Mar 18 2017 README
drwxr-xr-x 28 mysql mysql 4096 Jun 15 12:48 share
drwxr-xr-x 2 mysql mysql 90 Jun 15 12:48 support-files
[[email protected] mysql]# service mysql start
Starting MySQL. SUCCESS!
[[email protected] mysql]#
#登陸並修改密碼
mysql -u root -p
mysql> alter user ‘root’@‘localhost’ identified by ‘!QAZ2wsx#’;
Query OK, 0 rows affected (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)