Mysql tar

  • A+
所属分类:Mysql

系统环境:Centos 7

数据库版本: 5.7

数据库字符集: utf8mb4

1.安装依赖包和相关目录

yum install -y cmake make gcc gcc-c++ bison ncurses ncurses-devel perl libaio  wget;
mkdir /usr/local/boost/;

官方安装参考文档

2.创建Mysql用户和组

groupadd mysql; 
useradd -r -g mysql -s /bin/false mysql;

3.下载并预编译

wget https://cdn.mysql.com//Downloads/MySQL-5.7/mysql-5.7.26.tar.gz && tar -zxvf mysql-5.7.26.tar.gz && cd mysql-5.7.26 && cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/usr/local/mysql/data -DSYSCONFDIR=/etc  -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_PARTITION_STORAGE_ENGINE=1 -DWITH_FEDERATED_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_ARCHIVE_STORAGE_ENGINE=1 -DENABLE_DOWNLOADS=1 -DENABLED_LOCAL_INFILE=1 -DENABLE_DTRACE=0 -DDEFAULT_CHARSET=utf8mb4 -DDEFAULT_COLLATION=utf8mb4_general_ci -DDOWNLOAD_BOOST=1 -DWITH_BOOST=/usr/local/boost -DWITH_EMBEDDED_SERVER=1;

如果cmake失败,重新编译的前,需要删除之前编译的旧对象文件和配置信息:

rm -rf CMakeCache.txt;
rm -rf CMakeFiles;

cmake含义:

-DCMAKE_INSTALL_PREFIX=/usr/local/mysql 安装路径

-DMYSQL_DATADIR=/usr/local/mysql/data 数据库存放位置

-DSYSCONFDIR=/etc my.cnf目录

-DWITH_INNOBASE_STORAGE_ENGINE=1 支持InnoDB引擎

-DWITH_PARTITION_STORAGE_ENGINE=1 安装支持数据库分区

-DWITH_FEDERATED_STORAGE_ENGINE=1 安装frderated存储引擎

-DWITH_BLACKHOLE_STORAGE_ENGINE=1 安装blackhole存储引擎

-DWITH_MYISAM_STORAGE_ENGINE=1 支持MyIASM引擎

-DWITH_ARCHIVE_STORAGE_ENGINE=1 支持archive引擎

-DENABLED_LOCAL_INFILE=1 允许从本文件导入数据

-DENABLE_DTRACE=0 是否启用dtrace

-DDEFAULT_CHARSET=utf8mb4 数据库默认字符集

-DDEFAULT_COLLATION=utf8mb4_general_ci 默认排序规则

-DWITH_EMBEDDED_SERVER=1 编译成embedded
4.编译安装

make && make install

5.修改安装目录属主属组

chown -R mysql:mysql /usr/local/mysql;
ll /usr/local/mysql/;

6.数据目录初始化

/usr/local/mysql/bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data

注:初始化完会生成随机密码,例如Sv>ruE:xh1xo为生成的随机密码

[Note] A temporary password is generated for root@localhost: Sv>ruE:xh1xo

7.添加到系统服务

cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld;
chkconfig --add mysqld;
chkconfig mysqld on;

8.修改配置文件

配置/etc/my.cnf 仅供参考。

mv /etc/my.cnf /etc/my.cnf.bak;
tee -a  /etc/my.cnf <<-'EOF'
[client]
port        = 3306
socket      = /tmp/mysql.sock
[mysqld]
port        = 3306
socket      = /tmp/mysql.sock
basedir = /usr/local/mysql 
datadir = /usr/local/mysql/data 
character-set-server=utf8 
collation-server=utf8_general_ci 
skip-external-locking 
key_buffer_size = 128M 
max_allowed_packet = 32M 
table_open_cache = 512
net_buffer_length = 8K
sort_buffer_size = 2M 
read_buffer_size = 16M 
read_rnd_buffer_size = 160M 
myisam_sort_buffer_size = 32M 
thread_cache_size = 64 
query_cache_size= 64M
tmp_table_size = 64M
max_connections = 5000
max_user_connections = 5000
max_connect_errors = 6000
wait_timeout = 30 
interactive_timeout = 30 
long_query_time = 1 
log-bin=mysql-bin
binlog_format=mixed
server-id   = 1
expire_logs_days = 10
early-plugin-load = ""

default_storage_engine = InnoDB
innodb_file_per_table = 1
innodb_data_home_dir = /usr/local/mysql/data
innodb_data_file_path = ibdata1:10M:autoextend
innodb_log_group_home_dir = /usr/local/mysql/data
innodb_buffer_pool_size = 512M
innodb_log_file_size = 128M
innodb_log_buffer_size = 8M
innodb_flush_log_at_trx_commit = 1
innodb_lock_wait_timeout = 50

[mysqldump]
quick
max_allowed_packet = 32M
[mysql]
no-auto-rehash

[myisamchk]
key_buffer_size = 128M
sort_buffer_size = 2M
read_buffer = 2M
write_buffer = 2M

[mysqlhotcopy]
interactive-timeout
EOF

9.启动服务

/etc/init.d/mysqld start

10.添加链接

ln -sf /usr/local/mysql/bin/mysql /usr/bin/mysql;
ln -sf /usr/local/mysql/bin/mysqldump /usr/bin/mysqldump;
ln -sf /usr/local/mysql/bin/myisamchk /usr/bin/myisamchk;
ln -sf /usr/local/mysql/bin/mysqld_safe /usr/bin/mysqld_safe;
ln -sf /usr/local/mysql/bin/mysqlcheck /usr/bin/mysqlcheck;

11.登录并修改密码

 mysql -u root -p
mysql> set password =password('Admin@123');

avatar

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: