[Mysql] 一台服务器安装多个mysql数据库程序


本文总阅读量

1、已安装第一个mysql程序的相关信息:

1
2
3
端口:3306
目录:/data/mysql/
配置文件:/etc/my.cnf

2、新建用于第二个mysql程序的目录:

1
mkdir -p /data/twomysql

将安装包解压到twomysql目录(下载地址https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz)

1
2
3
tar -zxvf mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz -C /data/twomysql
cd /data/twomysql
mv mysql-5.7.22-linux-glibc2.12-x86_64 twomysql

创建相关数据、日志、配置文件目录:

1
2
3
4
5
6
7
8
9
10
mkdir -p /data/twomysql/twomysql/log
touch /data/twomysql/twomysql/log/mysqld.log
chown -R mysql.mysql /data/twomysql/twomysql/log
mkdir -p /data/twomysql/twomysql/data
chown -R mysql.mysql /data/twomysql/twomysql/data
mkdir -p /data/twomysql/twomysql/tmp
chown -R mysql.mysql /data/twomysql/twomysql/tmp
mkdir -p /data/twomysql/twomysql/etc
chown -R mysql.mysql /data/twomysql/twomysql/etc
cd /data/twomysql/twomysql/etc

配置文件信息如下,端口设为3307,目录设置跟上面创建的目录匹配:
vim my.cnf

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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
[client]
port = 3307
socket = /data/twomysql/twomysql/tmp/mysql.sock
[mysql]
prompt="\u@db \R:\m:\s [\d]> "
no-auto-rehash
[mysqld]
user = mysql
port = 3307
basedir = /data/twomysql/twomysql
datadir = /data/twomysql/twomysql/data
socket = /data/twomysql/twomysql/tmp/mysql.sock
pid-file = /data/twomysql/twomysql/tmp/mysql.pid
character-set-server = utf8mb4
skip_name_resolve = 1
open_files_limit = 65535
back_log = 1024
max_connections = 2000
max_connect_errors = 100
net_read_timeout = 30
net_write_timeout = 60
slave_net_timeout = 90
table_open_cache = 1024
table_definition_cache = 1024
table_open_cache_instances = 64
thread_stack = 512K
external-locking = FALSE
max_allowed_packet = 32M
sort_buffer_size = 4M
join_buffer_size = 4M
thread_cache_size = 768
query_cache_size = 0
query_cache_type = 0
interactive_timeout = 600
wait_timeout = 600
tmp_table_size = 32M
max_heap_table_size = 32M
slow_query_log = 1
slow_query_log_file = /data/twomysql/twomysql/log/slow.log
log-error = /data/twomysql/twomysql/log/error.log
long_query_time = 0.1
server-id = 3306101
log-bin = /data/twomysql/twomysql/log/mysql-binlog
sync_binlog = 1
binlog_cache_size = 4M
max_binlog_cache_size = 1G
max_binlog_size = 1G
expire_logs_days = 7
gtid_mode = on
enforce_gtid_consistency = 1
log_slave_updates
binlog_format = row
relay_log_recovery = 1
relay-log = relay-log
relay-log-purge = 1
key_buffer_size = 32M
read_buffer_size = 8M
read_rnd_buffer_size = 4M
bulk_insert_buffer_size = 64M
lock_wait_timeout = 60
explicit_defaults_for_timestamp = 1
innodb_thread_concurrency = 0
innodb_sync_spin_loops = 100
innodb_spin_wait_delay = 30
transaction_isolation = REPEATABLE-READ
innodb_buffer_pool_size = 2048M
innodb_buffer_pool_instances = 8
innodb_buffer_pool_load_at_startup = 1
innodb_buffer_pool_dump_at_shutdown = 1
innodb_data_file_path = ibdata1:1G:autoextend
innodb_flush_log_at_trx_commit = 1
innodb_log_buffer_size = 32M
innodb_log_file_size = 1G
innodb_log_files_in_group = 3
innodb_max_undo_log_size = 4G
innodb_io_capacity = 4000
innodb_io_capacity_max = 8000
innodb_flush_neighbors = 0
innodb_write_io_threads = 8
innodb_read_io_threads = 8
innodb_purge_threads = 4
innodb_page_cleaners = 4
innodb_open_files = 65535
innodb_max_dirty_pages_pct = 50
innodb_flush_method = O_DIRECT
innodb_lru_scan_depth = 4000
innodb_checksum_algorithm = crc32
innodb_lock_wait_timeout = 30
innodb_rollback_on_timeout = 1
innodb_print_all_deadlocks = 1
innodb_file_per_table = 1
innodb_online_alter_log_max_size = 4G
internal_tmp_disk_storage_engine = InnoDB
innodb_stats_on_metadata = 0
innodb_status_file = 1
innodb_status_output = 0
innodb_status_output_locks = 0
performance_schema = 1
performance_schema_instrument = '%=on'
lower_case_table_names = 1
explicit_defaults_for_timestamp = off
sql_mode = STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
[mysqldump]
quick
max_allowed_packet = 32M
[mysql.server]
basedir=/data/twomysql/twomysql

3、初始化数据库

1
2
3
sudo mkdir /data/twomysql/twomysql/mysql-files
sudo chown mysql:mysql /data/twomysql/twomysql/mysql-files
sudo chmod 750 /data/twomysql/twomysql/mysql-files

设置无密码登录,在后面在重新创建密码:

1
2
/data/twomysql/twomysql/bin/mysqld  --defaults-file=/data/twomysql/twomysql/etc/my.cnf --initialize-insecure --user=mysql 
sudo /data/twomysql/twomysql/bin/mysql_ssl_rsa_setup

4、初始化完成之后,启动数据库:

1
/data/twomysql/twomysql/bin/mysqld_safe --defaults-file=/data/twomysql/twomysql/etc/my.cnf &


5、修改用户密码

1
/data/twomysql/twomysql/bin/mysqladmin -u root -P 3307  -S /data/twomysql/twomysql/tmp/mysql.sock password 123456

6、登录mysql,需要输入密码:

1
/data/twomysql/twomysql/bin/mysql --socket=/data/twomysql/twomysql/tmp/mysql.sock --port=3307 -p
目录
  1. 1. 1、已安装第一个mysql程序的相关信息:
  2. 2. 2、新建用于第二个mysql程序的目录:
  3. 3. 3、初始化数据库
  4. 4. 4、初始化完成之后,启动数据库:
  5. 5. 5、修改用户密码
  6. 6. 6、登录mysql,需要输入密码:

Proudly powered by Hexo and Theme by Lap
本站访客数人次
© 2020 zeven0707's blog