cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql/ -DMYSQL_DATADIR=/data/mysql/ -DSYSCONFDIR=/etc/ -DWITH_BOOST=/usr/local/mysql/boost/ # 安裝目錄 CMAKE_INSTALL_PREFIX # 數(shù)據(jù)目錄 MYSQL_DATADIR # 配置文件目錄 SYSCONFDIR # 指定boost庫的位置 WITH_BOOST # cmake時遇到的錯誤 錯誤1: CMake Error: your C compiler: "CMAKE_C_COMPILER-NOTFOUND" was not found. Please set CMAKE_C_COMPILER to a valid compiler path or name. 解決: // 安裝gcc yum install gcc-c++ 錯誤2: CMake Error at cmake/readline.cmake:64 (MESSAGE): Curses library not found. Please install appropriate package, remove CMakeCache.txt and rerun cmake.On Debian/Ubuntu, package name is libncurses5-dev, on Redhat and derivates it is ncurses-devel 解決: yum install ncurses-devel 解除錯誤后刪除 CMakeCache.txt 在重新cmake // 添加mysql用戶 useradd -s /sbin/nologin mysql // 創(chuàng)建mysql數(shù)據(jù)存放目錄 mkdir -p /data/mysql // 給予目錄權(quán)限 chown -R mysql:mysql /data/mysql
編譯并安裝
make
make install # mysql 編譯時間較長建議make和make install分開執(zhí)行 # mysql 編譯非常消耗內(nèi)存 如果內(nèi)存較小可能無法編譯通過 # 之前1G內(nèi)存的阿里云編譯到30%左右就掛了 換4G內(nèi)存機(jī)器才編譯通過 # 目測編譯MySQL5.7.20至少要2G的內(nèi)存 ( 未測試 )
安裝完成后 初始化MySQL
/usr/local/mysql/bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql # 生成MySQL臨時密碼 --initialize # 指定運(yùn)行MySQL的用戶 --user=mysql # 指定MySQL的安裝目錄 --basedir=/usr/local/mysql # 指定MySQL的數(shù)據(jù)目錄 --datadir=/data/mysql # 初始化成功 A temporary password is generated for root@localhost: 5-h1Bbf*EQwk 臨時密碼: 5-h1Bbf*EQwk
啟動MySQL
# MySQL默認(rèn)啟動命令在 /usr/local/mysql/support-files/mysql.server # 拷貝一個出來 cp /usr/local/mysql/support-files/mysql.server /usr/local/mysql/mysqld # 啟動MySQL /usr/local/mysql/mysqld start # 啟動報(bào)錯 錯誤1: MySQL.2017-11-09T09:27:48.949025Z mysqld_safe error: log-error set to '/var/log/mariadb/mariadb.log', however file don't exists. Create writable for user 'mysql'. 解決: 猜測可能是日志文件沒有權(quán)限 直接去修改MySQL配置文件 /etc/my.cnf 修改 log-error 位置 并給予日志文件權(quán)限 在 mysql 目錄下創(chuàng)建了 log 存在錯誤日志 mkdir log chown mysql:mysql log 錯誤2: Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2) 解決: 首先查看 /var/lib/mysql/ 下是否有 mysql.sock 然后建立軟連接到 /tmp/ 下 ln -s /var/lib/mysql/mysql.sock /tmp/mysql.sock mysql.sock 的位置在my.cnf中也有配置 再次啟動 /usr/local/mysql/mysqld start 啟動成功
連接MySQL
/usr/local/mysql/bin/mysql -h localhost -uroot -p # 密碼是初始化的 : 5-h1Bbf*EQwk # 登陸成功 執(zhí)行 show databases; 直接報(bào)錯了 提示必須修改初始密碼 # 修改密碼 set password for root@localhost = password('MaShen666'); # 刷新權(quán)限 flush privileges; # 再次執(zhí)行 show databases; 成功