系统:CenteOS 7.4
shell> rpm -qa | grep mysql
shell> rpm -e --nodeps xxx(匹配到的mysql名称)
shell> yum install -y wget cmake gcc* c++* autoconf automake
shell> yum install -y zlib* libxml* ncurses-devel libmcrypt* libtool-ltdl-devel* perl
##在文件/etc/security/limits.conf的最后增加以下内容
mysql soft nproc 2047
mysql hard nproc 16384
mysql soft nofile 1024
mysql hard nofile 65536
shell> groupadd mysql
shell> useradd -g mysql mysql
从http://mirrors.sohu.com/mysql下载
# 下载和解压
shell> mkdir -p /home/q/mysql
shell> cd /home/q/mysql
shell> wget http://mirrors.sohu.com/mysql/MySQL-5.6/mysql-5.6.35.tar.gz
shell> tar -zxvf mysql-5.6.35.tar.gz
shell> cd mysql-5.6.35
shell>
cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DENABLED_LOCAL_INFILE=ON \
-DWITH_MYISAM_STORAGE_ENGINE=ON \
-DWITH_INNOBASE_STORAGE_ENGINE=ON \
-DMYSQL_DATADIR=/var/mysql/data \
-DSYSCONFDIR=/data/mysqldata/3306 \
-DMYSQL_UNIX_ADDR=/data/mysqldata/3306/mysql.sock
通过rm命令,删除源码包目录下的Cmakecache.txt文件,然后重新执行cmake命令
rm -if CMakeCache.txt
#重新执行 cmake ...
make && make install
chown -R mysql:mysql /usr/local/mysql
vi /home/mysql/.bash_profile
#在该文件的最后增加下面两行
export LANG=zh_CN.GB18030
export PATH=/usr/local/mysql/bin:$PATH
cd /data/
mkdir -p /data/mysqldata/{3306/{data,tmp,binlog},backup,scripts}
chown -R mysql:mysql mysqldata
su - mysql
cd /usr/local/mysql
touch /data/mysqldata/3306/my.cnf
vi /data/mysqldata/3306/my.cnf
# 添加下列参数
[client]
port = 3306
socket = /data/mysqldata/3306/mysql.sock
# The MySQL server
[mysqld]
port = 3306
user = mysql
socket = /data/mysqldata/3306/mysql.sock
pid-file = /data/mysqldata/3306/mysql.pid
basedir = /usr/local/mysql
datadir = /data/mysqldata/3306/data
tmpdir = /data/mysqldata/3306/tmp
open_files_limit = 10240
sql_mode = NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
# Buffer
max_allowed_packet = 256M
max_heap_table_size = 256M
net_buffer_length = 8K
sort_buffer_size = 2M
join_buffer_size = 4M
read_buffer_size = 2M
read_rnd_buffer_size = 16M
#log
log-bin = /data/mysqldata/3306/binlog/mysql-bin
binlog_cache_size = 32M
max_binlog_cache_size = 512M
max_binlog_size = 512M
binlog_format = mixed
log_output = FILE
log-error = ../mysql-error.log
slow_query_log = 1
slow_query_log_file = ../slow_query.log
general_log = 0
general_log_file = ../general_query.log
expire-logs-days = 14
#InnoDB
innodb_data_file_path = ibdatal:2048M:autoextend
innodb_log_file_size = 256M
innodb_log_files_in_group = 3
innodb_buffer_pool_size = 1024M
explicit_defaults_for_timestamp=true
[mysql]
no-auto-rehash
prompt = (\u@\h) [\d]>\_
default-character-set = gbk
/usr/local/mysql/scripts/mysql_install_db --datadir=/data/mysqldata/3306/data --basedir=/usr/local/mysql
shell> cd /usr/local/mysql
shell> bin/mysqld_safe --defaults-file=/data/mysqldata/3306/my.cnf &
netstat -lnt | grep 3306
ps -ef | grep bin/mysql | grep -v grep
ln -s /usr/local/mysql/bin/mysql /usr/bin
# 首次进入
mysql
select user,host from mysql.user; #查询用户
# 为保证安全删除其他用户
delete from mysql.user where (user,host) not in (select 'root','localhost');
# 修改现有用户
update mysql.user set user='root',password=password('111111');
# 删除test库的权限
truncate table mysql.db;
# 刷新权限
flush privileges;
-A INPUT -m state --state NEW -m tcp -p -dport 3306 -j ACCEPT
vi /data/mysqldata/scripts/mysql_env.ini
#set env
MYSQL_USER=root
MYSQL_PASS='111111'
# check parameter
if [ $# -ne 1]
then
HOST_PORT=3306
else
HOST_PORT=$1
fi
chmod 600 /data/mysqldata/scripts/mysql_env.ini
vi /data/mysqldata/scripts/mysql_db_startup.sh