- 工信部备案号 滇ICP备05000110号-1
- 滇公安备案 滇53010302000111
- 增值电信业务经营许可证 B1.B2-20181647、滇B1.B2-20190004
- 云南互联网协会理事单位
- 安全联盟认证网站身份V标记
- 域名注册服务机构许可:滇D3-20230001
- 代理域名注册服务机构:新网数码
环境centos7.4
一.首先编译安装mysql5.6
1.yum install cmake
2.yum install gcc gcc-c++ autoconf* automake* zlib* libxml* ncurses-devel* libgcrypt* libtool*
3.mysql下载地址:
http://www.landui.com/get/Downloads/MySQL-5.6/mysql-5.6.33.tar.gz
tat –zxvf mysql-5.6.33.tar.gz
cd mysql-5.6.3
3
cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/usr/local/mysql/data -DSYSCONFDIR=/usr/local/mysql/etc -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_MEMORY_STORAGE_ENGINE=1 -DWITH_READLINE=1 -DMYSQL_UNIX_ADDR=/var/lib/mysql/mysql.sock -DMYSQL_TCP_PORT=3306 -DENABLED_LOCAL_INFILE=1 -DWITH_PARTITION_STORAGE_ENGINE=1 -DEXTRA_CHARSETS=all -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci
make && make install
4.创建mysql用户和组
cat /etc/passwd 查看用户列表
cat /etc/group 查看用户组列表
如果没有则创建
groupadd mysql
useradd -g mysql mysql
5.chown -R mysql:mysql /usr/local/mysql
6.初始化mysql
cd /usr/local/mysql scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
7.启动
cp support-files/my-medium.cnf /etc/my.cnf cp support-files/mysql.server /etc/init.d/mysqld chkconfig mysqld on service mysqld start
8.添加path
#vi /etc/profile 在末尾输入:
PATH=/usr/local/mysql/bin:$PATH export PATH
#source /etc/profile 立即生效
9.设置密码
#mysql mysql>update mysql.user set password=password("xxxxxx") where user="root"; mysql>flush privileges; mysql>quit;
10.测试登陆
二.设置多实例
1.多实例的基本要求
配置文件安装路径不能相同
数据库目录不能相同
启动脚本不能同名
端口不能相同
socket文件的生成路径不能相同
2.由于多实例启动路径等不能相同所以创建不同目录
[root@localhost home]# mkdir /home/multimysql [root@localhost home]# mkdir /home/multimysql/{etc,socket,bin,datadir} [root@localhost home]#mkdir /home/multimysql/datadir/{3307,3308}
3.设置权限
[root@localhost home]#chown –R mysql:myql /home/multimysql [root@localhost home]#chmod 755 /home/multimysql
4.实例初始化
/usr/local/mysql/scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/home/multimysql/datadir/3307
5.创建实例的配置文件
先创建一个公用配置文件:
mkdir /home/multiMysql/etc/my.cnf.d/ vi /home/multiMysql/etc/my.cnf.d/my.cnf
然后输入公用的内容:
[mysqld] skip-name-resolve lower_case_table_names=1 innodb_file_per_table=1 back_log = 50 max_connections = 300 max_connect_errors = 1000 table_open_cache = 2048 max_allowed_packet = 16M binlog_cache_size = 2M max_heap_table_size = 64M sort_buffer_size = 2M join_buffer_size = 2M thread_cache_size = 64 thread_concurrency = 8 query_cache_size = 64M query_cache_limit = 2M ft_min_word_len = 4 default-storage-engine = innodb thread_stack = 192K transaction_isolation = REPEATABLE-READ tmp_table_size = 64M log-bin=mysql-bin binlog_format=mixed slow_query_log long_query_time = 1 server-id = 1 key_buffer_size = 8M read_buffer_size = 2M read_rnd_buffer_size = 2M bulk_insert_buffer_size = 64M myisam_sort_buffer_size = 128M myisam_max_sort_file_size = 10G myisam_repair_threads = 1 myisam_recover innodb_additional_mem_pool_size = 16M innodb_buffer_pool_size = 200M innodb_data_file_path = ibdata1:10M:autoextend innodb_file_io_threads = 8 innodb_thread_concurrency = 16 innodb_flush_log_at_trx_commit = 1 innodb_log_buffer_size = 16M innodb_log_file_size = 512M innodb_log_files_in_group = 3 innodb_max_dirty_pages_pct = 60 innodb_lock_wait_timeout = 120 [mysqldump] quick max_allowed_packet = 256M [mysql] no-auto-rehash prompt=\\u@\\d \\R:\\m> [myisamchk] key_buffer_size = 512M sort_buffer_size = 512M read_buffer = 8M write_buffer = 8M [mysqlhotcopy] interactive-timeout [mysqld_safe] open-files-limit = 8192
然后分别创建实例的配置文件:
root@localhost etc]# vim 3307.cnf
[client] port = 3307 socket = /home/multimysql/socket/mysql3307.sock [mysqld] datadir=/home/multimysql/datadir/3307 port = 3307 socket = /home/multimysql/socket/mysql3307.sock !includedir /home/multimysql/etc/my.cnf.d
然后把3307.cnf复制两份命名为3308.cnf
然后分别编辑复制的两份配置文件,把端口和socket进行修改:
6. 然后我们来编辑2个启动脚本:
[root@localhost bin]# vim /home/multimysql/bin/mysql3307
#!/bin/bash mysql_port=3307 mysql_username="root" mysql_password="" function_start_mysql() { printf "Starting MySQL...\n" mysqld_safe --defaults-file=/home/multimysql/etc/${mysql_port}.cnf 2>&1 > /dev/null & } function_stop_mysql() { printf "Stoping MySQL...\n" mysqladmin -u ${mysql_username} -p${mysql_password} -S /home/multimysql/socket/mysql${mysql_port}.sock shutdown } function_restart_mysql() { printf "Restarting MySQL...\n" function_stop_mysql function_start_mysql } function_kill_mysql() { kill -9 $(ps -ef | grep 'bin/mysqld_safe' | grep ${mysql_port} | awk '{printf $2}') kill -9 $(ps -ef | grep 'libexec/mysqld' | grep ${mysql_port} | awk '{printf $2}') } case $1 in start) function_start_mysql;; stop) function_stop_mysql;; kill) function_kill_mysql;; restart) function_stop_mysql function_start_mysql;; *) echo "Usage: /data/dbdata_${mysql_port}/mysqld {start|stop|restart|kill}";; esac
7.尝试打开实例
[root@localhost bin]# /home/multimysql/bin/mysql3307 start
查看是否有进程
链接实例
mysql -uroot -S /home/multimysql/socket/mysql3307.sock
8.其他实例参考3307,3308
售前咨询
售后咨询
备案咨询
二维码
TOP