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:
- Time08_23.sh
- Bytes -----------------------------------------------------------------------------------
-
- #! /Bin/bash
- # Crontab-e 57 7-22 ***/home/nemo/crontab/time08_23.bash
- DB_USER = "root"
- DB_PASS = "***"
- DB_HOST = "localhost"
- DB_PORT = "3306"
- # Others vars
- BIN_DIR = "/usr/bin"
- # TODO
- # Obtain the port 8080
- THETIME = 'netstat-ant | grep 8080 | wc-l'
- # Obtain the current hour
- THEHOUR = 'date + % H'
-
- # Update the current number of people in the current hour
- $ BIN_DIR/mysql-u $ DB_USER-p $ DB_PASS-h $ DB_HOST-P $ DB_PORT <EOF
- Use wapgame4sky2;
- UPDATE MgrSky SET time $ THEHOUR = $ thetime where TO_DAYS (date) = TO_DAYS (now ());
- 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:
- Character set 'ascii' is not a compiled character set and is not specified in the '/usr/local/share/mysql/charsets/Index.xml'
-
4. After analyzing the problem, it is clear that the encoding format is the problem.
- show variables like '%char%';
- +--------------------------+----------------------------+
- | Variable_name | Value |
- +--------------------------+----------------------------+
- | character_set_client | utf8 |
- | character_set_connection | utf8 |
- | character_set_database | utf8 |
- | character_set_filesystem | binary |
- | character_set_results | utf8 |
- | character_set_server | latin1 |
- | character_set_system | utf8 |
- | character_sets_dir | /opt/mysql/share/charsets/ |
- +--------------------------+----------------------------+
View the local mysql replica set settings:
- +--------------------------+----------------------------+
- | Variable_name | Value |
- +--------------------------+----------------------------+
- | character_set_client | latin1 |
- | character_set_connection | latin1 |
- | character_set_database | latin1 |
- | character_set_filesystem | binary |
- | character_set_results | latin1 |
- | character_set_server | latin1 |
- | character_set_system | utf8 |
- | character_sets_dir | /usr/share/mysql/charsets/ |
- +--------------------------+----------------------------+
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
- [client]
- character-sets-dir=/usr/local/mysql/share/mysql/charsets
- [client]
- character-sets-dir="C:/Program Files/MySQL/MySQL Server 5.0/share/charsets"
-
- Character set 'charset_name' is not a compiled character set and is not
- specified in the '/usr/share/mysql/charsets/Index.xml' file
- [client]
- 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:
- /Usr/local/mysql/bin
- ./Mysqld_safe &
- The command to disable the mysql service is:
- ./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!