Solution to Linux cron failure in MySQL execution

Source: Internet
Author: User
Tags mysql official site

Linux cron failed to execute MySQLIn this article, we will mainly introduce the solution to instance problems. Next let's take a look at this part.

1. first, in order to count the average number of online users on the server, a SHELL script is written to execute the command hourly from to every day to obtain the current online users so as to count the maximum number of online users, and average online users.

The SHELL script is as follows:

 
 
  1. Time08_23.sh
  2. Bytes -----------------------------------------------------------------------------------
  3.  
  4. #! /Bin/bash
  5. # Crontab-e 57 7-22 ***/home/nemo/crontab/time08_23.bash
  6. DB_USER = "root"
  7. DB_PASS = "***"
  8. DB_HOST = "localhost"
  9. DB_PORT = "3306"
  10. # Others vars
  11. BIN_DIR = "/usr/bin"
  12. # TODO
  13. # Obtain the port 8080
  14. THETIME = 'netstat-ant | grep 8080 | wc-l'
  15. # Obtain the current hour
  16. THEHOUR = 'date + % H'
  17.  
  18. # Update the current number of people in the current hour
  19. $ BIN_DIR/mysql-u $ DB_USER-p $ DB_PASS-h $ DB_HOST-P $ DB_PORT <EOF
  20. Use wapgame4sky2;
  21. UPDATE MgrSky SET time $ THEHOUR = $ thetime where TO_DAYS (date) = TO_DAYS (now ());
  22. EOF

2. The preceding SHELL scripts run correctly on both local and remote servers through source time08_23.sh and./time08_23.sh. The data is correct and everything is normal.

3. However, the above script uses the cron Task Scheduler to execute the database, but there is no data, so I thought it was a Task Scheduler configuration error or permission problem, but the query error log obtained the following information:

 
 
  1. Character set 'ascii' is not a compiled character set and is not specified in the '/usr/local/share/mysql/charsets/Index.xml'   
  2.  

4. After analyzing the problem, it is clear that the encoding format is the problem.

 
 
  1. show variables like '%char%';  
  2. +--------------------------+----------------------------+  
  3. | Variable_name            | Value                      |  
  4. +--------------------------+----------------------------+  
  5. | character_set_client     | utf8                       |  
  6. | character_set_connection | utf8                       |  
  7. | character_set_database   | utf8                       |  
  8. | character_set_filesystem | binary                     |  
  9. | character_set_results    | utf8                       |  
  10. | character_set_server     | latin1                     |  
  11. | character_set_system     | utf8                       |  
  12. | character_sets_dir       | /opt/mysql/share/charsets/ |  
  13. +--------------------------+----------------------------+ 

View the local mysql replica set settings:

 
 
  1. +--------------------------+----------------------------+  
  2. | Variable_name            | Value                      |  
  3. +--------------------------+----------------------------+  
  4. | character_set_client     | latin1                     |  
  5. | character_set_connection | latin1                     |  
  6. | character_set_database   | latin1                     |  
  7. | character_set_filesystem | binary                     |  
  8. | character_set_results    | latin1                     |  
  9. | character_set_server     | latin1                     |  
  10. | character_set_system     | utf8                       |  
  11. | character_sets_dir       | /usr/share/mysql/charsets/ |  
  12. +--------------------------+----------------------------+ 

Then, query the mysql official site, the solution to this problem is as follows: http://dev.mysql.com/doc/refman/5.0/en/charset-configuration.html

 
 
  1. [client]  
  2. character-sets-dir=/usr/local/mysql/share/mysql/charsets  
  3. [client]  
  4. character-sets-dir="C:/Program Files/MySQL/MySQL Server 5.0/share/charsets" 
  5.  
  6. Character set 'charset_name' is not a compiled character set and is not  
  7. specified in the '/usr/share/mysql/charsets/Index.xml' file  
  8. [client]  
  9. default-character-set=charset_name 

The problem should be clear. according to my understanding, linux cron should use the latin1 character set when compiling shell scripts. but here the use of UTF-8, resulting in encoding is not supported. then I contacted O & M and obtained my. cnf and mysql root permissions.

5. modify vi/etc/my. cnf: add it under [client], default-character-set = latin1, add it under [mysqld], default-character-set = latin1, and restart mysql.

Start the mysql command:

 
 
  1. /Usr/local/mysql/bin
  2. ./Mysqld_safe &
  3. The command to disable the mysql service is:
  4. ./Mysqladmin-u root-p shutdown

Follow these steps to solve the problem.

This article describes how to solve the Linux cron failure to execute MySQL!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.