Install MySQL5.6 in Linux compilation and modify Character Set

Source: Internet
Author: User
Tags mysql commands mysql login

Install MySQL5.6 in Linux compilation and modify Character Set

Environment preparation:
After mysql5.5, The./configure compilation method will be changed to the cmake tool for compilation.
Install the dependency package: yum install-y cmake gcc-c ++ make cmake ncurses-devel
Create mysql users and groups:
Groupadd mysql
Useradd-g mysql-s/sbin/nologin mysql
1. Install mysql
Download: http://dev.mysql.com/downloads/mysql

Tar zxvf mysql-5.6.14.tar.gz
Cd mysql-5.6.14
Cmake-DCMAKE_INSTALL_PREFIX =/usr/local/mysql5.6 \
-DSYSCONFDIR =/usr/local/mysql/etc \
-DMYSQL_DATADIR =/usr/local/mysql5.6/data
Make & make install

If the dependency package is not installed, the compilation configuration will report errors and missing libraries. The relevant packages can be installed, and cmakecache.txt will be deleted!

2. initialize the database and Configuration

/Usr/local/mysql5.6/scripts/mysql_install_db \
-- Basedir =/usr/local/mysql5.6 -- datadir =/usr/local/mysql5.6/data \
-- User = mysql & # initialize the database
Mkdir-p/usr/local/mysql5.6/etc
Cp support-files/my-medium.cnf/usr/local/mysql/etc/my. cnf
Cp support-files/mysql. server/etc/rc. d/init. d/mysqld
Chmod + x/etc/init. d/mysqld
Chown-R root. mysql/usr/local/mysql/# Grant mysql Group Permissions
Chown-R mysql. mysql/usr/local/mysql/data # grant the data storage directory permission
/Usr/local/mysql5.6/bin/mysqld_safe-user = mysql & # Start mysql safely
Echo 'path = $ PATH:/usr/local/mysql/bin'>/etc/profile # Set variables to facilitate mysql commands
Source/etc/profile

3. Set the default database encoding for mysql Creation

Vi/usr/local/mysql/etc/my. cnf
Add under [mysqld]
Default-character-set = utf8
Or default-character-set = gbk # prevents website garbled characters
Add under [client]
Default-character-set = utf8
Or default-character-set = gbk

4. test whether the installation is successful.

Service mysqld start
If an error is reported during startup:
Starting MySQL. ERROR! The server quit without updating PID file (/var/lib/mysql/202.pid)
Solution: rm-rf/etc/my. cnf # Delete the built-in configuration file

Mysqladmin-uroot password '192. com' # Set the initial mysql Login password
Mysql-u root-p123456
Mysql> show databases;
+ ------- +
| Database |
+ ------- +
| Information_schema |
| Mysql |
| Test |
+ ------- +
6 rows inset (0.00sec)

5. Common compilation Parameters

-DCMAKE_INSTALL_PREFIX =/usr/local/mysql # installation path
-DMYSQL_DATADIR =/usr/local/mysql/data # data file storage location
-DSYSCONFDIR =/usr/local/mysql/etc # my. cnf path
-DWITH_MYISAM_STORAGE_ENGINE = 1 # support for the MyIASM Engine
-DWITH_INNOBASE_STORAGE_ENGINE = 1 # InnoDB Engine supported
-DWITH_MEMORY_STORAGE_ENGINE = 1 # support for the MEMORY Engine
-DMYSQL_UNIX_ADDR =/tmp/mysqld. sock # Connection database socket path
-DMYSQL_TCP_PORT = 3306 # default port
-DWITH_EXTRA_CHARSETS: STRING = utf8, gbk # the character set required for Installation
-DDEFAULT_CHARSET = utf8 # default Character Set
-DDEFAULT_COLLATION = utf8_general_ci # sets the default effect Character Set sorting rule, which must be used with DDEFAULT_CHARSET.
-DMYSQL_USER = mysql # Run the user
-DWITH_COMMENT = 'string' # comment storage type

6. MySQL Character Set introduction and modification (encoding)

Common Character sets: atin English, big5 traditional Chinese, GB2312 Chinese, UTF8 general language

Mysql supports character sets in four layers:
Server );
Database );
Data table (table) (Field column );
Connection );
Method 1: modify my. cnf in the main configuration file
[Mysqld]
Character_set_server = utf8
[Mysql]
Default-character-set = utf8

Restart mysql!
Method 2: Modify the Mysql command (the website garbled as follows)
1. view the character set used by the database:
123 mysql> show variables like 'character \ _ set \ _ % ';
Mysql> show variables like 'Char % ';
Mysql> show create table tablename; # view the character set when creating a table

2. Modify the default Character Set
2.1 modify the default Character Set of the server
Set character_set_server = utf8

2.2 modify the database Character Set
Set character_set_database = utf8;
2.3 modify the character set of the database Client
Set character_set_client = utf8;
2.4 modify the default Character Set of the Connection
Set character_set_connection = utf8
3. Modify the character set of an existing library
3.1 modify the character set of the database
Alter database mydb character set UTF-8;
3.2 modify the character set of an existing table
Alter table mytable default character set utf8

This article permanently updates the link address:

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.