温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

多实例安装mysql 5.7的示例分析

发布时间:2021-11-01 16:42:45 来源:亿速云 阅读:117 作者:小新 栏目:MySQL数据库

这篇文章主要介绍多实例安装mysql 5.7的示例分析,文中介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们一定要看完!

datadir:

mkdir -p /home/data/3306

mkdir -p /home/data/3307

mkdir -p /home/data/3308

chown -R mysql /home/data/

cd /opt/mysql

初始化mysql

./bin/mysqld --initialize --datadir=/home/data/3306 --user=mysql

./bin/mysqld --initialize --datadir=/home/data/3307 --user=mysql

./bin/mysqld --initialize --datadir=/home/data/3308 --user=mysql

启动mysql

bin/mysqld_safe --defaults-file=/opt/mysql/3306.cnf --user=mysql &

bin/mysqld_safe --defaults-file=/opt/mysql/3307.cnf --user=mysql &

bin/mysqld_safe --defaults-file=/opt/mysql/3308.cnf --user=mysql &

修改密码

注意:执行bin/mysqld --initialize的时候,日志会输出初始化的密码

关键字 A temporary password is generated for root@localhost: 

mysql> set password = password('rootroot');

mysql> flush privileges;

配置环境变量

vim  /etc/profile 添加 

export PATH=$PATH:/opt/mysql/bin

刷新环境变量

source /etc/profile

配置别名

vim /root/.bashrc

```

alias mysql3306='mysql -uroot -prootroot -P3306 --socket=/home/data/3306/mysql.sock'

alias start_mysql_3306='/opt/mysql/bin/mysqld_safe --defaults-file=/opt/mysql/3306.cnf --user=mysql &'

alias stop_mysql_3306='mysqladmin shutdown -uroot -p"rootroot" --socket=/home/data/3306/mysql.sock'

alias mysql3307='mysql -uroot -prootroot -P3307 --socket=/home/data/3307/mysql.sock'

alias start_mysql_3307='/opt/mysql/bin/mysqld_safe --defaults-file=/opt/mysql/3307.cnf --user=mysql &'

alias stop_mysql_3307='mysqladmin shutdown -uroot -p"rootroot" --socket=/home/data/3307/mysql.sock'

alias mysql3308='mysql -uroot -prootroot -P3308 --socket=/home/data/3308/mysql.sock'

alias start_mysql_3308='/opt/mysql/bin/mysqld_safe --defaults-file=/opt/mysql/3308.cnf --user=mysql &'

alias stop_mysql_3308='mysqladmin shutdown -uroot -p"rootroot" --socket=/home/data/3308/mysql.sock'

```

建立主从

change master to 

MASTER_HOST="192.168.64.52",

MASTER_USER="root",

MASTER_PASSWORD="rootroot",

MASTER_PORT=3306, 

MASTER_CONNECT_RETRY=10, 

MASTER_AUTO_POSITION = 1;

编辑 /opt/mysql/3306.cnf

```

[mysql]

prompt = "\u@master \R:\m:\s [\d]> "

[client]

port  = 3306

socket = /data/mysql/data/mysql.sock

[mysqld]

datadir=/home/data/3306

socket=/home/data/3306/mysql.sock

skip-name-resolve

symbolic-links=0

log_bin = binlog

binlog_format= ROW

slow_query_log = 1

slow_query_log_file = slow.log

log-error = error.log

innodb_buffer_pool_size =512MB

innodb_buffer_pool_instances = 1

[mysqld_safe]

log-error=/home/data/3306/mysqld-err.log

```

编辑 /opt/mysql/3307.cnf

```

[mysql]

prompt = "\u@3307\R:\m:\s [\d]> "

[client]

port  =3307

socket = /data/mysql/data/mysql.sock

[mysqld]

datadir=/home/data/3307

socket=/home/data/3307/mysql.sock

skip-name-resolve

symbolic-links=0

log_bin = binlog

binlog_format= ROW

slow_query_log = 1

slow_query_log_file = slow.log

log-error = error.log

innodb_buffer_pool_size =512MB

innodb_buffer_pool_instances = 1

```

编辑 /opt/mysql/3308.cnf

```

[mysql]

prompt = "\u@3308\R:\m:\s [\d]> "

[client]

port  =3308

socket = /data/mysql/data/mysql.sock

[mysqld]

datadir=/home/data/3308

socket=/home/data/3308/mysql.sock

skip-name-resolve

symbolic-links=0

log_bin = binlog

binlog_format= ROW

slow_query_log = 1

slow_query_log_file = slow.log

log-error = error.log

innodb_buffer_pool_size =512MB

innodb_buffer_pool_instances = 1

```

以上是“多实例安装mysql 5.7的示例分析”这篇文章的所有内容,感谢各位的阅读!希望分享的内容对大家有帮助,更多相关知识,欢迎关注亿速云行业资讯频道!

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI