Install mysql5.0 for Linux 5, and configure the relevant MySQL load.

Time:2022-1-1
  • This article has installed mysql5 Version 5
  • MySQL master-slave service configuration

Before installation, take a snapshot to facilitate the return of problems in the middle. It is best to take a snapshot every node.

Check whether MySQL is installed on Linux,rpm -qa|grep mysqlseecentosWhat version is installed undermysql

rpm -qa|grep mysql

If there is a version of MySQL that is not what you want, use the command

RPM - e package name
rpm -e mysql-libs --nodeps
either-or

Add a new repo

rpm -Uvh http://mirror.steadfast.net/epel/6/i386/epel-release-6-8.noarch.rpm

A total of two repos need to be added. Now add another one. If not, it will still be MySQL version 5.1

rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-6.rpm

This step is to check whether the MySQL installation and version number can be ignored

yum --enablerepo=remi,remi-test list mysql mysql-server

Then install the procedure

yum --enablerepo=remi,remi-test install mysql mysql-server

Enter when promptedy

Mysql start, stop and restart

/etc/init. D / mysqld start on
/etc/init. D / mysqld stop stop
/etc/init. D / mysqld restart restart

The following information can be ignored

If you want to set the self startup setting 
`chkconfig --levels 345 mysqld on`

To enable MySQL security settings, enter the following command
`/usr/bin/mysql_secure_installation`

Enter ` y when the query interface appears`

Then maysql is installed

The above information comes from Baidu CentOS installation mysql5 5 stepshttps://jingyan.baidu.com/art…


Configure master-slave MySQL server

This content comes fromhttp://blog.51cto.com/369369/…

1. The master and slave servers do the following operations respectively

  1. Consistent version
  2. Initialize the table and start MySQL in the background
  3. Change the password of root

2. Modify the master of the master server (I understand it as a name, a substitute)

vi /etc/my.cnf
[mysqld] # if there is no such addition, there will always be one
Log bin = MySQL bin #[must] enable binary logging
Server id = 222 #[must be] the unique ID of the server. The default is 1. Generally, the last segment of the IP is used

3. Modify Slave Slave

vi /etc/my.cnf
[mysqld]
Log bin = MySQL bin #[not required] enable binary logging
Server id = 226 #[must be] the unique ID of the server. The default is 1. Generally, the last segment of the IP is used

4. Restart MySQL on both servers

/etc/init.d/mysql restart

5. Establish an account on the master server and authorize slave

Enter the MySQL console
mysqlor/var/bin/mysql/mysql -u root -p
Create a user

GRANT REPLICATION SLAVE ON *.* to 'mysync'@'%' identified by 'q123456'; 
#Generally, the root account is not used, & ldquo;%& rdquo; It means that all clients may be connected. As long as the account and password are correct, the specific client IP can be used here, such as 192.168.145.226, to strengthen security.

6. Log in to MySQL of the master server and query the status of the master server

mysql>show master status;
   +------------------+----------+--------------+------------------+
   | File             | Position | Binlog_Do_DB | Binlog_Ignore_DB |
   +------------------+----------+--------------+------------------+
   | mysql-bin.000004 |      308 |              |                  |
   +------------------+----------+--------------+------------------+
   1 row in set (0.00 sec)
Note: after this step, do not operate the master server Mysql to prevent the master server status value from changing

7. Configure slave server slave

mysql>change master to master_host='192.168.145.222',master_user='mysync',master_password='q123456',master_log_file='mysql-bin.000004',master_log_pos=308;   
#1. Be careful not to break. There are no single quotation marks before and after the 308 number.
#2. Note the number on your primary server.

Mysql>start slave;    # Start replication from server

8. Check the status of the replication function from the server

mysql> show slave status\G
*************************** 1. row ***************************

              Slave_IO_State: Waiting for master to send event
              Master_ Host: 192.168.2.222 // primary server address
              Master_ User: mysync // authorized account name. Try to avoid using root
              Master_ Port: 3306 // database port. Some versions do not have this line
              Connect_Retry: 60
              Master_Log_File: mysql-bin.000004
              Read_ Master_ Log_ Pos: 600 // # synchronous reading location of binary log, greater than or equal to Exec_ Master_ Log_ Pos
              Relay_Log_File: ddte-relay-bin.000003
              Relay_Log_Pos: 251
              Relay_Master_Log_File: mysql-bin.000004
              Slave_ IO_ Running: Yes // this status must be yes
              Slave_ SQL_ Running: Yes // this status must be yes
                    ......

Note: Slave_ IO and slave_ The SQL process must run normally, that is, in the yes state, otherwise it is in the wrong state (for example, one no is an error).

In the above operation process, the master-slave server configuration is completed.

9. Master slave server test

The master server MySQL establishes a database, creates a table in the database, and inserts a piece of data:

  mysql> create database hi_db;
  Query OK, 1 row affected (0.00 sec)

  mysql> use hi_db;
  Database changed

  mysql>  create table hi_tb(id int(3),name char(10));
  Query OK, 0 rows affected (0.00 sec)
 
  mysql> insert into hi_tb values(001,'bobu');
  Query OK, 1 row affected (0.00 sec)

  mysql> show databases;
   +--------------------+
   | Database           |
   +--------------------+
   | information_schema |
   | hi_db                |
   | mysql                |
   | test                 |
   +--------------------+
   4 rows in set (0.00 sec)

Query MySQL from server:

   mysql> show databases;

   +--------------------+
   | Database               |
   +--------------------+
   | information_schema |
   | hi_ DB |#i'm here, you see
   | mysql                 |
   | test          |
   +--------------------+
   4 rows in set (0.00 sec)

   mysql> use hi_db
   Database changed
   mysql> select * from hi_ tb;           # View the specific data added on the primary server
   +------+------+
   | id   | name |
   +------+------+
   |    1 | bobu |
   +------+------+
   1 row in set (0.00 sec)

10. Complete

The blogger here is talking about writing shell scripts to prevent downtime. I’m not still learning operation and maintenance. The blogger said the same.

Write a shell script and use Nagios to monitor the two yes’s of the slave (slave_io and slave_sql processes). If only one or zero yes is found, it indicates that there is a problem between the master and slave. Send a text message alarm.


At present, I have just learned the master-slave database and still understand its benefits. I only know that there is a master-slave configuration and I don’t know how to use it. Later, other types of loads will be added slowly.

Recommended Today

Could not get a resource from the pool when the springboot project starts redis; nested exception is io. lettuce. core.

resolvent: Find your redis installation path: Start redis server Exe After successful startup: Restart project resolution. ———————————————————————->Here’s the point:<——————————————————————- Here, if you close the redis command window, the project console will report an error. If you restart the project, the same error will be reported at the beginning, The reason is: It is inconvenient to […]