系統是cenos6.7 64位的,預設mysql5.7.11下載到/usr/local/src,安裝目錄在/app/local/mysql目錄下,mysql數據放置目錄/app/local/data。mysql從5.1後採用cmake方式編譯安裝,所以要先編譯安裝cmake工具,也可以採用yum方式 ...
系統是cenos6.7 64位的,預設mysql5.7.11下載到/usr/local/src,安裝目錄在/app/local/mysql目錄下,mysql數據放置目錄/app/local/data。mysql從5.1後採用cmake方式編譯安裝,所以要先編譯安裝cmake工具,也可以採用yum方式安裝cmake。從mysql5.7開始編譯安裝需要boost庫的支持,所以也要下載boost庫
#wget http://mirrors.sohu.com/mysql/MySQL-5.7/mysql-5.7.11.tar.gz
#wget https://cmake.org/files/v3.1/cmake-3.1.3.tar.gz
#wget https://sourceforge.net/projects/boost/files/boost/1.59.0/boost_1_59_0.tar.gz
如果沒有mysql用戶則新建mysql用戶。
#groupadd mysql
#useradd -g mysql mysql -s /bin/false
創建相應的目錄
#mkdir -p /app/local/{mysql,data}
#mkdir /usr/local/boost
編譯安裝cmake
#tar zxvf cmake-3.1.3.tar.gz
#cd cmake-3.1.3
#./configure
#make && make install
#cd ../
將boost庫解壓到/usr/local/boost目錄下
#tar zxvf boost_1_59_0.tar.gz
#cd boost_1_59_0/
#mv ./* /usr/local/boost/
#cd ../
編譯安裝mysql5.7.11
#tar zxvf mysql-5.7.11.tar.gz
#cd mysql-5.7.11
#cmake -DCMAKE_INSTALL_PREFIX=/app/local/mysql/ -DMYSQL_DATADIR=/app/local/data -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DMYSQL_TCP_PORT=3306 -DMYSQL_USER=mysql -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_ARCHIVE_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DWITH_MEMORY_STORAGE_ENGINE=1 -DDOWNLOAD_BOOST=1 -DWITH_BOOST=/usr/local/boost
#make && make install
#cd ../
#chown -R mysql:mysql /app/local/data/
#chown -R mysql:mysql /app/local/mysql/
#cd /app/local/mysql/bin
#./mysqld --initialize --user=mysql --basedir=/app/local/mysql/ --datadir=/app/local/data/#初始化mysql 並且生成一個隨機密碼
#mv /etc/my.cnf /etc/my.cnfbak#先備份生成的my.cnf
#cp ../support-files/my-default.cnf /etc/my.cnf
#cp ../support-files/mysql.server /etc/init.d/mysqld
#chmod 755 /etc/init.d/mysqld
#chkconfig mysqld on
#service mysqld start
#mysql -uroot -p
Enter password:
用剛纔生成的隨機密碼登錄
要是不行,就在my.cnf里配置password
登錄後重置root密碼
mysql> SET PASSWORD FOR 'root'@localhost = PASSWORD('123456');
Query OK, 0 rows affected, 1 warning (0.00 sec)
就可以了