Uninstalling, reinstalling, and encoding MySql in Ubuntu

Source: Internet
Author: User

Recently, MySQL in Ubuntu has encountered some problems. I have not found the answer for a long time on the Internet, so I uninstalled and reinstalled it. Of course, as the title is written, encoding is also involved here.

1. Uninstall

When I first installed sudo apt-Get install mysql-server mysql-client

Therefore, the corresponding uninstallation: sudo aptitude purge mysql-server mysql-Client

In fact, I also tried to uninstall the new software manager, but I was skipped the step of setting the root password when I installed it again. Should it be incomplete? However, in any case, I use the following command to uninstall it and reinstall it normally.

2. Install MySQL

Sudo apt-Get install mysql-server mysql-Client

Yes, it is still the original installation method. You need to enter the root password and confirm it once. However, after I install sudo/etc/init. d/MySQL restart cannot be used to restart, start, and stop sudo/etc/init. d/MySQL restart. The following prompt appears:

Luo @ Luo-Ubuntu :~ $ Sudo/etc/init. d/MySQL restart
Rather than invoking init scripts through/etc/init. d, use the service (8)
Utility, e.g. Service MySQL restart
Since the script you are attempting to invoke has been converted to
Upstart job, you may also use the restart (8) utility, e.g. Restart MySQL
MySQL start/running, process 3942
Luo @ Luo-Ubuntu :~ $ Sudo/etc/init. d/MySQL restartrather than invoking init scripts through/etc/init. d, use the service (8) utility, e.g. Service MySQL restart
Since the script you are attempting to invoke has been converted to anupstart job, you may also use the restart (8) utility, e.g. Restart mysqlmysql start/running, process 3942

Therefore, follow the prompts to use the following command line to restart, start, and stop MYSQL:

Sudo restart MySQL # restart

Sudo start MySQL # Start

Sudo stop MySQL # Stop

3. Encoding
It has been circulated on the Internet that the default encoding of MySQL is Latin1, And I used MYSQL as well. However, after I reinstall MySQL, I used: Show variables like "character_set %". The result is as follows:

Mysql> show variables like 'character % ';
+ -------------------------- + ---------------------------- +
| 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 | utf8 |
| Character_set_system | utf8 |
| Character_sets_dir |/usr/share/MySQL/charsets/|
+ -------------------------- + ---------------------------- +
8 rows in SET (0.00 Sec)
Is this the new version? I am not sure, so I should record the method for modifying MySQL encoding.
First, go to MySQL and use show variables like 'character % '; to check whether the encoding is displayed
+ -------------------------- + ---------------------------- +
| 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/|
+ -------------------------- + ---------------------------- +

Modify the encoding and the/etc/MySQL/My. CNF file.
Find the client configuration [client] and add it below
Default-character-set = utf8 default Character Set: utf8
Add in [mysqld]
Default-character-set = utf8 default Character Set: utf8
Init_connect = 'set names utf8' (utf8 encoding is used to set the connection to the MySQL database to run utf8)

After modification, restart MySQL and query show variables like 'character % '. If no exception occurs, it is OK.

Tip: http://liluo.org/2010/06/ubuntu-%E4%B8%AD-mysql-%E5%8D%B8%E8%BD%BD%E3%80%81%E9%87%8D%E8%A3%85%E4%BB%A5%E5%8F%8A%E7%BC%96%E7%A0%81%E9%97% AE %E9%A2%98/

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.