Job Recruitment Website - Immigration policy - How to find mysql installation directory and change it under linux?

How to find mysql installation directory and change it under linux?

MySQL is a relational database management system, which was developed by Swedish MySQL AB company and currently belongs to Oracle.

1. can be installed in two ways, one is yum installation, and the other is source installation.

Rpm installation command is as follows

Yum installs mysql-server -y

2. View the related paths as follows

[root @ rhel 5 ~]# find/-name MySQL-print

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

/var/lib/mysql

/var/lib/mysql/mysql

/var/lock/subsys/mysql

/usr/lib/mysql

/usr/include/mysql

/usr/share/mysql

/usr/bin/mysql

The data is placed in: /var/lib/mysql by default.

2. Generally speaking, you only need to modify the storage path of data, and the modification method is as follows

Original path: /var/lib/mysql

Target path: /home/data/mysql

Create a data directory under the (1) home directory.

cd /home

Mkdir data

(2) Stop the mysql process

Service mysqld stopped.

(3) Copy the entire directory of /var/lib/mysql to /home/data with permission.

CP-ARP/var/lib/MySQL/home/data/

(4) Find the my.cnf configuration file.

If there is no my.cnf configuration file in the /etc/ directory, please go to /usr/share/mysql/ to find my-medium*. Cnf file, copy it to /etc/ and rename it my.cnf

The command is as follows:

[root@test 1 mysql]# cp

/usr/share/MySQL/my-medium . cn f/etc/my . cn f

(5) edit/etc/my.cnf.

In order to ensure that MySQL can work normally, it is necessary to indicate the location where the mysql.sock file is generated. modify

Socket =/var/lib/MySQL/mysql.sock is:

socket =/home/data/MySQL/MySQL . sock

The operation is as follows:

Vi my.cnf (edit my.cnf file with Vi tool and find the following data to modify)

# MySQL server [mysqld]

Port = 3306

# Socket =

/var/lib/mysql/mysql.sock (original content, please use "#" to make this line more secure).

Socket =/home/data/MySQL/MySQL. Sock (plus this line)

(6) Modify MySQL startup script /etc/init.d/mysql.

Search datadir to change /var/lib/mysql to the current actual storage path: home/data/mysql.

[root @ test 1 etc]# VI/etc/init . d/MySQL

get _ MySQL _ option mysqld datadir "/data/MySQL "

Finally, make a mysql.sock link:

ln-s/home/data/MySQL/MySQL . sock

/var/lib/mysql/mysql.sock (you need to copy from /home/data/mysql).

(7) Restart MySQL service.

Service mysqld restart

Finally, create a database to see if it already exists in the target directory.