编译安装MySQL
cd /opt
mkdir /mysql
cd /mysql
安装环境包
yum -y install gcc gcc-c++ ncurses ncurses-devel bison cmake
编译安装
cd /opt
tar zxvf mysql-boost-5.7.20.tar.gz
cd mysql-5.7.20/
cmake \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock \
-DSYSCONFDIR=/etc \
-DSYSTEMD_PID_DIR=/usr/local/mysql \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_ARCHIVE_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DWITH_PERFSCHEMA_STORAGE_ENGINE=1 \
-DMYSQL_DATADIR=/usr/local/mysql/data \
-DWITH_BOOST=boost \
-DWITH_SYSTEMD=1
make && make install
创建mysql用户,设置权限
useradd -s /sbin/nologin mysql
chown -R mysql.mysql /usr/local/mysql/
配置文件
cd /etc
vim my.cnf
删除全部内容,添加如下内容
[client]
port = 3306
default-character-set=utf8
socket = /usr/local/mysql/mysql.sock
[mysql]
port = 3306
default-character-set=utf8
socket=/usr/local/mysql/mysql.sock
[mysqld]
user = mysql
basedir = /usr/local/mysql
datadir=/usr/local/mysql/data
port = 3306
character_set_server=utf8
pid-file = /usr/local/mysql/mysqld.pid
socket = /usr/local/mysql/mysql.sock
server-id = 1
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_AUTO_VALUE_ON_ZERO,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,PIPES_AS_CONCAT,ANSI_QUOTES
设置环境变量
vim /etc/profile
最后一行添加
PATH=/usr/local/mysql/bin:/usr/local/mysql/lib:$PATH
export PATH
source /etc/profile
初始化数据库
cd /usr/local/mysql/
bin/mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
设置MySQL密码
cp usr/lib/systemd/system/mysqld.service /usr/lib/systemd/system
systemctl start mysqld.service
netstat -ntap | grep 3306
systemctl enable mysqld.service ‘设置开机自启’
mysqladmin -u root -p password "abc123"
Enter password: 空,这边不填
[root@localhost mysql]# mysql -u root -p
Enter password:abc123
mysql> show databases;
mysql> quit