温馨提示×

温馨提示×

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

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

Ubuntu 中怎么配置mysql

发布时间:2021-07-20 14:31:04 来源:亿速云 阅读:256 作者:Leah 栏目:系统运维

本篇文章为大家展示了Ubuntu 中怎么配置mysql,内容简明扼要并且容易理解,绝对能使你眼前一亮,通过这篇文章的详细介绍希望你能有所收获。

1. 在master上建立一个专门用来做复制的用户:grant replication slave on *.* to 'replicationuser'@'192.168.51.165' identified by '123456';

2.设置master机my.cnf:

执行sudo vim etc/Ubuntu mysql/my.cnf在[Ubuntu mysqld]区域加入以下内容:  server-id               = 1 log_bin                 = /var/log/Ubuntu mysql/Ubuntu mysql-bin.log   #开启二进制日志  binlog_do_db            = testdb  #需要同步的数据库,可选  binlog_ignore_db        = Ubuntu mysql,information_schema  #

不需要同步的数据库,可选重启master服务器 sudo /etc/init.d/Ubuntu mysql restart

3.设置slave机my.cnf:

执行sudo vim etc/Ubuntu mysql/my.cnf在[Ubuntu mysqld]区域加入以下内容:server-id  = 2重启slave服务器 sudo /etc/init.d/Ubuntu mysql restart

4.刷新主服务器上所有的表和块写入语句:flush tables with read lock; 然后读取主服务器上的二进制文件名和分支:show master status;将File和Position的值记录下来。

并备份master上的数据到slave进行初始化。(flush tables with read lock是为了确保没有数据库操作),(只要记录下File和Position的值,这里就可以执行第6个步骤释放锁:Ubuntu mysql> unlock table; )

scp -r ./* root@192.168.47.175:/var/lib/Ubuntu mysql 用root***权限,更改root密码 sudo su -passwd

5.登陆slave的Ubuntu mysql,用系统真实值代替选项:

Ubuntu mysql> CHANGE MASTER TO MASTER_HOST='192.168.51.162',MASTER_USER='replicationuser',  MASTER_PASSWORD='123456',MASTER_LOG_FILE='Ubuntu mysql-bin.000001',MASTER_LOG_POS=1279702;  这里master_log_file和master_log_pos就是前面show master status的结果

6.登陆master并释放锁:Ubuntu mysql> unlock table;

7.切换到slave机,启动从线程:Ubuntu mysql> start slave;这样就完成了master/slave的配置工作。***可以用show processlist"G;来分别查看 master与slave的状态。master: 48发送binlog到slave,等待更新。

*************************** 5. row ***************************       Id: 48     User: replicationuser     Host: 192.168.51.165:43746       db: NULL  Command: Binlog Dump     Time: 767    State: Has sent all binlog to slave; waiting for binlog to be updated      Info: NULL

slave:12等待master发送更新信息。13等待本身I"O线程的数据写入

*************************** 3. row ***************************       Id: 12     User: system user     Host:       db: NULL  Command: Connect     Time: 470    State: Waiting for master to send event     Info: NULL  *************************** 4. row ***************************       Id: 13     User: system user     Host:       db: NULL  Command: Connect     Time: 359    State: Has read all relay log; waiting for the slave I/O thread to update it      Info: NULL

如果show processlist\G;可以看到上面的信息,那代表slave机建立成功。在master上所做的数据更改会马上表现到slave机。

上述内容就是Ubuntu 中怎么配置mysql,你们学到知识或技能了吗?如果还想学到更多技能或者丰富自己的知识储备,欢迎关注亿速云行业资讯频道。

向AI问一下细节

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

AI