Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to install and configure MySQL Service

2025-01-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

This article is mainly about how to install and configure MySQL services. If you are interested, let's take a look at this article. I believe it is of some reference value to you after reading how to install and configure MySQL services.

For the convenience of doing the experiment, we configure two MySQL services on the same machine (run two ports)

Cd / usr/local/; cp-r mysql mysql_2; cd mysql_2

Initialize mysql2:. / scripts/mysql_install_db-- user=mysql-- datadir=/data/mysql2

Copy the configuration file: cp / etc/my.cnf. / my.cnf

Modify configuration file related parameters: vim my.cnf # change port and socket

Start: / usr/local/mysql_2/bin/mysqld_safe-- defaults-file=/usr/local/mysql_2/my.cnf-- user=mysql &

If you boot it, you need to add it to / etc/rc.local.

Configure master-slave preparation work

Set mysql_2 master port 3307 and MySQL to slave port 3306

Create a test library on the master: create database db1

Then export the main mysql library data and import it to db1

Mysqldump-uroot-S / tmp/mysql2.sock mysql > 123.sql

Mysql-uroot-S / tmp/mysql2.sock db1

< 123.sql 配置主(master) vim /usr/local/mysql_2/my.cnf #修改或添加: server-id=1 log-bin=mysql-bin 两个可选参数(2选1): binlog-do-db=db1,db2 #需要同步的库 binlog-ignore-db=db1,db2 #忽略不同步的库 修改配置文件后,重启mysql_2 pid=ps uax |grep mysql2.sock |grep -v grep |awk '{print $2}' ; kill $pid; cd /usr/local/mysql_2/bin/; ./mysqld_safe --defaults-file=../my.cnf --user=mysql & 设置root密码:mysqladmin -u root -S /tmp/mysql2.sock password '123456' mysql -u root -S /tmp/mysql2.sock -p'123456' grant replication slave on . to 'repl'@'127.0.0.1' identified by '123123'; flush tables with read lock; show master status; #一定要记住前两列的内容,一会会用到 设置从(slave) vim /etc/my.cnf #修改或增加 server-id = 2 #这个数值不能和主一样 可选参数:replicate-do-db=db1,db2 和 replicate-ignore-db=db1,db2 #意义同主的那两个可选参数 service mysqld restart 拷贝主的db1库数据到从:mysqldump -uroot -S /tmp/mysql2.sock -p123456 db1 >

Db1.sql; mysql-uroot-p-e "create database db1"; mysql-uroot-p db1 < db1.sql

Mysql-uroot-p # login from mysql

Slave stop

Change master to master_host='127.0.0.1', master_port=3307, master_user='repl', master_password='123123', master_log_file='mysql-bin.000006', master_log_pos=474952

Slave start

Master: mysql-uroot-S / tmp/mysql2.sock-p123456-e "unlock tables"

View the status of slave from above: show slave status\ G

Test master-slave

Main empty db table of db1 library: use db1; select count () from db "; truncate table db

Enter slave and view the db1 library db table: use db1; select count () from db "

Delete table db: drop table db on the master

Judging from the above, the db table no longer exists.

Suggestion: the master-slave mechanism of MySQL is fragile and should be operated cautiously. If you restart master, be sure to stop slave first, that is, you need to execute the slave stop command on slave, and then restart master's mysql service, otherwise it is likely to be interrupted. Of course, after the restart, you also need to turn on slave start for slave. Does the above details about how to install and configure MySQL services help you? If you want to know more about it, you can continue to follow our industry information section.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report