Linux Cron failed to execute MySQL (encoding problem)

Source: Internet
Author: User
Tags mysql official site

 

When accessing a channel, because the other party does not grant the root permission and does not have the highest permission of MySQL, the configuration of MySQL is no longer under control, so there is a problem.

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
Certificate ------------------------------------------------------------------------------------------------------------------------------------
#! /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
Certificate ------------------------------------------------------------------------------------------------------------------------------------

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.

4.1 view the current MySQL replica set settings:

Then, add the following to the shell:
Set names Latin1;
Modify the script file encoding format;
Modifies the default sequence set in Linux;
Wait, and so on. If all the solutions have been tried, they all fail, and cron executes the script to report this error.
The same script file. Why does the Code problem occur when both source and./are executed normally and cron is used ??? I have asked two Linux groups, but no one can help solve this problem (or they are unwilling to ignore such a small 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
Certificate ------------------------------------------------------------------------------------------------------------------------------------
[Client]
Character-sets-Dir =/usr/local/MySQL/share/MySQL/charsets

[Client]
Character-sets-Dir = "C:/program files/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
Certificate ------------------------------------------------------------------------------------------------------------------------------------

The problem should be clear. According to my understanding, Linux Cron should use the Latin1 character set when compiling shell scripts, but here it uses UTF-8, leading to unsupported encoding.
Contact the O & M team and obtain the root permission of my. CNF and MySQL.

5. Modify:
VI/etc/My. CNF
Add under [client]
Default-character-set = Latin1
Add under [mysqld]
Default-character-set = Latin1
Restart MySQL
Certificate ------------------------------------------------------------------------------------------------------------------------------------
Start the MySQL command:
/Usr/local/MySQL/bin
./Mysqld_safe &
The command to disable the MySQL service is:
./Mysqladmin-u root-P Shutdown
Certificate ------------------------------------------------------------------------------------------------------------------------------------

Finally, the problem is solved...

 

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.