当前实验环境默认存在3306端口的mysql并可以正常运行,在此基础上增加一个新的mysql实例并使用3307端口。
配置过程如下:
1、将默认的mysql配置文件复制一份
cp /etc/my.cnf /etc/my3307.cnf
2、修改/etc/my3307.cnf(将原来3306的port、socket及相关数据路径换掉,下面是一个修改好后的my3307.cnf)
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
3、接下来初始化新的数据库
/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 &
5、查看端口(此时应该可以看到3307的端口了)
netstat -lntp
6、连接mysql命令(默认密码空,直接回车)
mysql -uroot -p -S /tmp/mysql3307.sock
7、更改密码
/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 shutdow