1 安装数据库(略)
2 初始化数据库 3306 3307 两个实例
[root@localhost] /Data/apps/mysql/scripts/mysql_install_db --basedir=/Data/apps/mysql --datadir=/Data/data/dbdata_3306 --user=mysql [root@localhost] /Data/apps/mysql/scripts/mysql_install_db --basedir=/Data/apps/mysql --datadir=/Data/data/dbdata_3307 --user=mysql
3 创建配置数据库配置文件
3306配置文件
[client] port = 3306 socket = /Data/data/dbdata_3306/mysql.sock [mysqld] datadir=/Data/data/dbdata_3306/ skip-name-resolve lower_case_table_names=1 innodb_file_per_table=1 port = 3306 pid-file = /Data/data/dbdata_3306/mysql.pid socket = /Data/data/dbdata_3306/mysql.sock 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
3307 配置文件
[client] port = 3307 socket = /Data/data/dbdata_3307/mysql.sock [mysqld] datadir=/Data/data/dbdata_3307/ skip-name-resolve lower_case_table_names=1 innodb_file_per_table=1 port = 3307 pid-file = /Data/data/dbdata_3307/mysql.pid socket = /Data/data/dbdata_3307/mysql.sock 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
4 创建启动文件
3306实例的mysqld (/Data/data/dbdata_3306/mysqld)
#!/bin/bash mysql_port=3306 mysql_username="root" mysql_password="123456" function_start_mysql() { printf "Starting MySQL...\n" /bin/sh /Data/apps/mysql/bin/mysqld_safe --defaults-file=/Data/data/dbdata_${mysql_port}/my.cnf 2>&1 > /dev/null & } function_stop_mysql() { printf "Stoping MySQL...\n" /Data/apps/mysql/bin/mysqladmin -u ${mysql_username} -p${mysql_password} -S /Data/data/dbdata_${mysql_port}/mysql.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/data/dbdata_${mysql_port}/mysqld {start|stop|restart|kill}";; esac
3307实例的mysqld (/Data/data/dbdata_3307/mysqld)修改下mysql_port=3307即可。
启动两个实例
/Data/data/mysql/data3306/mysqld start
/Data/data/mysql/data3307/mysqld start
分别设置root密码
/Data/apps/mysql/bin/mysqladmin -uroot password -S /Data/data/dbdata_3306/mysql.sock
/Data/apps/mysql/bin/mysqladmin -uroot password -S /Data/data/dbdata_3307/mysql.sock
登录测试(创建所需用户)
/Data/apps/mysql/bin/mysql -uroot -p123456 -S /Data/data/dbdata_3306/mysql.sock
/Data/apps/mysql/bin/mysql -uroot -p123456 -S /Data/data/dbdata_3307/mysql.sock
......