1.cmake软件的安装
wget https://cmake.org/files/v3.5/cmake-3.5.0-rc3.tar.gz
tar xf cmake-3.5.0.tar.gz
cd cmake-3.5.0
./configure
gmake
gmake install
2.依赖包 ncurses-devel,boost,bison
yum -y install gcc gcc-c++ ncurses ncurses-devel cmake bison bison-devel autoconf automake zlib* libxml* libmcrypt* libtool*
yum install ncurses-devel
#apt-get install libncurses5-dev
yum install boost.x86_64 -y
rm -rf CMakeCache.txt
yum install -y zlib.x86_64
yum install -y cmake.x86_64
boost : http://www.boost.org/users/download/
tar zxf boost_1_59_0.tar.gz
在后面编译的时候:-DWITH_BOOST 指向这个解压的目录地址中就可以了,也可以下载带有bison版本的mysql源码 这时候就指向./boost/boost_1_59_0就可以了
#cd boost_1_59_0
#./bootstrap.sh
#./b2 stage threading=multi link=shared
#./b2 install threading=multi link=shared
gmock https://github.com/paulsapps/gmock-1.7.0
unzip gmock-1.7.0.zip
cp gmock-1.7.0 /src/mysql-5.7.11/source_downloads/ 中去就可以了
3.创建用户和组
groupadd mysql
useradd mysql -s /sbin/nologin -M -g mysql
4.安装mysql
wget http://dev.mysql.com/get/Downloads/MySQL-5.5/mysql-5.5.48.tar.gz
tar zxf mysql-5.5.32.tar.gz
cd mysql-5.5.32
mkdir -p /application/mysql
mkdir -p /application/mysql/etc
mkdir -p /application/mysql/tmp
mkdir -p /application/mysql/data
cmake -DCMAKE_INSTALL_PREFIX=/application/mysql -DSYSCONFDIR=/application/mysql/etc -DMYSQL_UNIX_ADDR=/application/mysql/tmp/mysql.sock -DMYSQL_DATADIR=/application/mysql/data -DDOWNLOAD_BOOST=1 -DWITH_BOOST=./boost/boost_1_59_0 -DMYSQL_TCP_PORT=3306 -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DEXTRA_CHARSETS=all -DENABLED_LOCAL_INFILE=ON -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITHOUT_FEDERATED_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DWITH_EXAMPLE_STORAGE_ENGINE=1 -DWITHOUT_PARTITION_STORAGE_ENGINE=1 -DWITH_FAST_MUTEXES=1 -DWITH_ZLIB=bundled -DENABLED_LOCAL_INFILE=1 -DWITH_READLINE=1 -DWITH_EMBEDDED_SERVER=1 -DWITH_DEBUG=0
5.编译安装
make && make install
6.获取配置文件
ll mysql-5.5.32/support-files/*.cnf
cp support-files/my-default.cnf /usr/local/mysql/etc/my.cnf
7.创建mysql数据库文件
mkdir -p /usr/local/mysql/data
chown -R mysql.mysql /usr/local/mysql/data
chmod -R 1777 /tmp
#5.7之前的初始化数据库的方式
/usr/local/mysql/scripts/mysql_install_db --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --user=mysql
#5.7之后数据库初始化方式
bin/mysqld --initialize --user=mysql --basedir=/application/mysql/ --datadir=/application/mysql/data/
得到初始的密码,用这个初始密码进入数据库中,在这之前已启动数据库
bin/mysqld_safe --defaults-file=./my.cnf &
进入:
bin/mysql -uroot -p
输入得到的初始密码
set password=password('rootpasswd');
更改初始的密码,这样就可以进行操作了,在mysql5.7之后,密码有了一个默认的过期时间了,默认是360天
用这个来查看过期时间
show variables like 'default_password_lifetime'; 生产环境建议设为0,永不过期
8.启动mysql数据库
/usr/local/mysql/bin/mysqld_safe --user=mysql &
9.检查mysql数据库是否启动
netstat -lnt|grep 3306
10.配置mysql命令全局使用路径
vi /etc/profile 在底部加入
export PATH="/usr/local/mysql/bin:$PATH"
# echo 'export PATH="/usr/local/mysql/bin:$PATH"' >>/etc/profile
使其生效,执行下面命令:
source /etc/profile
11.启动和停止方式
cp mysql-5.5.32/support-files/mysql.server /etc/init.d/mysqld
chmod 700 /etc/init.d/mysqld
/etc/init.d/mysqld stop
这样就可以停止或启动mysql服务了
12.配置Mysql数据库开机启动
chkconfig --add mysqld
chkconfig mysqld on
chkconfig --list mysqld
13.为mysql中的root增加密码
mysqladmin -uroot password 'root'
14.清理多余的用户和不用的数据库
select USER,HOST from mysql.user;
delete from mysql.user where USER='';
delete from mysql.user where HOST='::1'; # 这个是IPV6的,可以删除
+------+-----------+
| USER | HOST |
+------+-----------+
| root | 127.0.0.1 |
| root | localhost |
+------+-----------+
最后保留这样就可以了,到此mysql源码安装完毕