linux下mysql5.5&mysql5.6的tar该怎么搭建
这篇文章给大家介绍linux下mysql5.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 = 3306socket = /data/mysql/mysql.sock#default-character-set=utf8[mysql]prompt = "mysql [\d]>\_"#default-character-set=utf8[mysqld]port = 3306socket = /data/mysql/mysql.sockbasedir = /usr/local/mysqldatadir = /data/mysqlopen_files_limit = 3072back_log = 103max_connections = 512max_connect_errors = 100000table_open_cache = 512external-locking = FALSEmax_allowed_packet = 32Msort_buffer_size = 2Mjoin_buffer_size = 2Mthread_cache_size = 51query_cache_size = 32Mtmp_table_size = 96Mmax_heap_table_size = 96Mslow_query_log = 1slow_query_log_file = /data/mysql/slow.loglog-error = /data/mysql/error.loglong_query_time = 2event_scheduler = 1 lower_case_table_names = 1log-bin-trust-function-creators=1server-id = 1log-bin = /data/mysql/mysql-binsync_binlog = 1binlog_cache_size = 4Mmax_binlog_cache_size = 8Mmax_binlog_size = 1024Mexpire_logs_days = 7key_buffer_size = 32Mread_buffer_size = 1Mread_rnd_buffer_size = 16Mbulk_insert_buffer_size = 64Mcharacter-set-server=utf8default-storage-engine = InnoDBbinlog_format=row#gtid_mode=on#log_slave_updates=1#enforce_gtid_consistency=1transaction_isolation = REPEATABLE-READinnodb_additional_mem_pool_size = 16Minnodb_buffer_pool_size = 1434Minnodb_data_file_path = ibdata1:1024M:autoextendinnodb_flush_log_at_trx_commit = 1innodb_log_buffer_size = 16Minnodb_log_file_size = 256Minnodb_log_files_in_group = 2innodb_max_dirty_pages_pct = 50innodb_file_per_table = 1innodb_locks_unsafe_for_binlog = 0[mysqldump]quickmax_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@localhost data]# /usr/local/mysql/scripts/mysql_install_db --defaults-file=/etc/my.cnf --datadir=/data/mysql/ --basedir=/usr/local/mysql --user=mysqlCan't locate Data/Dumper.pm in @INC (@INC contains: /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_db line 42.BEGIN failed--compilation aborted at /usr/local/mysql/scripts/mysql_install_db line 42.解决: yum install '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=1relay-log=/data/mysql/relay-log-binrelay-log-index=/data/mysql/slave-relay-bin.indexmax_relay_log_size=300M#关闭自动删除relay-logrelay_log_purge=0
关于linux下mysql5.5&mysql5.6的tar该怎么搭建就分享到这里了,希望以上内容可以对大家有一定的帮助,可以学到更多知识。如果觉得文章不错,可以把它分享出去让更多的人看到。