一氨淌,準(zhǔn)備篇
1泊愧,配置網(wǎng)絡(luò)&關(guān)閉SELINUX
配置網(wǎng)絡(luò)&關(guān)閉SELINUX
2,升級軟件
yum -y update
3盛正,安裝依賴
yum -y install wget gcc gcc-c++ make cmake bison bison-devel ncurses ncurses-devel perl
4删咱,下載MySQL源碼
cd /usr/local/src && wget https://cdn.mysql.com//Downloads/MySQL-5.6/mysql-5.6.38.tar.gz && tar zxvf mysql-5.6.38.tar.gz && cd mysql-5.6.38
5,創(chuàng)建mysql用戶
groupadd mysql && useradd -g mysql -s /bin/false mysql
6豪筝,創(chuàng)建MySQL數(shù)據(jù)目錄痰滋,并設(shè)置權(quán)限
mkdir -p /data/mysql && chown -R mysql.mysql /data/mysql
7,刪除系統(tǒng)默認(rèn)的配置文件
rm -rf /etc/my.cnf
二续崖、安裝篇
1敲街,生成編譯配置
cmake . \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_DATADIR=/data/mysql \
-DDEFAULT_CHARSET=utf8mb4 \
-DDEFAULT_COLLATION=utf8mb4_general_ci
2,編譯&安裝
make && make install
3严望,初始化數(shù)據(jù)目錄
/usr/local/mysql/scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql
4聪富,軟連接MySQL配置文件到/etc目錄
ln -s /usr/local/mysql/my.cnf /etc/my.cnf
5,拷貝MySQL控制腳本著蟹,將mysql加入開機啟動
cp /usr/local/mysql/support-files/mysql.server /etc/rc.d/init.d/mysqld
chmod 755 /etc/init.d/mysqld
chkconfig mysqld on
service mysqld start
6墩蔓,把mysql服務(wù)加入系統(tǒng)環(huán)境變量
echo "export PATH=$PATH:/usr/local/mysql/bin" >> /etc/profile
source /etc/profile
附:一鍵安裝腳本
yum -y update && yum -y install wget gcc gcc-c++ make cmake bison bison-devel ncurses ncurses-devel perl && cd /usr/local/src && wget https://cdn.mysql.com//Downloads/MySQL-5.6/mysql-5.6.38.tar.gz && tar zxvf mysql-5.6.38.tar.gz && cd mysql-5.6.38 && groupadd mysql && useradd -g mysql -s /bin/false mysql && mkdir -p /data/mysql && chown -R mysql.mysql /data/mysql && rm -rf /etc/my.cnf && cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/data/mysql -DDEFAULT_CHARSET=utf8mb4 -DDEFAULT_COLLATION=utf8mb4_general_ci && make && make install && /usr/local/mysql/scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql && ln -s /usr/local/mysql/my.cnf /etc/my.cnf && cp /usr/local/mysql/support-files/mysql.server /etc/rc.d/init.d/mysqld && chmod 755 /etc/init.d/mysqld && chkconfig mysqld on && service mysqld start && echo "export PATH=$PATH:/usr/local/mysql/bin" >> /etc/profile && source /etc/profile
三、優(yōu)化篇
1萧豆,使用mysql_secure_installation提高M(jìn)ySQL安全性
mysql_secure_installation
- 為root帳戶設(shè)置密碼奸披。
- 刪除匿名用戶帳戶。
- 不允許遠(yuǎn)程root登錄涮雷。
- 刪除test數(shù)據(jù)庫阵面。
- 重新加載權(quán)限表。
2,設(shè)置root賬戶遠(yuǎn)程訪問密碼
shell> mysql -uroot -p
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456' WITH GRANT OPTION;
mysql> exit;