Home > Database > Mysql Tutorial > body text

MySQL - Detailed introduction to installing MySQL5.5 in RPM mode under CentOS

黄舟
Release: 2017-03-09 13:25:22
Original
1177 people have browsed it

This article describes MySQL - a detailed introduction to the installation of MySQL5.5 in RPM mode under CentOS. It has reference value. Let’s analyze it together.

First go to the mySQL official website download page:

http: //dev.mysql.com/downloads/mysql/#downloads

Select Platform Select Oracle & Red Hat Linux 4 & 5

to download the following three files respectively ( Since my machine is 32-bit, the following is the 32-bit version of the package. If your machine is 64-bit, please download the 64-bit version):

1. Red Hat & Oracle Linux 5 (x86, 32-bit), RPM Package
MySQL Server

2. Red Hat & Oracle Linux 5 (x86, 32-bit), RPM Package
Client Utilities

##3. Red Hat & Oracle Linux 5 (x86, 32-bit), RPM PackageDevelopment Libraries

Use wget command to use break Download these three files by clicking on the transfer

wget -c http://cdn.mysql.com/Downloads/MySQL-5.5/MySQL-server-5.5.28-1.rhel5.i386.rpm                                                                          
wget -c http://cdn.mysql.com/Downloads/MySQL-5.5/MySQL-client-5.5.28-1.rhel5.i386.rpm                                                                          
wget -c http://cdn.mysql.com/Downloads/MySQL-5.5/MySQL-devel-5.5.28-1.rhel5.i386.rpm
Copy after login

After the download is complete, start the installation:

rpm -ivh MySQL-server-5.5.28-1.rhel5.i386.rpm

rpm -ivh MySQL-client-5.5.28-1.rhel5.i386.rpm

##rpm -ivh MySQL-devel-5.5 .28-1.rhel5.i386.rpm

If an error occurs during the installation:

error: Failed dependencies:                                                                 
        libaio.so.1()(64bit) is needed by MySQL-server-5.5.28-1.rhel5.x86_64                                                                 
        libaio.so.1(LIBAIO_0.1)(64bit) is needed by MySQL-server-5.5.28-1.rhel5.x86_64                                                                  
        libaio.so.1(LIBAIO_0.4)(64bit) is needed by MySQL-server-5.5.28-1.rhel5.x86_64
Copy after login

is that the dependent library is missing, just install the dependent library

yum install libaio
Copy after login

After prompting that the installation is complete, enter mysql to see if the installation is successful

mysql
Copy after login

If there is no response or the following error message appears:


ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)

Indicates that the mysql service has not been started yet, enter service mysql start Start the mysql service

service mysql start
Copy after login

and then enter mysql. If the following prompt message appears, it means success.

Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.5.16 MySQL Community Server (GPL)
                                                            
Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
                                                            
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
                                                            
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
Copy after login

If an error occurs

Starting MySQL.... ERROR! The server quit without updating PID file (/var/lib/mysql/lechiexxxxx.pid).
Copy after login


View the log file based on the error address

The address here is /var/lib/mysql/

The log name is generally the server name.err

When I open it, I find this sentence:

[ERROR] Fatal error: Can't open and lock privilege tables: Table 'mysql.host' doesn't exist
121012 15:12:05 mysqld_safe mysqld from pid file /var/lib/mysql/lechiexxxxxx.pid ended
Copy after login

So the table is missing.

Initialization of the execution table

/usr/bin/mysql_install_db
Copy after login

After execution, the startup still fails. Check the log:

[ERROR] Failed to open log (file './mysql-bin.000004', errno 13)
Copy after login

It should be that there is no permission. After granting mysql permission

chown -R mysql:mysql /var/lib/mysql/
Copy after login

Re-execute service mysql start to start the service, success!

You can start the daemon process

/usr/bin/mysqld_safe &
Copy after login

I usually press Enter several times to exit putty or secureCRT, and then reopen a session


[Question]

Where is mysql installed after installation? Generally in the following folders

/usr/share/mysql/ or /usr/lib/mysql/ or /var/lib/mysql/

You can pass the command:

whereis mysql
Copy after login

Let’s see where it is installed.

[Initialization Settings]

The MySQL installed by rpm package will not install the /etc/my.cnf file. As a solution, you only need to copy my in the /usr/share/mysql directory. -huge.cnf file to the /etc directory and rename it to my.cnf

cp /usr/share/mysql/my-huge.cnf /etc/my.cnf
Copy after login

[Set password]

When installing for the first time, the default password is empty. You can use the following command to modify root Password,

/usr/bin/mysqladmin -u root  password 新密码XXXXX
Copy after login

For example: /usr/bin/mysqladmin -u root password 123456

Then log in again

mysql -u root –p新密码XXXXX
Copy after login

Modify the login password

This is through The mysqladmin command can be used to modify the password, or the password can be changed by modifying the library.

[Directory Description]

1. Database directory

/var/lib/mysql/

2. Configuration file

/ usr/share/mysql (mysql.server command and configuration file)

3. Related commands

/usr/bin (mysqladmin mysqldump and other commands)

4. Startup script

/etc/rc.d/init.d/ (directory of startup script file mysql)

[Start and Stop]

1. Start


After the MySQL installation is completed, the startup file mysql is in the /etc/init.d directory. Just run the following command when you need to start it.


/etc/init.d/mysql start


or

/etc/rc.d/init.d/mysql start


2. Stop

/usr/bin/mysqladmin -u root -p shutdown

3. Automatically start

1) Check whether mysql is automatically In the startup list

/sbin/chkconfig –list

2) Add MySQL to the startup service group of your system

/sbin/chkconfig – add mysql

3) Delete MySQL from the startup service group.

/sbin/chkconfig – del mysql


[Change MySQL directory]

MySQL’s default data file storage directory is /var/lib/mysql.

If you want to move the directory to /home/data, you need to perform the following steps:


1. Create the data directory under the home directory

cd /home

mkdir data

Remember to grant permissions:

chown -R mysql:mysql /home/data


2. Stop the MySQL service process :

mysqladmin -u root -p shutdown

3. Move the entire /var/lib/mysql directory to /home/data

mv /var/lib/mysql /home/data/

This will move the MySQL data file to /home/data/mysql

4. Find the my.cnf configuration file

If /etc There is no my.cnf configuration file in the / directory. Please find the *.cnf file in /usr/share/mysql/,

copy one of them to /etc/ and rename it to my.cnf). The command is as follows:

cp /usr/share/mysql/my-medium.cnf /etc/my.cnf

5、编辑MySQL的配置文件/etc/my.cnf

为保证MySQL能够正常工作,需要指明mysql.sock文件的产生位置。

修改socket=/var/lib/mysql/mysql.sock一行中等号右边的值

为:/home/mysql/mysql.sock 。操作如下:

vi my.cnf ##用vi工具编辑my.cnf文件,找到下列数据修改之
# The MySQL server
[mysqld]
port = 3306
#socket = /var/lib/mysql/mysql.sock     ##原内容,为了更稳妥用“#”注释此行
socket = /home/data/mysql/mysql.sock #加上此行
Copy after login

6、修改MySQL启动脚本/etc/rc.d/init.d/mysql

最后,需要修改MySQL启动脚本/etc/rc.d/init.d/mysql,把其中datadir=/var/lib/mysql一行中,等号右边的路径改成你现在的实际存

放路径:home/data/mysql。

vi /etc/rc.d/init.d/mysql
#datadir=/var/lib/mysql##注释此行
datadir=/home/data/mysql ##加上此行
Copy after login

7、重新启动MySQL服务

/etc/rc.d/init.d/mysql start

或用reboot命令重启Linux

如果工作正常移动就成功了,否则对照前面的7步再检查一下。

【配置远程访问】

处于安全考虑,Mysql默认是不允许远程访问的,可以使用下面开启远程访问

//赋予任何主机访问数据的权限mysql>GRANT ALL PRIVILEGES ON *.* TO 'root'@'%'WITH GRANT OPTION
//使修改生效mysql>FLUSH PRIVILEGES
Copy after login

如果依然不能远程访问的话,那就很可能防火墙的原因了,可以在防火墙中开启3306端口或者干脆关掉防火墙。


The above is the detailed content of MySQL - Detailed introduction to installing MySQL5.5 in RPM mode under CentOS. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!