51工具盒子

依楼听风雨
笑看云卷云舒,淡观潮起潮落

mysql5.7.18多实例配置

当前实验环境默认存在3306端口的mysql并可以正常运行,在此基础上增加一个新的mysql实例并使用3307端口。

配置过程如下:

1、将默认的mysql配置文件复制一份
cp /etc/my.cnf /etc/my3307.cnf

|---|--------------------------------| | 1 | cp /etc/my.cnf /etc/my3307.cnf |

2、修改/etc/my3307.cnf(将原来3306的port、socket及相关数据路径换掉,下面是一个修改好后的my3307.cnf)
vi /etc/my3307.cnf

|---|--------------------| | 1 | vi /etc/my3307.cnf |


[client] #password = your_password port = 3307 socket = /tmp/mysql3307.sock [mysqld] port = 3307 socket = /tmp/mysql3307.sock datadir = /usr/local/mysql/var3307 skip-external-locking key_buffer_size = 16M max_allowed_packet = 1M table_open_cache = 64 sort_buffer_size = 512K net_buffer_length = 8K read_buffer_size = 256K read_rnd_buffer_size = 512K myisam_sort_buffer_size = 8M thread_cache_size = 8 query_cache_size = 8M tmp_table_size = 16M performance_schema_max_table_instances = 500 explicit_defaults_for_timestamp = true #skip-networking max_connections = 500 max_connect_errors = 100 open_files_limit = 65535 log-bin=mysql-bin binlog_format=mixed server-id = 1 expire_logs_days = 10 early-plugin-load = "" default_storage_engine = InnoDB innodb_file_per_table = 1 innodb_data_home_dir = /usr/local/mysql/var3307 innodb_data_file_path = ibdata1:10M:autoextend innodb_log_group_home_dir = /usr/local/mysql/var3307 innodb_buffer_pool_size = 16M innodb_log_file_size = 5M innodb_log_buffer_size = 8M innodb_flush_log_at_trx_commit = 1 innodb_lock_wait_timeout = 50 [mysqldump] quick max_allowed_packet = 16M [mysql] no-auto-rehash [myisamchk] key_buffer_size = 20M sort_buffer_size = 20M read_buffer = 2M write_buffer = 2M [mysqlhotcopy] interactive-timeout

|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 | [client] #password = your_password port = 3307 socket = /tmp/mysql3307.sock [mysqld] port = 3307 socket = /tmp/mysql3307.sock datadir = /usr/local/mysql/var3307 skip-external-locking key_buffer_size = 16M max_allowed_packet = 1M table_open_cache = 64 sort_buffer_size = 512K net_buffer_length = 8K read_buffer_size = 256K read_rnd_buffer_size = 512K myisam_sort_buffer_size = 8M thread_cache_size = 8 query_cache_size = 8M tmp_table_size = 16M performance_schema_max_table_instances = 500 explicit_defaults_for_timestamp = true #skip-networking max_connections = 500 max_connect_errors = 100 open_files_limit = 65535 log-bin=mysql-bin binlog_format=mixed server-id = 1 expire_logs_days = 10 early-plugin-load = "" default_storage_engine = InnoDB innodb_file_per_table = 1 innodb_data_home_dir = /usr/local/mysql/var3307 innodb_data_file_path = ibdata1:10M:autoextend innodb_log_group_home_dir = /usr/local/mysql/var3307 innodb_buffer_pool_size = 16M innodb_log_file_size = 5M innodb_log_buffer_size = 8M innodb_flush_log_at_trx_commit = 1 innodb_lock_wait_timeout = 50 [mysqldump] quick max_allowed_packet = 16M [mysql] no-auto-rehash [myisamchk] key_buffer_size = 20M sort_buffer_size = 20M read_buffer = 2M write_buffer = 2M [mysqlhotcopy] interactive-timeout |

3、接下来初始化新的数据库
/usr/local/mysql/bin/mysqld --defaults-file=/etc/my3307.cnf --initialize-insecure --user=mysql

|---|------------------------------------------------------------------------------------------------| | 1 | /usr/local/mysql/bin/mysqld --defaults-file=/etc/my3307.cnf --initialize-insecure --user=mysql |

PS:

--defaults-file=/etc/my3307.cnf #指定启动的配置文件
--initialize-insecure #初始化数据库,加上-insecure不生成随机密码,默认密码空
--user=mysql #指定用户

4、启动mysql3307数据库
/usr/local/mysql/bin/mysqld_safe --defaults-file=/etc/my3307.cnf --user=mysql &

|---|----------------------------------------------------------------------------------| | 1 | /usr/local/mysql/bin/mysqld_safe --defaults-file=/etc/my3307.cnf --user=mysql & |

5、查看端口(此时应该可以看到3307的端口了)
netstat -lntp

|---|---------------| | 1 | netstat -lntp |

6、连接mysql命令(默认密码空,直接回车)
mysql -uroot -p -S /tmp/mysql3307.sock

|---|----------------------------------------| | 1 | mysql -uroot -p -S /tmp/mysql3307.sock |

7、更改密码
/usr/local/mysql/bin/mysqladmin -u root password "blogwhsircom" -S /tmp/mysql3307.sock

|---|----------------------------------------------------------------------------------------| | 1 | /usr/local/mysql/bin/mysqladmin -u root password "blogwhsircom" -S /tmp/mysql3307.sock |

8、关闭mysql3307
/usr/local/mysql/bin/mysqladmin -u root -p -S /tmp/mysql3307.sock shutdown

|---|----------------------------------------------------------------------------| | 1 | /usr/local/mysql/bin/mysqladmin -u root -p -S /tmp/mysql3307.sock shutdown |


赞(0)
未经允许不得转载:工具盒子 » mysql5.7.18多实例配置