linux下mysql5.5&mysql5.6的tar该怎么搭建
这篇文章给大家介绍linux下MySQL5.5&mysql5.6的tar该怎么搭建,内容非常详细,感兴趣的小伙伴们可以参考借鉴,希望对大家能有所帮助。
创新互联主营大安网站建设的网络公司,主营网站建设方案,重庆App定制开发,大安h5重庆小程序开发公司搭建,大安网站营销推广欢迎大安等地区企业咨询
提前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@localhost data]# /usr/local/mysql/scripts/mysql_install_db --defaults-file=/etc/my.cnf --datadir=/data/mysql/ --basedir=/usr/local/mysql --user=mysql Can'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=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
关于linux下mysql5.5&mysql5.6的tar该怎么搭建就分享到这里了,希望以上内容可以对大家有一定的帮助,可以学到更多知识。如果觉得文章不错,可以把它分享出去让更多的人看到。
新闻名称:linux下mysql5.5&mysql5.6的tar该怎么搭建
链接分享:http://cdiso.cn/article/iicjje.html