Article Directory
- MySQL troubleshooting and production environment optimization
MySQL troubleshooting and production environment optimization
1. Case implementation: common failures of MySQL single instance
Fault 1
1. Failure phenomenon
ERROR 2002 (HY000): Can’t connect to local MySQL server through socket "/data/mysq/mysql.sock’ (2)
2. Problem analysis
The database is not started or the database port is blocked by the firewall
3. Solution
Start the database or open the database listening port on the firewall
Fault two
1. Failure phenomenon
ERROR 1045 (28000): Access denied for user 'root @'localhost (using password:NO)
2. Problem analysis
Incorrect password or no access
3. Solution
Modify the main configuration file of my.cnf and add skip-grant tables under [mysqld]
- update updates the authentication_string field of the user table
- Reauthorize.
Fault three
1. Failure phenomenon
The problem of slow remote connection to the database occasionally occurs when using remote connection to the database
2. Problem analysis
Slow DNS resolution, too many client connections
3. Solution
- Modify the my.cnf main configuration file (add the skip-name-resolve parameter)
- Database authorization prohibits the use of host names
Fault four
1. Failure phenomenon
Can’t open file: ‘xxX_ forums.MYI’. (errmno: 145)
2. Problem analysis
- The server is shut down abnormally, the space where the database is located is full, or some other unknown reason causes damage to the database table
- The file's belonging group has changed due to copying the database
3. Solution
- Repair data table (myisamchk, phpMyAdmin)
- Modify the file's group
Fault five
1. Failure phenomenon
ERROR 1129 (HY000): Host xxx.oxx.xxx.xxx is blocked because of many connection errors; unblock with ‘mysqladmin flush-hosts’
2. Problem analysis
Maximum number of connection errors exceeded
3. Solution
- Clear the cache (flush-hosts keyword)
- Modify mysq|configuration file (max_ connect_ errors=1000)
Fault six
1. Failure phenomenon
Too many connections
2. Problem analysis
The number of connections exceeds the maximum connection limit of MySQL
3. Solution
- Modify MySQL configuration file (max_ connections = 10000)
- Temporarily modify the parameters: set GLOBAL max_ connections= 10000;
Fault seven
1. Failure phenomenon
Warning: World-writable config file /etc/my.cnf is ignored ERROR! MySQL is running but PID file could not be found
2. Problem analysis
MySQL configuration file /etc/my.cn permission problem
3. Solution
chmod 644 /etc/my.cnf
Fault eight
1. Failure phenomenon
InnoDB: Error: page 14178 log sequence number 29455369832
InnoDB: is in the future! Current system log sequence number 29455369832
2. Problem analysis
Innodb data file is damaged
3. Solution
Modify the my.cnf configuration file (innodb_ force_recovery=4)
Back up data files after starting the database
Use backup files to restore data
2. Case implementation: common failures of MySQL master-slave environment
Fault one
1. Failure phenomenon
Slave_ I0_ Running from the library is NO
The slave I/O thread stops because master and slave have equal MySQL server ids; these ids must be different for replication to work (or the --replicate-same-server-id option must be used on slave but this does not always make sense;please check the manual before using it).
2. Problem analysis:
The server-id value of the main library and the slave library are the same
3. Solution
- Modify the server-id value of the slave library to be different from the main library
- Restart the database and synchronize again
Fault two
1. Failure phenomenon:
Slave_ I0_ Running from the library is NO
2. Problem analysis:
The primary key conflicts or the primary database deletes or updates data, the record cannot be found in the database, and the data is modified.
3. Solution
- 方法一
mysql> stop slave;
mysql> set GLOBAL SQL_SLAVE_ SKIP_COUNTER=1;
mysql> start slave; - Method two
set global read_ only=true;
Fault three
1. Failure phenomenon
Error initializing relay log position: 1/0 error reading the header from the binary log
2. Problem analysis
The relay-bin of the relay log from the library is damaged
3. Solution
Manually repair, find the synchronized binlog and pos points again, and then resynchronize
mysql> CHANGE MASTER TO MASTER_LOG_FILE='mysql-bin.xx',MASTER_LOG_POS=xxx;
3. Case implementation: MySQL optimization
1. Hardware optimization
- CPU: It is recommended to use SMP architecture multi-channel symmetrical CPU
- RAM: Physical RAM above 4GB
- Disk: RAID-0+1 disk array or solid state drive
2. MySQL configuration file optimization
- Adjust configuration items
3. SQL optimization
- Try to use cable bow|Check
- Optimize paging
- GROUP BY optimization
4. MySQL architecture optimization
- Architecture choices: master-slave, master-master, one-master-multi-slave, multi-master-multi-slave