1、安装Mysql环境依赖包
[root@localhost ~]#
yum -y install \
gcc-c++ \
gcc \
make \
ncurses \
ncurses-devel \
bison \
cmake
2、创建运行用户
[root@localhost ~] useradd -s /sbin/nologin mysql
3、编译安装
###上传mysql-boost-5.7.20.tar.gz到opt目录下###
[root@localhost ~]cd /opt
[root@localhost opt]# tar xzvf mysql-boost-5.7.20.tar.gz
[root@localhost opt]# cd /opt/mysql-5.7.20/
[root@localhost 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
[root@localhost mysql-5.7.20]# make && make install
[root@localhost mysql-5.7.20]#
用make -j2 安装开始时间:10:38 安装11:58 接下来是make install 时间开始13:37
------注意:如果在CMAKE的过程中有报错---
当报错解决后,需要把源码目录中的CMakeCache.txt文件删除,然后再重新CMAKE,否则错误依旧
------注意:make: *** No targets specified and no makefile found. Stop.解决方法
wget http://ftp.gnu.org/pub/gnu/ncurses/ncurses-5.6.tar.gz
tar zxvf ncurses-5.6.tar.gz
./configure -prefix=/usr/local -with-shared-without-debug
make
make install
4、数据库目录进行权限调整
[root@localhost mysql-5.7.20]#chown -R mysql:mysql /usr/local/mysql/
5、调整配置文件
[root@localhost mysql-5.7.20]#vi /etc/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
chown mysql:mysql /etc/my.cnf
6、设置环境变量
echo 'PATH=/usr/local/mysql/bin:/usr/local/mysql/lib:$PATH' >> /etc/profile
echo 'export PATH' >> /etc/profile
source /etc/profile
7、初始化数据库
cd /usr/local/mysql/
bin/mysqld \
--initialize-insecure \
--user=mysql \
--basedir=/usr/local/mysql \
--datadir=/usr/local/mysql/data
cp usr/lib/systemd/system/mysqld.service /usr/lib/systemd/system/
8、数据库开启自启、 关闭、状态
systemctl enable mysqld
systemctl start mysqld
systemctl stop mysqld
systemctl status mysqld
netstat -anpt | grep 3306
9、设置Mysql密码
mysqladmin -u root -p password //刚开始没密码是空的直接回车,然后输入密码123123,在此确认123123,这是在root账户下运行的
10、登录数据库
mysql -u root -p ##这个命令敲下,提示要输入密码,这个就是刚才设置的密码123123
这样就OK登录了!