1. Install MySQL database first download mysql from the MySQL website, then go to the directory where you downloaded the installation files, run the following command to install, Where mysql-server-community-5.1.56-1.rhel5.i386.rpm is the RPM package for the MySQL database server that you just downloaded, and then uses/etc/rc.d/init.d/ Mysqlrestart command to restart the MySQL service:
- [Email protected] ~]# RPM-IVH mysql-server-community-5.1.56-1.rhel5.i386.rpm
- [Email protected] ~]#/etc/rc.d/init.d/mysql restart
- Shutting down MySQL. Determine
- Starting MySQL. Determine
2. Configuring the MySQL database character set
Note: The purpose of configuring the MySQL database character set is to facilitate the use of the database, do not need to temporarily set the database character sets each time the connection, the individual does not recommend this method, the real project should be connected to the database temporarily set the database character sets, so as to facilitate the system migration, And it doesn't affect the use of other databases in the database server!
After the installation is complete, you need to configure the MySQL character set configuration, first need to find the location of the MySQL configuration file, because the MySQL configuration file name is the. CNF end, so you can use the following command to find:
- [[email protected] ~]# Find/-iname ' *.cnf '-print
- /usr/share/mysql/my-large.cnf
- /usr/share/mysql/my-medium.cnf
- /usr/share/mysql/my-innodb-heavy-4g.cnf
- /usr/share/mysql/my-huge.cnf
- /usr/share/mysql/my-small.cnf
- /usr/share/doc/mysql-server-community-5.1.56/my-large.cnf
- /usr/share/doc/mysql-server-community-5.1.56/my-medium.cnf
- /usr/share/doc/mysql-server-community-5.1.56/my-innodb-heavy-4g.cnf
- /usr/share/doc/mysql-server-community-5.1.56/my-huge.cnf
- /usr/share/doc/mysql-server-community-5.1.56/my-small.cnf
- /etc/pki/tls/openssl.cnf
After entering the command "Find/-iname ' *.cnf '-print" Enter, the screen displays the MySQL configuration file that you searched for and then copies My-large.cnf, MY-MEDIUM.CNF, MY-INNODB-HEAVY-4G.CNF, MY-HUGE.CNF, my-small.cnf any one to the/etc directory, and named My.cnf, whose commands are as follows:
- [Email protected] ~]# CP/USR/SHARE/MYSQL/MY-MEDIUM.CNF/ETC/MY.CNF
- [Email protected] ~]# VI/ETC/MY.CNF
Then, using the VI editor, modify the/etc/my.cnf file and add it under [client]: "default-character-set=gb2312"; under [Mysqld], add: "default-character-set= gb2312 ". As shown below:
- # The following options would be passed to all MySQL clients
- [Client]
- default-character-set=gb2312
- #Password = your_password
- Port = 3306
- Socket =/var/lib/mysql/mysql.sock
- # here follows entries for some specific programs
- # The MySQL server
- [Mysqld]
- default-character-set=gb2312
- Port = 3306
- Socket =/var/lib/mysql/mysql.sock
- Skip-locking
- Key_buffer_size = 16M
- Max_allowed_packet = 1M
- Table_open_cache =
- Sort_buffer_size = 512K
- Net_buffer_length = 8K
Click the ESC key, enter ": Wq" after the return to save the configuration file, enter "/etc/rc.d/init.d/mysqlrestart" Restart the MySQL service, as follows:
- [Email protected] ~]#/etc/rc.d/init.d/mysql restart
- Shutting down MySQL. Determine
- Starting MySQL. Determine
Finally, we verify that the MySQL server configuration is successful, first log in to MySQL, enter the "mysql–uroot-p" carriage return, the system prompts for a password, log in successfully after entering the MySQL command mode, as follows:
- [Email protected] ~]# mysql-uroot-p
- Enter Password:
- Welcome to the MySQL Monitor. Commands End With; or \g.
- Your MySQL Connection ID is 2
- Server Version:5.1.56-community-log MySQL Community Server (GPL)
- Copyright (c), Oracle and/or its affiliates. All rights reserved.
- Oracle is a registered trademark of the Oracle Corporation and/or its
- Affiliates. Other names trademarks of their respective
- Owners.
- Type ' help ', ' or ' \h ' for help. Type ' \c ' to clear the current input statement.
- MySQL>
In MySQL command mode, enter "show variables like ' collation_% ';", "show variables like ' character_set_% ';" The character set is displayed after the carriage return as follows:
- MySQL> Show variables like ' collation_% ';
- +----------------------+-------------------+
- | variable_name | Value |
- +----------------------+-------------------+
- | collation_connection | Gb2312_chinese_ci |
- | Collation_database | Gb2312_chinese_ci |
- | Collation_server | Gb2312_chinese_ci |
- +----------------------+-------------------+
- 3 rows in Set (0.05 sec)
- MySQL> Show variables like ' character_set_% ';
- +--------------------------+----------------------------+
- | variable_name | Value |
- +--------------------------+----------------------------+
- | character_set_client | gb2312 |
- | character_set_connection | gb2312 |
- | Character_set_database | gb2312 |
- | Character_set_filesystem | binary |
- | Character_set_results | gb2312 |
- | Character_set_server | gb2312 |
- | Character_set_system | UTF8 |
- | Character_sets_dir | /usr/share/mysql/charsets/|
- +--------------------------+----------------------------+
- 8 rows in Set (0.00 sec)
- MySQL>
According to the above query results, we set the MySQL database configuration information has been effective, to complete the installation and configuration of MySQL server.
3. Some considerations for MySQL Database 3.1 remote connection MySQL Slow resolution: Add a configuration like this in the MySQL server configuration (/etc/my.cnf) to quickly.
- [Mysqld]
- Skip-name-resolve
Note: This enables DNS resolution to be disabled, and the connection speed is much faster. However, it is not possible to use the hostname in the MySQL authorization table and only use the IP format.
3.2 After restarting the database, it is found that no password (or any password) can be used to connect the workaround: Check your MySQL configuration file (/etc/my.cnf) for a more statement: "Skip-grant-tables", delete (comment) the statement, Reconfigure the MySQL password and restart the MySQL service again! Note: If you use the Skip-grant-tables system will not do any user access control, but you can use mysqladmin flush-privileges or mysqladmin reload to turn on access control; By default, show The databases statement is open to all users, and if the MySQL server does not have a remote account open, add Skip-grant-tables to the/ETC/MY.CNF.
Blog Address : http://blog.csdn.net/shuxiao9058
Original author : Kevdzija
MySQL database installation and configuration under Linux