MySQL-5.7.19编译安装详解!

时间:2022-04-21 11:39:32

mysql   版本 5.7.19

必备的包和工具

gcc/g++ :MySQL 5.6开始,需要使用g++进行编译。

bison  :MySQL语法解析器需要使用bison进行编译。

libncurses5-dev :用于终端操作的开发包.(注:Debian/Ubuntu下需要安装libncurses5-dev;Redhat下需要安装 ncurses-devel)
zlib    :MySQL使用zlib进行压缩

 

功能需要的包

libxml2  :用于XML输入输出方式的支持。

openssl  :使用openssl安全套接字方式通信。

dtrace  :用于诊断MySQL问题。

cmake  :MySQL 5.5开始,使用cmake进行工程管理,cmake需要2.8以上版本。

 

sudo apt-get install gcc

sudo apt-get install libxml2

sudo apt-get install  libncurses5-dev bison 

安装cmake      下载地址  https://cmake.org/download/

 

建立源码包目录

mkdir /data/src

 

解压

tar zxvf cmake-3.6.1.tar.gz 

mv cmake-3.6.1 /data/src

cd cmake-3.6.1

 

编译安装

./configure   make && make install

 

加入环境变量

vim ~/.bashrc

添加

export PATH="/data/src/cmake-3.6.1/bin/cmake:$PATH"

 

从MySQL 5.7.5开始Boost库是必需的,下载Boost库 http://sourceforge.net/projects/boost/files/boost/

tar zxvf boost_1_59_0.tar.gz 

mv boost_1_59_0 /data/src/


mysql官方下载地址

http://dev.mysql.com/downloads/mysql/   此次有个坑:一定要选择选择可编译版本

具体过程如下:

tar -zxvf mysql-5.7.19.tar.gz
cd /data/
mkdir service
cd /
ll
cd /data/
mkdir src
cd /src/
cp -r /mysql-5.7.19 /data/src/
cd /data/src/
pkill -9 mysqld
cd mysql-5.7.19/


cmake -DCMAKE_INSTALL_PREFIX=/data/service/mysql -


DMYSQL_UNIX_ADDR=/data/service/mysql/data/mysql.sock -DDEFAULT_CHARSET=utf8 -


DDEFAULT_COLLATION=utf8_general_ci -DWITH_EXTRA_CHARSETS:STRING=utf8,gbk -


DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_MEMORY_STORAGE_ENGINE=1 


-DWITH_READLINE=1 -DENABLED_LOCAL_INFILE=1 -DMYSQL_DATADIR=/data/service/mysql/data -


DMYSQL_USER=mysql -DMYSQL_TCP_PORT=3306 -DDOWNLOAD_BOOST=1 -


DWITH_BOOST=/data/service/mysql/mysql-5.7.19/boost/boost_1_59_0


make & make install
cd /data/service
ll
cd mysql
ll
mkdir etc
cd etc/
cp /etc/init.d/my.cnf ./
ls
cd ../
./bin/mysqld --defaults-file=/data/service/mysql/etc/my.cnf --initialize --user=mysql
./bin/my
./bin/mysql -uroot -p
cd /data/service/mysql/
ll
cd /data
ls
ps -ef|grep mysql
cd ../
chown -R root .
chown -R mysql mysql
chown -R mysql data/
pkill -9 mysqld
ps -ef|grep mysql
./bin/mysqld_safe --user=mysql &
./bin/mysql -uroot -p
ps -ef|grep mysql
vi etc/my.cnf
vi /etc/init.d/my.cnf
cp /data/service/mysql/support-files/mysql.server /etc/init.d/
vi /etc/init.d/mysql.server
/etc/init.d/mysql.server restart
./bin/mysqld_safe --user=mysql
ps -ef|grep mysql
./bin/mysql -uroot -p
set password = password('123456');
use mysql;
select * from user \G;
update user set authentication_string=password('123456') where user='root' and host=
flush privileges;
 exit
 vi /etc/init.d/my.cnf
 /etc/init.d/mysql.server restart
./bin/mysql -uroot -p
exit
vi /etc/init.d/my.cnf






//忘记密码时:mysql设置:
1.首先修改配置文件:/etc/init.d/my.cnf
把skip-grant-tables注释打开!顾名思义,就是在启动mysql时不启动grant-tables,授权表
2../bin/mysql -uroot -p
set password = password('123456');
use mysql;
select * from user \G;
update user set authentication_string=password('123456') where user='root' and host=
flush privileges;












#/etc/init.d/my.cnf配置如下:
[client]
port = 3306
socket = /data/service/mysql/data/mysql.sock


[mysqld]
port = 3306
socket = /data/service/mysql/data/mysql.sock


basedir = /data/service/mysql
datadir = /data/service/mysql/data
pid-file = /data/service/mysql/data/mysql.pid
user = mysql


server-id = 1
log-bin = mysql-bin


skip-name-resolve
#skip-grant-tables








#etc/my.cnf配置如下:
# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html
# *** DO NOT EDIT THIS FILE. It's a template which will be copied to the
# *** default location during install, and will be replaced if you
# *** upgrade to a newer version of MySQL.




[mysqld]
port = 3306
socket = /usr/local/mysql/data/mysql.sock
basedir = /usr/local/mysql
explicit_defaults_for_timestamp=1
datadir  = /usr/local/mysql/data
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M


# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin


# These are commonly set, remove the # and set as required.
# basedir = .....
# datadir = .....
# port = .....
# server_id = .....
# socket = .....


# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M


sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES