Install and configure Ubuntu 12.04 to access MySQL

Source: Internet
Author: User

In Ubuntu 12.04, you can use the apt-get method to install MySQL. It is too troublesome to install and change the configurations by yourself, the following two articles are worth your reference:

I just want to save time. In fact, it is best to install it on your own, so that you can clearly understand it. The following describes my installation and configuration process for dummies:

Install and configure MySql

1. Install mysql-server and mysql-workbench with the following command:

Sudo apt-get install mysql-server

Sudo apt-get install mysql-workbench

It should be noted that mysql-admin and mysql-query-browser must be installed in many installation tutorials on the Internet or on the books, but no longer needed. You only need to install mysql-server, at the same time, mysql-admin will be installed by default, and the Mission of mysql-query-browser has been handed over to mysql-workbench, a very convenient front-end manager, mysql workbench is sufficient for general mysql operations. lz uses workbench all the time and does not use mysql-admin.

During the installation of mysql-server, you will be prompted to enter the password of the root user, which is also available during windows installation. It should not be unfamiliar, but you are not allowed to specify the default Character Set of the database, this was installed on windows, so that some Chinese support problems can be avoided in advance, but this option is not provided during ubuntu installation, in this case, mysql cannot support Chinese characters after installation. However, this problem can be solved well. Let's continue.

2. Solve Chinese support problems

(1) Change the mysql configuration to support Chinese characters:

The configuration file of mysql in ubuntu is/etc/mysql/my. cnf,

In the [client] section, add:

Default-character-set = utf8

In the [mysqld] section, add:

Character_set_server = utf8


Init_connect = 'set NAMES utf8'


In the [mysql] section, add:

Default-character-set = utf8


In the [mysqld_safe] section, add:

Default-character-set = utf8


After mysql is restarted, it can support Chinese characters. The restart command is:

Sudo/etc/init. d/mysql restart

Run the show variables like 'character % 'command in mysql to confirm the Modification result. If the following content is displayed, the modification is successful:

+ -------------------------------------- +
| 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/|
+ -------------------------------------- +


(2) If you use the C language to access the MySql database, you must set the character set in the code to support Chinese characters:

Use the following function to solve the problem

Int mysql_set_character_set (MYSQL * mysql, char * csname)

If the returned value is 0, the operation is successful. If the value is not 0, an error occurs.
For example, you can use the following code snippet:

If (mysql_set_character_set (& my_connection, "utf8 ")){
Fprintf (stderr, "Set character set error % d: % s \ n", mysql_errno (& my_connection), mysql_error (& my_connection ));
}

Now you can use workbench for familiar operations. The interface is exactly the same as that in windows.

The following describes how to access the MySql database in C language in ubuntu.

  • 1
  • 2
  • Next Page

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.