[MySQL Notes] install/configure mysql source code and support Chinese gbk/gb2312 Encoding

Source: Internet
Author: User
[MySQL Notes] the installation and configuration steps of mysql source code and the configuration methods that support Chinese gbkgb2312 encoding have been taken for a long time. I hope to help more beginners with the notes: this note takes the mysql-5.1.73 version as an example to explain 1. mysql source code compilation and installation step 1) download the mysql source code on the official website and decompress it. 2) cd to the source code directory and execute

[MySQL Notes] the steps for installing and configuring mysql source code and the methods for configuring the Chinese gbk/gb2312 encoding have been discussed for a long time. I hope to help more beginners with the notes: this note takes the mysql-5.1.73 version as an example to explain 1. mysql source code compilation/installation step 1) download the mysql source code on the official website and decompress it. 2) cd to the source code directory and execute

[MySQL Notes] installation/configuration steps of mysql source code and configuration methods supporting Chinese gbk/gb2312 Encoding

I shared my learning notes a long time ago, hoping to help more beginners.

Note: This document uses the mysql-5.1.73 version as an example to explain

1. mysql source code compilation/installation steps

1) download and decompress the mysql source code from the official website
2) cd to the source code directory and execute

./configure  --prefix=/home/slvher/tools/mysql-5.1.73 --with-charset=gbk --with-charset=gb2312 --with-extra-charsets=all --with-plugins=max-no-ndb
Note:
-- Prefix specifies the installation directory, which needs to be modified according to the actual situation
-- With-charset specifies the default supported character sets. You can specify multiple ( If you need to support simplified Chinese, you must specify at least one gbk and gb2312.)
-- With-plugins: Specifies the innodb engine to be installed. (You must manually specify the innodb engine from mysql5.1. Previously, it was installed by default)
3) Check the Makefile file. After confirming that several basic configurations are correct, run
   shell> make   shell> make install
Note 1:If the installation failure is caused by an error specified by the parameter during step 1./configure, you need to re-Execute./configure. Make sure to execute make cleanAnd then make & make install again. If you do not make clean directly, the part of the last compiled files in the source code directory will not be re-compiled, and these last compiled files use the last incorrectly configured parameters!
NOTE 2:After the installation is complete, cd to the mysql installation directory (through the path specified by -- prefix or the default system path), you can see folders such as bin/include/lib, which indicates that the binary file is successfully installed.
4) copy the my-medium.cnf from the support-files folder in the source directory (small/medium/large three levels in total, depending on the machine configuration select the appropriate) configuration ~ /. My. cnf file and configure relevant parameters. When mysql server starts, it reads the configuration of this file. For mysql's search path for the my. cnf file, you can view the official mysql-refman document.
Note:Improper configuration of my. cnf may cause mysql to report an error, for example, "mysql: unknown variable 'character-set-server = utf8'". For how to solve this problem, see here
5) execute the following commands in the mysql installation directory to install the permission table and default database.
 ./bin/mysql_install_db --basedir=/home/slvher/tools/mysql-5.1.73 --datadir=/home/slvher/tools/mysql-5.1.73/db-data ./bin/mysql_install_db --user=slvher
6) run the following command in the mysql installation directory to start mysqld:
./bin/mysqld_safe &
7) Run "ps-x" to check whether mysqld is successfully started. "d" indicates the daemon mode. Therefore, the normal method to close mysqlserver is the following command:
./bin/mysqladmin shutdown -uroot -p
Then enter the root password to stop the mysqld process. If you force kill-9 to kill the process, the database may be damaged!
8) Add the mysql execution PATH to the search path of the path variable.

So far, mysql server supporting Chinese gbk and gb2312 has been installed.Run the following command to verify the supported character sets:
   shell> mysql -uroot     mysql> show character set;
Note 1:The new mysql server is installed. The default root password is null.
NOTE 2:If you perform this operation in step 1. /when using the -- with-charset parameter to specify gbk or gb2312, the output of show should be able to see these character sets. Otherwise, you have to reinstall it -_-

2. access permission configuration after installation is complete and mysqld_safe is started

1) set the root password of the mysql server
The root Password is empty by default. (therefore, you can directly log on to mysql-uroot. In addition, after logon, Run "select User, Host, Password from mysql. user ", you can see that the field" root Password "is empty.Set the root password in several ways:
A. Use the set password statement:

Shell> mysql-u root mysql> set password for 'root' @ 'localhost' = PASSWORD ('xxx '); # xxx is the new password mysql> set PASSWORD for 'root' @ 'host _ name' = password ('xxx '); # host_name is the machine name mysql> set password for 'root' @ '127. 0.0.1 '= PASSWORD ('xxx ');
B. Use the update statement:
Shell> mysql-u root mysql> update mysql. user set Password = PASSWORD ('xxx') where User = 'root'; mysql> flush privileges; # This statement will allow mysql server to re-read the permission table
If the root field has multiple Host fields, we recommend that you use this method to specify the root password, because it is more concise.
C. Use the mysqladmin tool:
      shell> mysqladmin -u root password "xxx"       shell> mysqladmin -u root -h host_name passord "xxx"
This method cannot be used to set a new root password, which is like 'root' @ '192. 0.0.1.
Note: The newly installed mysql server allows anonymous users to log on to the machine by default. If you do not need to log on, you are advised to delete anonymous users.

2) Add and authorize a new user
Because the root permission is too large, it is necessary to add a normal user for mysql and set its permissions, you can follow these steps (assuming that you have logged on to the machine where the mysql server is located ):

Shell> mysql-u root-pxxx # note that there is no space between-p and password (assuming "xxx"), you can skip the process of entering a password. mysql> create user work; mysql> grant select on db1.test _ table to 'user' @ 'localhost' identified by 'xxx ';
The above grant statement execution result: the user logged on from localhost must use the xxx password to log on successfully, and can only access the test_table table of database db1.
To grant all operation permissions to all tables in all databases to the user logged on from localhost, run the following command:
      mysql> grant all privileges on *.* to 'user'@'localhost' identified by 'xxx';
If you authorize the remote login user (select/insert permission for db1.test _ table), you need to execute the following command:
      mysql> grant select, insert on db1.test_table to 'user'@'%' identified by 'xxx';
'%' In the preceding statement indicates any host, so remote logon can be overwritten.
Note 1:When authorizing a remote logon user, you may find that the user cannot log on remotely even if the preceding command is executed. This is generally because the user name first hits a record in the permission table that does not support remote Logon (for example, the user from a certain IP address is not allowed to log on ). When troubleshooting, run select User, Host, Password from mysql. user where User = 'user' to view the current permissions of the user, determine whether a user has the permission to log on from any machine or whether a log explicitly specifies that the user cannot log on from a specific machine.
NOTE 2:Sometimes, after completing the Remote User Logon Settings, you will find that remote logon is normal, but you cannot log on locally through-h localhost or-h 127.0.0.1, this is generally because anonymous users on the local machine are allowed to log on without a password (mysql server allows anonymous logon by default). You only need to delete the logon permissions of anonymous users.

[References]
1. mysql reference manual
2. mysql: unknown variable 'character-set-server = utf8' Solution

====================================== EOF ======================== ================

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.