设为首页 收藏本站
查看: 502|回复: 0

[经验分享] MariaDB与MySQL在一台服务器同时运行

[复制链接]
累计签到:1 天
连续签到:1 天
发表于 2016-8-5 09:11:04 | 显示全部楼层 |阅读模式
[iyunv@HE3 ~]#groupadd mariadb -g 513
[iyunv@HE3 ~]#useradd-u 513 -g mariadb -s /sbin/nologin -d /home/mariadb mariadb

从MariaDB官网下载二进制安装包至/root目录,本文采用的是目前最新稳定版mariadb-10.1.16
[iyunv@HE3 ~]# tarxvf mariadb-10.1.16-linux-x86_64.tar.gz
[iyunv@HE3 ~]# mv/root/mariadb-10.1.16-linux-x86_64 /usr/local/mariadb

[iyunv@HE3 ~]#mkdir -p/data/mariadb
[iyunv@HE3 ~]#chown -Rmariadb. /data/mariadb
[iyunv@HE3 ~]#mkdir -p/log/mariadb
[iyunv@HE3 ~]#chown -Rmariadb. /log/mariadb

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
[iyunv@HE3 ~]#vi /usr/local/mariadb/my.cnf
[client]
port = 3307
socket = /tmp/mariadb.sock
default-character-set = utf8
  
[mysql]
default-character-set = utf8
  
[mysqld]
port = 3307
socket = /tmp/mariadb.sock
basedir = /usr/local/mariadb
datadir = /data/mariadb
open_files_limit = 3072
back_log = 103
max_connections = 800
max_connect_errors = 100000
table_open_cache = 512
external-locking = FALSE
max_allowed_packet = 32M
sort_buffer_size = 2M
join_buffer_size = 2M
thread_cache_size = 51
query_cache_size = 32M
tmp_table_size = 96M
max_heap_table_size = 96M
slow_query_log = 1
slow_query_log_file = /log/mariadb/slow.log
log-error = /log/mariadb/error.log
long_query_time = 1
server-id = 2503307
log-bin = /log/mariadb/mysql-bin
sync_binlog = 1
binlog_cache_size = 4M
max_binlog_cache_size = 8M
max_binlog_size = 1024M
expire_logs_days = 60
key_buffer_size = 32M
read_buffer_size = 1M
read_rnd_buffer_size = 16M
bulk_insert_buffer_size = 64M
character-set-server = utf8
default-storage-engine = InnoDB
binlog_format = row
innodb_buffer_pool_dump_at_shutdown = 1
innodb_buffer_pool_load_at_startup = 1
#binlog_rows_query_log_events = 1
explicit_defaults_for_timestamp = 1
  

transaction_isolation = REPEATABLE-READ
innodb_additional_mem_pool_size = 16M
innodb_buffer_pool_size = 512M
#innodb_data_home_dir =
innodb_data_file_path = ibdata1:1024M:autoextend
innodb_flush_log_at_trx_commit = 1
innodb_log_buffer_size = 16M
innodb_log_file_size = 512M
innodb_log_files_in_group = 2
innodb_max_dirty_pages_pct = 50
innodb_file_per_table = 1
innodb_locks_unsafe_for_binlog = 0
wait_timeout = 14400
interactive_timeout = 14400
skip-name-resolve
[mysqldump]
quick
max_allowed_packet = 32M




初始化数据库
[iyunv@HE3 ~]#/usr/local/mariadb/scripts/mysql_install_db--basedir=/usr/local/mariadb --datadir=/data/mariadb--defaults-file=/usr/local/mariadb/my.cnf --user=mariadb

拷贝启停模板至/etc/init.d/下
[iyunv@HE3 ~]#cp -rp /usr/local/mariadb/support-files/mysql.server /etc/init.d/mariadb

编辑该启停脚本变更第46、47、58行为mariadb相关目录,本文示例如下
1
2
3
4
5
6
7
8
9
10
11
12
13
14
[iyunv@HE3 ~]#vi /etc/init.d/mariadb
     46 basedir=/usr/local/mariadb
     47 datadir=/data/mariadb
     48
     49 # Default value, in seconds, afterwhich the script should timeout waiting
     50 # for server start.
     51 # Value here is overriden by value in my.cnf.
     52 # 0 means don't wait at all
     53 # Negative numbers mean to wait indefinitely
     54 service_startup_timeout=900
     55
     56 # Lock directory for RedHat / SuSE.
     57 lockdir='/var/lock/subsys'
     58 lock_file_path="$lockdir/mariadb"




第311行添加唯一参数路径,本文为--defaults-file=/usr/local/mariadb/my.cnf
1
311       $bindir/mysqld_safe --defaults-file=/usr/local/mariadb/my.cnf --datadir="$datadir" --pid-file="$mysqld_pid_file_path" "$@" >/dev/null 2>&1 &





1
2
3
4
5
6
7
8
[iyunv@HE3 ~]# ps -ef|grep mysql
root     28996  2226  0 16:50 pts/2    00:00:00 grep mysql
[iyunv@HE3 ~]# /etc/init.d/mysqld start
Starting MySQL. SUCCESS!
[iyunv@HE3 ~]# ps -ef|grep mysql
root     29008     1  0 16:51 pts/2    00:00:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/data/mysql --pid-file=/data/mysql/HE3.pid
mysql    29754 29008 13 16:51 pts/2    00:00:00 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/data/mysql --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/log/mysql/error.log --open-files-limit=3072 --pid-file=/data/mysql/HE3.pid --socket=/tmp/mysql.sock --port=3306
root     29778  2226  0 16:51 pts/2    00:00:00 grep mysql






1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
[iyunv@HE3 ~]# /usr/local/mysql/bin/mysql -uroot -p -P3306
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.6.25-log MySQL Community Server (GPL)
Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> select version();
+------------+
| version()  |
+------------+
| 5.6.25-log |
+------------+
1 row in set (0.01 sec)
mysql>









[iyunv@HE3 ~]# /etc/init.d/mariadb start
Starting MySQL SUCCESS!
1
2
3
4
5
6
[iyunv@HE3 ~]# ps -ef|grep mysql
root     29008     1  0 16:51 pts/2    00:00:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/data/mysql --pid-file=/data/mysql/HE3.pid
mysql    29754 29008  0 16:51 pts/2    00:00:00 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/data/mysql --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/log/mysql/error.log --open-files-limit=3072 --pid-file=/data/mysql/HE3.pid --socket=/tmp/mysql.sock --port=3306
root     29802     1  0 16:52 pts/2    00:00:00 /bin/sh /usr/local/mariadb/bin/mysqld_safe --defaults-file=/usr/local/mariadb/my.cnf --datadir=/data/mariadb --pid-file=/data/mariadb/HE3.pid
mariadb  30041 29802  7 16:52 pts/2    00:00:00 /usr/local/mariadb/bin/mysqld --defaults-file=/usr/local/mariadb/my.cnf --basedir=/usr/local/mariadb --datadir=/data/mariadb --plugin-dir=/usr/local/mariadb/lib/plugin --user=mariadb --log-error=/log/mariadb/error.log --open-files-limit=3072 --pid-file=/data/mariadb/HE3.pid --socket=/tmp/mariadb.sock --port=3307
root     30070  2226  0 16:52 pts/2    00:00:00 grep mysql





1
2
3
4
5
6
7
8
9
10
11
12
13
14
[iyunv@HE3 ~]# /usr/local/mariadb/bin/mysql -uroot -p -P3307
Enter password:
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MySQL connection id is 11
Server version: 5.6.25-log MySQL Community Server (GPL)
Copyright (c) 2000, 2016, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]> select version();
+-----------------+
| version()       |
+-----------------+
| 10.1.16-MariaDB |
+-----------------+
1 row in set (0.00 sec)






也可以手动启停
启动命令
[iyunv@HE3~]# /usr/local/mariadb/bin/mysqld_safe --defaults-file=/etc/mariadb.cnf--ledir=/usr/local/mariadb/bin --datadir=/data/mariadb &

停止命令
[iyunv@HE3 ~]#/usr/local/mariadb/bin/mysqladmin --defaults-file=/usr/local/mariadb/my.cnf-hlocalhost -P3307 shutdown



运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-253097-1-1.html 上篇帖子: 使用cmake在CentOS6.5安装MYSQL5.6 下篇帖子: 使用mysqlbinlog恢复数据 服务器
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表