Install and configure Mysql
This topic describes how to install and configure Mysql.
1. Install the MySQL database
This section uses mysql5.1.49 as an example to describe how to install a Mysql database.
Step 1. log on to the server as a root user.
Step 2 upload the following package of mysql5.1.49 to the "/tmp" Directory through SSH or XFTP.
? MySQL-client-community-5.1.49-1.rhel5.x86_64.rpm? MySQL-server-community-5.1.49-1.rhel5.x86_64.rpm
Step 3 go to the "/tmp" directory.
cd /tmp
Step 4 install the mysql server.
rpm -ivh MySQL-client-community-5.1.49-1.rhel5.x86_64.rpm
Step 5 install the mysql client.
rpm -ivh MySQL-server-community-5.1.49-1.rhel5.x86_64.rpm
Step 6 copy "/usr/share/mysql/MySQL-server-community-5.1.49" to the "/etc" directory and change it to "my. cnf ",
The directory here should be/usr/share/mysql/doc/MySQL-server-community-5.1.49
In order not to reduce the system performance, especially when the system memory is small, such as only 1 ~ 2G, please perform this step.
cp /usr/share/mysql/MySQL-server-community-5.1.49 /etc/my.cnf
-- End
2. Configure the MySQL database
After installing Mysql, you must configure it properly. This section describes how to configure Mysql.
Step 1 log on to the Mysql server as a root user.
Step 2 start the mysql database.
service mysql start
The system displays the following information, indicating that the startup is successful.
Starting MySQL [OK]
Step 3. Set the user name and password.
mysqladmin -u root password 'root'
If you have set a logon password for the MySQL database, the system displays the following information.
mysqladmin: connect to server at 'localhost' failederror: 'Access denied for user 'root'@'localhost' (using password: NO)'
Step 4. log on to mysql.
mysql -uroot -proot
Step 5 allow remote connection and refresh to take effect.
grant all on *.* to 'root'@'%' identified by 'root' WITH GRANT OPTION;FLUSH PRIVILEGES;
Step 6 Close log_bin to prevent Mysql from returning the 1418 error code.
SET GLOBAL log_bin_trust_function_creators = 1;
Step 7 exit mysql.
exit
Step 8 configure the Mysql character encoding to UTF-8.
1. Open the "/etc/my. cnf" file.
vi /etc/my.cnf
[client]//password = [your_password]port = 3306socket = /var/lib/mysql/mysql.sockdefault-character-set=utf8
? Set the server encoding format to UTF-8.
In the following information, insert the blue font to set the server encoding format to UTF-8.
The MySQL server [mysqld]// generic configuration optionsdefault-character-set=utf8port = 3306socket = /var/lib/mysql/mysql.sock
service mysql restart
-- End
3. Check the MySQL database
Step 1. log on to the server as a root user.
Step 2 check whether the MySQL database is started.
service mysql status
If not, run the following command:
service mysql start
Step 3 check whether MySQL is started with the system.
chkconfig --list mysql
If MySQL is started randomly, the following information is displayed:
Mysql 0: Disable 1: Disable 2: Enable 3: Enable 4: Enable 5: Enable 6: Disable
If the mysql entry is not displayed, enter the command to add it to the startup Service Group of the system:
chkconfig --add mysql
If 2 ~ 5. If it is disabled, it must be started. For example, if 2 is in the "off" status and needs to switch to the "Start" status, enter the following command:
chkconfig --level 2 mysql on