学堂 学堂 学堂公众号手机端

linux下mysql5.5&mysql5.6的tar该怎么搭建

lewis 5年前 (2020-01-18) 阅读数 5 #技术
这篇文章给大家介绍linux下5.5&mysql5.6的tar该怎么搭建,内容非常详细,感兴趣的小伙伴们可以参考借鉴,希望对大家能有所帮助。

提前yum安装依赖包
yum -y install perl perl-devel libaio* 'perl(Data::Dumper)'
准备好mysql的tar包
1、在/usr/local下解压mysql的安装包,并将解压后的文件改名为mysql,其执行命令
tar zxvf mysql-5.6.16-linux-glibc2.5-x86_64.tar 解压
mv mysql-5.6.16-linux-glibc2.5-x86_64 mysql 改名
2、建立mysql用户,并赋予/usr/local/mysql目录的权限
useradd mysql 建用户
chown mysql:mysql -R mysql 赋权
3、建立数据目录,并把目录赋权给mysql用户
mkdir -p /data/mysql 建数据目录
chown mysql:mysql -R /data 赋权
查看赋权是否成功,可在其目录上以及ll查看所属用户及权限
4、配置文件
在/etc目录下新建my.cnf文件,并编辑配置文件
vim /etc/my.cnf 创建并编辑配置文件,写入以下内容
注意:以下配置中适合主库,若要对从库使用,需要注释配置中的事件event_scheduler = 1

[client]
port=3306
socket=/data/mysql/mysql.sock
#default-character-set=utf8
[mysql]
prompt="mysql[\d]>\_"
#default-character-set=utf8
[mysqld]
port=3306
socket=/data/mysql/mysql.sock
basedir=/usr/local/mysql
datadir=/data/mysql
open_files_limit=3072
back_log=103
max_connections=512
max_connect_errors=100000
table_open_cache=512
external-locking=FALSE
max_allowed_packet=32M
sort_buffer_size=2M
join_buffer_size=2M
thread_cache_size=51
query_cache_size=32M
tmp_table_size=96M
max_heap_table_size=96M
slow_query_log=1
slow_query_log_file=/data/mysql/slow.log
log-error=/data/mysql/error.log
long_query_time=2
event_scheduler=1
lower_case_table_names=1
log-bin-trust-function-creators=1
server-id=1
log-bin=/data/mysql/mysql-bin
sync_binlog=1
binlog_cache_size=4M
max_binlog_cache_size=8M
max_binlog_size=1024M
expire_logs_days=7
key_buffer_size=32M
read_buffer_size=1M
read_rnd_buffer_size=16M
bulk_insert_buffer_size=64M
character-set-server=utf8
default-storage-engine=InnoDB
binlog_format=row
#gtid_mode=on
#log_slave_updates=1
#enforce_gtid_consistency=1
transaction_isolation=REPEATABLE-READ
innodb_additional_mem_pool_size=16M
innodb_buffer_pool_size=1434M
innodb_data_file_path=ibdata1:1024M:autoextend
innodb_flush_log_at_trx_commit=1
innodb_log_buffer_size=16M
innodb_log_file_size=256M
innodb_log_files_in_group=2
innodb_max_dirty_pages_pct=50
innodb_file_per_table=1
innodb_locks_unsafe_for_binlog=0
[mysqldump]
quick
max_allowed_packet=32M

5、初始化数据库
/usr/local/mysql/scripts/mysql_install_db --defaults-file=/etc/my.cnf --basedir=/usr/local/mysql --datadir=/data/mysql/ --user=mysql


初始化报错:
[root@localhostdata]#/usr/local/mysql/scripts/mysql_install_db--defaults-file=/etc/my.cnf--datadir=/data/mysql/--basedir=/usr/local/mysql--user=mysql
Can'tlocateData/Dumper.pmin@INC(@INCcontains:/usr/local/lib64/perl5/usr/local/share/perl5/usr/lib64/perl5/vendor_perl/usr/share/perl5/vendor_perl/usr/lib64/perl5/usr/share/perl5.)at/usr/local/mysql/scripts/mysql_install_dbline42.
BEGINfailed--compilationabortedat/usr/local/mysql/scripts/mysql_install_dbline42.

解决:
yuminstall'perl(Data::Dumper)'

6、启动数据库
/bin/mysqld_safe --defaults-file=/etc/my.cnf &
或者通过cp数据库启动脚本
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
chmod +x /etc/init.d/mysqld
启动: /etc/init.d/mysqld start
关闭: /etc/init.d/mysqld stop
7、加入到开机自启
chkconfig --add mysqld
chkconfig --list mysqld 查看mysql的开启等级
chkconfig --level 0 mysqld on

8、注意配置环境变量
9、从库配置,请加上如下参数,记得注意主从的server_id不能相同

log_slave_updates=1
relay-log=/data/mysql/relay-log-bin
relay-log-index=/data/mysql/slave-relay-bin.index
max_relay_log_size=300M
#关闭自动删除relay-log
relay_log_purge=0
版权声明

本文仅代表作者观点,不代表博信信息网立场。

热门