设为首页 收藏本站
查看: 813|回复: 0

[经验分享] msyql5.6双mysql安装以及简单优化

[复制链接]
累计签到:2 天
连续签到:1 天
发表于 2016-1-18 10:38:18 | 显示全部楼层 |阅读模式
注意事项:
只要做到以下4点,2个mysql就可以同时安装到一台机器ps:可以举一反三,一台机器只要你的负载够的话,想安装几个都可以。下面以2个为例:
我的测试服务器配置为2个6核cpu 48g内存 4t硬盘,安装主从测试之后10w的并发基本是上限。
2个mysql安装到一台服务器
1.socket文件不同
2.data文件不同
3.配置文件不同
4.mysql端口不同
安装步骤:
第一个mysql5.6正常安装:
groupadd mysql
useradd -s /sbin/nologin -M -g mysql mysql
tar -zxvf mysql-5.6.25.tar.gz
cd mysql-5.6.25
cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DEXTRA_CHARSETS=all -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_READLINE=1 -DWITH_SSL=system -DWITH_ZLIB=system -DWITH_EMBEDDED_SERVER=1 -DENABLED_LOCAL_INFILE=1
cp support-files/my-default.cnf /etc/my.cnf
vi /etc/my.cnf
#加入优化的mysql配置:
###查看mysql innodb 5.5版本 show engine innodb status\G;
###注意:innodb 一定要在初始化之前加入配置文件
###5.6版本需要去掉#log_slow_queries=/usr/local/mysql/slow-log.log
###需要chmod 777 /tmp

[client]
#password = your_password
port  = 3306
socket  = /tmp/mysql.sock
# Here follows entries for some specific programs
# The MySQL server
[mysqld]
port  = 3306
socket  = /tmp/mysql.sock
skip-external-locking
max_allowed_packet = 32M
table_open_cache = 2048
net_buffer_length = 1M
character-set-server = utf8
skip-name-resolve
ft_min_word_len = 4

####  performance  ####
open_files_limit = 10240
max_connections = 800
max_connect_errors = 6000
thread_stack = 192K
transaction_isolation = REPEATABLE-READ
tmp_table_size = 256M
max_heap_table_size = 256M
slow_query_log
long_query_time = 1
#log_slow_queries=/usr/local/mysql/slow-log.log
net_buffer_length = 1M
#### log ####
log-error=/usr/local/mysql/mysqld.err
back_log = 500
max_binlog_cache_size = 8M
max_binlog_size = 512M
binlog_format=mixed
expire_logs_days = 7
####  buffer && cache  ####
read_buffer_size = 10M
read_rnd_buffer_size = 32M
sort_buffer_size = 2M
join_buffer_size = 2M
thread_cache_size = 300
thread_concurrency = 8
query_cache_size = 64M
query_cache_limit = 4M
binlog_cache_size = 4M
key_buffer_size = 32M
bulk_insert_buffer_size = 64M
####  myisam  ####
myisam_sort_buffer_size = 128M
myisam_max_sort_file_size = 10G
myisam_repair_threads = 1
myisam_recover
log-bin=mysql-bin
server-id = 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 = 1G
innodb_additional_mem_pool_size = 16M
innodb_log_file_size = 150M
innodb_log_buffer_size = 16M
innodb_flush_log_at_trx_commit =2
innodb_lock_wait_timeout = 60
innodb_flush_method = O_DIRECT
innodb_open_files  =   800
innodb_file_per_table=1
innodb_file_io_threads=4
[mysqldump]
quick
max_allowed_packet = 32M
[mysql]
no-auto-rehash
# Remove the next comment character if you are not familiar with SQL
#safe-updates
[myisamchk]
key_buffer_size = 32M
sort_buffer_size = 32M
read_buffer = 8M
write_buffer = 8M
[mysqlhotcopy]
interactive-timeout
[mysqld_safe]
open-files-limit = 8196
#修改目录权限:
cd /usr/local/mysql/
chown -R mysql .
chgrp -R mysql .
初始化mysql:
/usr/local/mysql/scripts/mysql_install_db --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --user=mysql --defaults-file=/etc/my.cnf
启动mysql:
/usr/local/mysql/bin/mysqld_safe  --defaults-file=/etc/my.cnf --user=mysql&
登录:
/usr/local/mysql/bin/mysql -u root -p
/usr/local/mysql/bin/mysqladmin -u root -p shutdown
/usr/local/mysql/bin/mysqladmin --socket=/tmp/mysql1.sock -u root password  xxx 修改密码
授权远程连接:
grant all privileges on   *.* to root@"%" identified by 'xxx' with grant option;
flush privileges ;
第二个mysql:
#需要知道不同的配置文件,data文件和scoket文件名不同
tar -zxvf mysql-5.6.25.tar.gz
cd mysql-5.6.25
注意:
安装位置不能相同,这里指定为/usr/local/3307与前面的mysql区分开

cmake -DCMAKE_INSTALL_PREFIX=/usr/local/3307 -DEXTRA_CHARSETS=all -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_READLINE=1 -DWITH_SSL=system -DWITH_ZLIB=system -DWITH_EMBEDDED_SERVER=1 -DENABLED_LOCAL_INFILE=1
make && make install
cp support-files/my-default.cnf /usr/local/3307/my.cnf

vi /usr/local/3307/my.cnf
#加入优化的mysql配置:

###查看mysql innodb 5.5版本 show engine innodb status\G;
###注意:innodb 一定要在初始化之前加入配置文件
###5.6版本需要去掉#log_slow_queries=/usr/local/mysql/slow-log.log
###需要chmod 777 /tmp

[client]
#password = your_password
port  = 3307  ##修改mysql的端口文件不要和以前那个重名
socket  = /tmp/mysql1.sock   ##修改mysql的socket文件不要和以前那个重名
# Here follows entries for some specific programs
# The MySQL server
[mysqld]
port  = 3307   ##修改mysql的端口文件不要和以前那个重名
socket  = /tmp/mysql1.sock  ##修改mysql的socket文件不要和以前那个重名
skip-external-locking
max_allowed_packet = 32M
table_open_cache = 2048
net_buffer_length = 1M
character-set-server = utf8
skip-name-resolve
ft_min_word_len = 4

####  performance  ####
open_files_limit = 10240
max_connections = 800
max_connect_errors = 6000
thread_stack = 192K
transaction_isolation = REPEATABLE-READ
tmp_table_size = 256M
max_heap_table_size = 256M
slow_query_log
long_query_time = 1
#log_slow_queries=/usr/local/mysql/slow-log.log
net_buffer_length = 1M
#### log ####
log-error=/usr/local/mysql/mysqld.err
back_log = 500
max_binlog_cache_size = 8M
max_binlog_size = 512M
binlog_format=mixed
expire_logs_days = 7
####  buffer && cache  ####
read_buffer_size = 10M
read_rnd_buffer_size = 32M
sort_buffer_size = 2M
join_buffer_size = 2M
thread_cache_size = 300
thread_concurrency = 8
query_cache_size = 64M
query_cache_limit = 4M
binlog_cache_size = 4M
key_buffer_size = 32M
bulk_insert_buffer_size = 64M
####  myisam  ####
myisam_sort_buffer_size = 128M
myisam_max_sort_file_size = 10G
myisam_repair_threads = 1
myisam_recover
log-bin=mysql-bin
server-id = 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 = 1G
innodb_additional_mem_pool_size = 16M
innodb_log_file_size = 150M
innodb_log_buffer_size = 16M
innodb_flush_log_at_trx_commit =2
innodb_lock_wait_timeout = 60
innodb_flush_method = O_DIRECT
innodb_open_files  =   800
innodb_file_per_table=1
innodb_file_io_threads=4
[mysqldump]
quick
max_allowed_packet = 32M
[mysql]
no-auto-rehash
# Remove the next comment character if you are not familiar with SQL
#safe-updates
[myisamchk]
key_buffer_size = 32M
sort_buffer_size = 32M
read_buffer = 8M
write_buffer = 8M
[mysqlhotcopy]
interactive-timeout
[mysqld_safe]
open-files-limit = 8196
修改权限:
cd /usr/local/mysql/
chown -R mysql .
chgrp -R mysql .
初始化mysql:
/usr/local/mysql/scripts/mysql_install_db --basedir=/usr/local/3307 --datadir=/usr/local/3307/data --user=mysql --defaults-file=/usr/local/3307/my.cnf
vi /usr/local/3307/my.cnf
重新加入mysql优化文件内容,初始化之后配置文件被重置
制定配置文件启动mysql:
/usr/local/mysql/bin/mysqld_safe  --defaults-file=/usr/local/3307/my.cnf --user=mysql&
登录:
/usr/local/3307/bin/mysql --socket=/tmp/mysql1.sock (无密码)
/usr/local/3307/bin/mysqladmin --socket=/tmp/mysql1.sock -u root password xxxx(设置密码为xxxx)
/usr/local/3307/bin/mysql --socket=/tmp/mysql1.sock  -u root -p (有密码登录)
/usr/local/3307/bin/mysqladmin --socket=/tmp/mysql1.sock -u root shutdown -p(关闭)
/usr/local/3307/bin/mysqld_safe --defaults-file=/usr/local/3307/my.cnf --user=mysql&
/usr/local/mysql/bin/mysqladmin --socket=/tmp/mysql1.sock -u root password  xxx 修改密码
授权远程连接:
grant all privileges on   *.* to root@"%" identified by 'xxxxx' with grant option;
flush privileges ;


运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.iyunv.com/thread-165975-1-1.html 上篇帖子: MySQL单表查询之分组查询 下篇帖子: percona-toolkit工具检查mysql复制一致性及修复不一致性 mysql
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表