扫二维码与项目经理沟通
我们在微信上24小时期待你的声音
解答本文疑问/技术咨询/运营咨询/技术建议/互联网交流
一般情况下是1-4个实例,1-2个居多
我们注重客户提出的每个要求,我们充分考虑每一个细节,我们积极的做好做网站、网站设计服务,我们努力开拓更好的视野,通过不懈的努力,成都创新互联赢得了业内的良好声誉,这一切,也不断的激励着我们更好的服务客户。 主要业务:网站建设,网站制作,网站设计,小程序定制开发,网站开发,技术开发实力,DIV+CSS,PHP及ASP,ASP.Net,SQL数据库的技术开发工程师。
一、安装环境
二、多实例添加(安装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配置文件中参数名字改动或删减
我们在微信上24小时期待你的声音
解答本文疑问/技术咨询/运营咨询/技术建议/互联网交流