一般情况下是1-4个实例,1-2个居多
让客户满意是我们工作的目标,不断超越客户的期望值来自于我们对这个行业的热爱。我们立志把好的技术通过有效、简单的方式提供给客户,将通过不懈努力成为客户在信息化领域值得信任、有价值的长期合作伙伴,公司提供的服务项目有:域名注册、虚拟空间、营销软件、网站建设、西安网站维护、网站推广。一、安装环境
二、多实例添加(安装mysql)
三、配置文件的添加
四、启动脚本的添加
五、文件权限及所属
六、配置全局路径
七、初始化数据库
八、mysql启动、关闭、登录
一、安装环境
CentOS Linux release 7.2.1511安装目录:/application/mysql
安装版本:mysql-5.7.9
二、实例的添加(安装mysql)
见博文mysql安装 https://blog.51cto.com/13006632/2457769
mkdir /data/{3306,3307}/data -p三、配置文件my.cnf的添加
[client] port = 3306 #实例端口,另一个为3307 socket = /data/3306/mysql.sock [mysql] no-auto-rehash [mysqld] user = mysql port = 3306 socket =/data/3306/mysql.sock basedir = /application/mysql datadir = /data/3306/data open_files_limit = 1024 back_log = 600 max_connections = 800 max_connect_errors = 3000 table_open_cache = 614 external-locking = FALSE max_allowed_packet = 8M sort_buffer_size = 1M join_buffer_size = 1M thread_cache_size = 100 query_cache_size = 2M query_cache_limit = 1M #default_table_type = InnoDB thread_stack =192k #transaction_isolation = READ-COMMITTED tmp_table_size = 2M max_heap_table_size = 2M long_query_time = 1 #log_long_format #log-error = /data/3306/error.log #log-slow-queries = /data/3306/slow.log pid-file = /data/3306/mysql.pid log-bin = /data/3306/mysql-bin relay-log =/data/3306/relay-bin relay-log-info-file = /data/3306/relay-log.info binlog_cache_size = 1M max_binlog_cache_size = 1M max_binlog_size = 2M expire_logs_days = 7 key_buffer_size = 16M read_buffer_size = 1M read_rnd_buffer_size = 1M bulk_insert_buffer_size = 1M #myisam_sort_buffer_size = 1M #myisam_max_extra_sort_file_size = 10G #uyisam_repair_threads = 1 #yisam_recover lower_case_table_names = 1 skip-name-resolve slave-skip-errors = 1032,1062 replicate-ignore-db = mysql server-id = 8 innodb_buffer_pool_size = 32M innodb_data_file_path = ibdata1:128M:autoextend innodb_thread_concurrency =8 innodb_flush_log_at_trx_commit = 2 innodb_log_buffer_size = 2M innodb_log_file_size = 4M innodb_log_files_in_group = 3 innodb_max_dirty_pages_pct = 90 innodb_lock_wait_timeout = 120 innodb_file_per_table = 0 [mysqldump] quick max_allowed_packet = 2M [mysqld_safe] log-error = /data/3306/mysql_3306.err pid-file = /data/3306/mysqld.pid四、mysql脚本的添加
#!/bin/sh #init port=3306 mysql_user="root" mysql_pwd="123456" CmdPath="/application/mysql/bin" mysql_sock="/data/${port}/mysql.sock" #startup function function_start_mysql() { if [ ! -e "$mysql_sock" ];then printf "Starting MySQL...\n" /bin/sh ${CmdPath}/mysqld_safe --defaults-file=/data/${port}/my.cnf 2>&1 > /dev/null & else printf "MySQL is running...\n" exit fi } #stop function function_stop_mysql() { if [ ! -e "$mysql_sock" ];then printf "MySQL is stopped...\n" exit else printf "Stoping MySQL...\n" ${CmdPath}/mysqladmin -u${mysql_user} -p${mysql_pwd} -S /data/${port}/mysql.sock shutdown fi } #restart function function_restart_mysql() { printf "Restarting MySQL...\n" function_stop_mysql sleep 2 function_start_mysql } case $1 in start) function_start_mysql ;; stop) function_stop_mysql ;; restart) function_restart_mysql ;; *) printf "Usage: /data/${port}/mysql {start|stop|restart}\n" esac特别说明:来源于老男孩教育
启动原理
/bin/sh /application/mysql/bin/mysqld_safe --defaults-file=/data/3306/my.cnf
停止原理
/application/mysq/bin/mysqladmin -uroot -poldboy -S /data/3306/mysql.sock shutdown
将my.cnf修改为3306和3307后和mysql脚本,放在/data/3306和/data/3307下
[root@mysql data]# tree . ├── 3306 │ ├── data │ ├── my.cnf │ └── mysql └── 3307 ├── data ├── my.cnf └── mysql 4 directories, 4 files五、文件权限及所属
chown -R mysql.mysql /data find /data -type f -name "mysql" |xargs chmod 700 find /data -type f -name "mysql" |xargs ls -l六、全局路径配置
echo 'export PATH=/application/mysq/bin:$PATH' >>/etc/profile tail -1 /etc/profile source /etc/profile七、初始化数据库
cd /application/mysql/ ./bin/mysqld --defaults-file=/data/3306/my.cnf --initialize --basedir=/application/mysql/ --datadir=/data/3306/data/ --user=mysql ./bin/mysqld --defaults-file=/data/3307/my.cnf --initialize --basedir=/application/mysql/ --datadir=/data/3307/data/ --user=mysql八、mysql启动、关闭、登录
/data/3307/mysql start /data/3307/mysql stop #mysql登录 mysql -S /data/3307/mysql.sock #修改密码 mysqladmin -uroot -p'password' password '123456' -S /data/3307/mysql.sock #远程登录多实例 mysql -uuser -p'password' -h292.168.1.23 -P 3307九、报错处理
报错1:
启动不起来,日志显示: 2019-12-12T17:51:06.643562Z 0 [ERROR] InnoDB: The Auto-extending innodb_system data file './ibdata1' is of a different size 768 pages (rounded down to MB) than specified in the .cnf file: initial 8192 pages, max 0 (relevant if non-zero) pages! 2019-12-12T17:51:06.643597Z 0 [ERROR] InnoDB: Plugin initialization aborted with error Generic error 2019-12-12T17:51:06.945987Z 0 [ERROR] Plugin 'InnoDB' init function returned error. 2019-12-12T17:51:06.946185Z 0 [ERROR] Plugin 'InnoDB' registration as a STORAGE ENGINE failed. 2019-12-12T17:51:06.946203Z 0 [ERROR] Failed to initialize plugins. 2019-12-12T17:51:06.946214Z 0 [ERROR] Aborting解决方法:
初始化没有加配置文件重新初始化
./bin/mysqld --initialize --defaults-file=/data/3307/my.cnf --basedir=/application/mysql/ --datadir=/data/3307/data/ --user=mysql参数顺序有问题如下:报错2报错2:
2019-12-12T18:24:10.667460Z 0 [ERROR] unknown variable 'defaults-file=/data/3307/my.cnf' 2019-12-12T18:24:10.667497Z 0 [ERROR] Aborting原因见博客:https://www.cnblogs.com/jerry-rock/p/7380922.html
解决方法,修改成如下:
./bin/mysqld --defaults-file=/data/3307/my.cnf --initialize --basedir=/application/mysql/ --datadir=/data/3307/data/ --user=mysql报错3:
2019-12-12T18:22:50.814935Z 0 [ERROR] --initialize specified but the data directory has files in it. Aborting. 2019-12-12T18:22:50.814979Z 0 [ERROR] Aborting原因:/data/3307/data/ 目录有旧的初始化文件需要删除清空。
解决方法:
rm -fr /data/3307/data/*报错4:
2019-12-12T18:29:32.841614Z 0 [ERROR] unknown variable 'table_cache=64' #改为table_open_cache 2019-12-12T18:29:32.841644Z 0 [ERROR] unknown variable 'thread_concurrency=2' #需删除 2019-12-12T19:04:17.320405Z 0 [ERROR] unknown variable 'innodb_additional_mem_pool_size=4M' #需删除 2019-12-12T19:14:21.886638Z 0 [ERROR] unknown variable 'innodb_file_io_threads=4' #需删除 2019-12-12T18:29:32.841644Z 0 [ERROR] Aborting原因见博客:https://www.cnblogs.com/putihk/p/7967829.html
mysql版本5.7,我用的my.cnf配置文件中参数名字改动或删减
另外有需要云服务器可以了解下创新互联cdcxhl.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。