一、 环境准备
- 下载软件包
wget http://test.hexin.cn/software/mysql-5.7.9.tar.gz -P /usr/local/src/
wget http://test.hexin.cn/software/cmake-3.4.0.tar.gz -P /usr/local/src/
wget http://test.hexin.cn/software/boost_1_59_0.tar.gz -P /usr/local/src/ - 安装基础软件
yum -y install make gcc-c++ bison-devel ncurses-devel
二、 安装配置MySQL
-
编译安装cmake
tar zxvf /usr/local/src/cmake-3.4.0.tar.gz
cd /usr/local/src/cmake-3.4.0
./configure && make && make install -
编译安装boost(编译时不加boost,可以不用安装此软件)
tar zxvf /usr/local/src/boost_1_59_0.tar.gz -C /usr/local/boost/
cd /usr/local/boost/
./bootstrap.sh
./b2 -
新增用户用户组
groupadd mysql
useradd mysql -g mysql -M -s /sbin/nologin -
编译安装MySQL
tar zxvf /usr/local/src/mysql-5.7.9.tar.gz
cd /usr/local/src/mysql-5.7.9/
cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/usr/local/mysql/data -DSYSCONFDIR=/etc -DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock -DDOWNLOAD_BOOST=1 -DWITH_BOOST=/usr/local/boost -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_ARCHIVE_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DWITH_READLINE=1 -DWITH_SSL=system -DWITH_ZLIB=system -DWITH_LIBWRAP=0 -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci
make
make install
cmake参数说明
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql [MySQL安装的根目录]
-DMYSQL_DATADIR=/usr/local/mysql [MySQL数据库文件存放目录]
-DSYSCONFDIR=/etc [MySQL配置文件所在目录]
-DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock [MySQL的UNIX socket文件目录]
-DDOWNLOAD_BOOST=1 [允许下载BOOST]
-DWITH_BOOST=/usr/local/boost [指定BOOST安装路径]
-DWITH_INNOBASE_STORAGE_ENGINE=1 [支持InnoDB存储引擎]
-DWITH_MYISAM_STORAGE_ENGINE=1 [支持MYISAM存储引擎]
-DWITH_ARCHIVE_STORAGE_ENGINE=1 [支持Archive引擎]
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 [支持BLACKHOLE引擎]
-DWITH_READLINE=1[支持readline库]
-DWITH_SSL=system[通讯时支持ssl协议]
-DWITH_ZLIB=system[允许使用zlib library]
-DWITH_LIBWRAP=0 [不支持libwrap库]
-DDEFAULT_CHARSET=utf8[设置默认字符集为utf8]
-DDEFAULT_COLLATION=utf8_general_ci[设置默认字符校对]
-
修改权限
chown -R mysql.mysql /usr/local/mysql/ -
初始化MySQL
cd /usr/local/mysql
bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
初始化成功后会生成一个root用户的临时密码,首次登录mysql后需要先修改这个临时密码
- 配置my.cnf 编译的时候制定在/etc目录下
[client]
port = 3306
default-character-set=utf8
[mysqld]
datadir=/usr/local/mysql/data
socket=/usr/local/mysql/mysql.sock
user=mysql
character-set-server=utf8
symbolic-links=0
open_files_limit = 102400
max_connections=2000
skip-name-resolve
#skip-grant-tables
slow_query_log = ‘on’
long_query_time=1
slow_query_log_file=/usr/local/mysql/mysql-slow.log
tmp_table_size=256M
key_buffer_size=512M
read_buffer_size=32M
sort_buffer_size=32M
query_cache_limit=1M
query_cache_size=16M
#INNODB
default-storage-engine=INNODB
innodb_buffer_pool_size=8G
innodb_additional_mem_pool_size = 32M
innodb_buffer_pool_instances=8
innodb_read_io_threads = 8
innodb_write_io_threads = 8
innodb_log_file_size=265M
innodb_log_buffer_size=8M
innodb_log_files_in_group = 3
innodb_lock_wait_timeout=90
innodb_file_per_table=1
innodb_flush_log_at_trx_commit=2
innodb_max_dirty_pages_pct = 90
innodb_thread_concurrency = 16
innodb_file_io_threads=4
innodb_open_files = 1000
read_only
server-id = 1
log-bin=mysql-bin
log-slave-updates
binlog_cache_size = 4M
binlog_format = mixed
max_binlog_cache_size = 1G
max_binlog_size = 1G
auto_increment_offset=1
auto_increment_increment=2
[mysqld_safe]
log-error=/usr/local/mysql/log/mysqld.log
pid-file=/usr/local/mysql/data/mysqld.pid
replicate-do-db =all
- 配置环境变量
vim /etc/profile
PATH=/usr/local/mysql/bin:${PATH}
export PATH
source /etc/profile
- 启动mysql,并加入开机自启动
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
chmod 755 /etc/init.d/mysqld
chkconfig mysqld on
service mysqld start
ln -s /usr/local/mysql/bin/mysql /usr/bin/mysql
数据库启动时报错找不到pid 这时就要给/usr/local/mysql/data目录加755的权限、
- 配置root密码,开通root权限
mysql –uroot -p2qP3PlPZiN;s
mysql>alter user ‘root’@‘localhost’ identified by ‘10jqka@123’;(或者下面grant也行)
mysql>grant all privileges on . to ‘root’@’%’ identified by “10jqka@123”
Mysql>flush privileges;
mysql>exit
如果你格式化时候没有保留初始密码 是进不去数据库的 这时你要
/usr/local/mysql/bin/mysqld_safe --user=mysql --skip-grant-tables &
mysql>use mysql
mysql>update mysql.user set password=password(‘10jqka@123’) where user=‘root’ ;
Mysql>flush privileges;
特别注意:mysql5.7以上版本启动默认路径是/usr/local目录下,如果你安装目录更改,那么要修改启动文件:
vim /etc/init.d/mysqld
找到如下二行:
basedir=
datadir=
修改为:
basedir=安装的mysql目录
datadir=mysql的数据目录
然后再启动。不然会报错无法更新pid文件