首先安装mysql,不要启动MySQL,先配置vim /etc/my.cnf。
[mysqld_multi]mysqld = /usr/bin/mysqld_safemysqladmin = /usr/bin/mysqladminlog = /opt/testdb/logs/mysql/mysqld_multi/mysqld_multi.log[mysqld1]
datadir=/opt/testdb/mysql3306socket=/opt/testdb/mysql3306/mysql.socksymbolic-links=0skip-name-resolvedefault-time-zone='+8:00'port = 3306
secure_file_priv = /opt/testdb/mysql_datainnodb_file_per_table=1innodb_open_files=1024skip-external-lockingnet_buffer_length = 8Kmyisam_sort_buffer_size = 8Mlower_case_table_names = 1wait_timeout=1800
interactive_timeout = 1800key_buffer_size = 512M back_log = 500max_connections = 3000max_connect_errors = 6000table_open_cache = 2048max_allowed_packet = 32M join_buffer_size = 2Mthread_cache_size= 128query_cache_limit = 8Mtmp_table_size = 256Mread_buffer_size=8Msort_buffer_size=8Mbulk_insert_buffer_size = 64Minnodb_buffer_pool_size = 102400Minnodb_buffer_pool_instances = 8innodb_log_buffer_size=20Mread_rnd_buffer_size=32Mslow_query_log = 1
slow_query_log_file = /opt/testdb/logs/mysql/3306/mysqld3306_slow.loglong_query_time = 10log_queries_not_using_indexes = 1log_output = 'FILE'innodb_flush_log_at_trx_commit = 2
sync_binlog=8log-error=/opt/testdb/logs/mysql/3306/mysqld3306.log
pid-file=/var/run/mysql/mysqld3306.pidserver-id=36
binlog_ignore_db=mysqlrelay_log = relay-binlog-bin=/opt/testdb/logs/mysql/3306/mysql_R3306.log[mysqld2]
datadir=/opt/testdb/mysql3307socket=/opt/testdb/mysql3307/mysql.socksymbolic-links=0skip-name-resolvedefault-time-zone='+8:00'port = 3307
secure_file_priv = /opt/testdb/mysql_datainnodb_file_per_table=1innodb_open_files=1024skip-external-lockingnet_buffer_length = 8Kmyisam_sort_buffer_size = 8Mlower_case_table_names = 1wait_timeout=1800
interactive_timeout = 1800key_buffer_size = 512M back_log = 500max_connections = 3000max_connect_errors = 6000table_open_cache = 2048max_allowed_packet = 32M join_buffer_size = 2Mthread_cache_size= 128query_cache_limit = 8Mtmp_table_size = 256Mread_buffer_size=8Msort_buffer_size=8Mbulk_insert_buffer_size = 64Minnodb_buffer_pool_size = 20480Minnodb_log_buffer_size=20Mread_rnd_buffer_size=32Mslow_query_log = 1
slow_query_log_file = /opt/testdb/logs/mysql/3307/mysqld3307_slow.loglong_query_time = 10log_queries_not_using_indexes = 1log_output = 'FILE'innodb_flush_log_at_trx_commit = 2
sync_binlog=8log-error=/opt/testdb/logs/mysql/3307/mysqld3307.log
pid-file=/var/run/mysql/mysqld3307.pidserver-id=37
relay-log = relay-binlog-slave-updates = 1binlog_ignore_db=mysqllog-bin=/opt/testdb/logs/mysql/3307/mysql_R3307.log注意其中innodb_buffer_pool_size配置,这里使用的引擎是Innodb。
在/opt/sdb下新建mysql3306和mysql3307两个文件夹:/opt/testdb/mysql3306, /opt/testdb/mysql3307分别提权:chown -R mysql:mysql /opt/testdb/mysql3306chown -R mysql:mysql /opt/testdb/mysql3307到mysqld目录下,cd /usr/sbin初始化,执行mysqld --initialize --datadir=/opt/testdb/mysql3306 --user=mysql,保存临时密码同样执行,mysqld --initialize --datadir=/opt/testdb/mysql3307 --user=mysql,保存临时密码运行MySQL,mysqld_multi start 1-2,同时启动登陆MySQL,修改密码,mysql -uroot -p -S /opt/testdb/mysql3306/mysql.sock (或者mysql -uroot -p -P3306)登陆后修改密码:ALTER USER 'root'@'localhost' identified by '12345678';FLUSH PRIVILEGES;添加远程/登陆用户grant all PRIVILEGES on *.* totestDB@'%' identified by '12345678';查看MySQL_multi状态,mysqld_multi report关闭musqld_multi,mysqladmin -h172.16.2.64 -P3306 -uroot -p12345678 shutdown