1,安装所有包
yum -y install gcc-c++ ncurses-devel cmake make perl gcc autoconf automake zlib libxml libgcrypt libtool bison python-devel
2,创建用户,目录,权限
groupadd mysql
useradd -r -g mysql -s /bin/false mysql
mkdir /usr/local/mysql 软件目录
mkdir -p /usr/local/mysql/data 数据目录
mkdir -p /var/log/mysql 日志路径
mkdir -p /var/run/mysql pid路径
-- 用户属主
chown -R mysql:mysql /usr/local/mysql
chown -R mysql:mysql /mydata/mysql/data
chown -R mysql:mysql /var/log/mysql
chown -R mysql:mysql /var/run/mysql
另外如果有登陆固需求:
设置vim /etc/security/limits.conf
mysql soft nproc 2047
mysql hard nproc 16384
mysql soft nofile 1024
mysql hard nofile 65536
环境变量:
vim /home/mysql/.bash_profile
export LANG=zh_CN.GB18030
export PATH=/usr/local/mysql/bin:$PATH
3,安装一些配置,工具包
gmock ,地址http://git.typecodes.com/libs/ccpp/gmock-1.6.0.zip
安装步骤,解压到mysql-5.7.9的source_downloads目录,可选步骤
安装cmake,可以使用yum安装或者下载安装,下载路经http://git.typecodes.com/libs/ccpp/cmake-3.2.1.tar.gz
安装ncurses-devel,yum安装
GNU分析器生成器,连接http://git.typecodes.com/libs/ccpp/bison-3.0.tar.gz
boost请看第四部分析
4,编译&&安装
tar zxvf mysql-5.7.9.tar.gz
cd mysql-5.7.9
第一部:cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql
-DMYSQL_DATADIR=/mydata/mysql/data -DSYSCONFDIR=/etc -DMYSQL_USER=mysql
-DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1
-DWITH_ARCHIVE_STORAGE_ENGINE=1 -DWITH_MEMORY_STORAGE_ENGINE=1
-DWITH_READLINE=1
-DMYSQL_UNIX_ADDR=/var/run/mysql/mysql.sock -DMYSQL_TCP_PORT=3306
-DENABLED_LOCAL_INFILE=1 -DENABLE_DOWNLOADS=1
-DWITH_PARTITION_STORAGE_ENGINE=1 -DEXTRA_CHARSETS=all
-DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci
-DWITH_DEBUG=0 -DMYSQL_MAINTAINER_MODE=0
-DWITH_SSL:STRING=bundled -DWITH_ZLIB:STRING=bundled
-DWITH_BOOST=/usr/local/boost
第二部:make && make install
说明
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \ [MySQL安装的根目录]
-DMYSQL_DATADIR=/mydata/mysql/data \ [MySQL数据库文件存放目录]
-DSYSCONFDIR=/etc \ [MySQL配置文件所在目录]
-DMYSQL_USER=mysql \ [MySQL用户名]
-DWITH_MYISAM_STORAGE_ENGINE=1 \ [MySQL的数据库引擎]
-DWITH_INNOBASE_STORAGE_ENGINE=1 \ [MySQL的数据库引擎]
-DWITH_ARCHIVE_STORAGE_ENGINE=1 \ [MySQL的数据库引擎]
-DWITH_MEMORY_STORAGE_ENGINE=1 \ [MySQL的数据库引擎]
-DWITH_READLINE=1 \ [MySQL的readline library]
-DMYSQL_UNIX_ADDR=/var/run/mysql/mysql.sock \ [MySQL的通讯目录]
-DMYSQL_TCP_PORT=3306 \ [MySQL的监听端口]
-DENABLED_LOCAL_INFILE=1 \ [启用加载本地数据]
-DENABLE_DOWNLOADS=1 \ [编译时允许自主下载相关文件]
-DWITH_PARTITION_STORAGE_ENGINE=1 \
-DEXTRA_CHARSETS=all \ [使MySQL支持所有的扩展字符]
-DDEFAULT_CHARSET=utf8 \ [设置默认字符集为utf8]
-DDEFAULT_COLLATION=utf8_general_ci \ [设置默认字符校对]
-DWITH_DEBUG=0 \ [禁用调试模式]
-DMYSQL_MAINTAINER_MODE=0 \
-DWITH_SSL:STRING=bundled \ [通讯时支持ssl协议]
-DWITH_ZLIB:STRING=bundled \ [允许使用zlib library]
-DWITH_BOOST=/usr/local/boost [boost库地址,如果安装了,可以不用指定]
中间遇到两个问题,
第一,CMake Error at cmake/boost.cmake:76 (MESSAGE)
You can download it with -DDOWNLOAD_BOOST=1 -DWITH_BOOST=<directory>
解决方法:追加编译选项-DDOWNLOAD_BOOST=1 -DWITH_BOOST=/usr/local/boost或者将
http://sourceforge.net/projects/boost/files/boost/1.59.0
/boost_1_59_0.tar.gz下载到/usr/local/boost
再追加编译选项-DWITH_BOOST=/usr/local/boost
这个一定要匹配,mysql-5.7.9可能需要安装boost_1_59_0以上版本的
第二,Could NOT find Curses (missing: CURSES_LIBRARY CURSES_INCLUDE_PATH)
解决:
rm CMakeCache.txt
yum install ncurses-devel
其实这个根据提示就可以看出来了
第三,安装boost的时候,提示很多python库没找到
yum install python-devel
5,配置文件
我们安装时配置的路径是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.
[client]
port=3306
socket=/var/run/mysql/mysql.sock
[mysqld]
# 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.
user = mysql
basedir = /usr/local/mysql
datadir = /mydata/mysql/data
port=3306
server-id = 1
socket=/var/run/mysql/mysql.sock
character-set-server = utf8
log-error = /var/log/mysql/error.log
pid-file = /var/log/mysql/mysql.pid
general_log = 1
skip-name-resolve
#skip-networking
back_log = 300
max_connections = 1000
max_connect_errors = 6000
open_files_limit = 65535
table_open_cache = 128
max_allowed_packet = 4M
binlog_cache_size = 1M
max_heap_table_size = 8M
tmp_table_size = 16M
read_buffer_size = 2M
read_rnd_buffer_size = 8M
sort_buffer_size = 8M
join_buffer_size = 28M
key_buffer_size = 4M
thread_cache_size = 8
query_cache_type = 1
query_cache_size = 8M
query_cache_limit = 2M
ft_min_word_len = 4
log_bin = mysql-bin
binlog_format = mixed
expire_logs_days = 30
performance_schema = 0
explicit_defaults_for_timestamp
#lower_case_table_names = 1
#default-storage-engine=myism
#innodb_buffer_pool_size=2048M
#innodb_log_file_size=1024M
myisam_sort_buffer_size = 8M
myisam_repair_threads = 1
interactive_timeout = 28800
wait_timeout = 28800
# 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
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
# Recommended in standard MySQL setup
sql_mode=NO_ENGINE_SUBSTITUTION,NO_AUTO_CREATE_USER,STRICT_TRANS_TABLES
[mysqldump]
quick
max_allowed_packet = 16M
[myisamchk]
key_buffer_size = 8M
sort_buffer_size = 8M
read_buffer = 4M
write_buffer = 4M
6,初始化数据库
/usr/local/mysql/bin/mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql --datadir=/mydata/mysql/data
这部很重要,如果初始库不能创建,服务是岂不来的
7,设置系统服务,开机子启动
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
chmod +x /etc/init.d/mysqld
chkconfig --add mysql
chkconfig mysqld on
8,启动服务
mysqld_safe --user=mysql --datadir=/mydata/mysql/data --log-error=/var/log/mysql/error.log &
service mysqld start
不懂两者关系摆渡
查看启动情况:ps -ef | grep mysql,netstat -tunpl | grep 3306
9,初始化配置
mysql_secure_installation
根据需要配置一些root密码,是否匿名访问,是否远程访问,删除test库等操作
10,创建用户等
mysql -uroot -p
create database `mysqldb` default character set utf8 collate utf8_general_ci;
grant all privileges on mysqldb.* to [email protected] identified by ‘china123‘;
flush privileges;
说明:mysql比较特殊,不像oracle,授权即可创建新用户