Operation steps of the practice process of changing the data storage directory of the MySQL database

The default database file of the MySQL database is located in /var/lib/mysql. Sometimes due to storage planning and other reasons, the data storage directory of the MySQL database needs to be changed. The steps in the practice process are summarized below.

1: Confirm the MySQL database storage directory

[root@DB-Server tmp]# mysqladmin -u root -p variables | grep datadir

Enter password:

| datadir | /var/lib/mysql/

2: Shut down the MySQL service

Before changing the MySQL data directory, the MySQL service must be shut down.

Way 1:

[root@DB-Server ~]# service mysql status

MySQL running(9411)[OK]

[root@DB-Server ~]# service mysql stop

Shutting down MySQL..[OK]

[root@DB-Server ~]#

Way 2:

[root@DB-Server ~]# /etc/rc.d/init.d/mysql status

MySQL running(8900)[OK]

[root@DB-Server ~]# /etc/rc.d/init.d/mysql stop

Shutting down MySQL..[OK]

[root@DB-Server ~]#

3: Create a new database storage directory

[root@DB-Server ~]# cd /u01

[root@DB-Server u01]# mkdir mysqldata

4: Move the MySQL data directory to the new location

[root@DB-Server ~]# mv /var/lib/mysql /u01/mysqldata/

5: Modify the configuration file my.cnf

Not all versions include the configuration file my.cnf. In MySQL version 5.5, I can't find the configuration file my.cnf. In some MySQL versions, the file is located in /usr/my.cnf, if the /etc/ directory There is no my.cnf configuration file, please go to /usr/share/mysql/ to find the *.cnf file, copy one of them to /etc/ and rename it to my.cnf. The command is as follows:

[root@DB-Server mysql]# cp /usr/share/mysql/my-medium.cnf /etc/my.cnf

Edit the /etc/my.cnf file and modify the parameter socket

6: Modify the startup script /etc/init.d/mysql

Modify the parameter datadir to datadir=/u01/mysqldata/mysql/

7: Start the MySQL service and verify the MySQL database path

[root@DB-Server ~]# service mysql start

Starting MySQL..[OK]

[root@DB-Server ~]# mysqladmin -u root -p variables | grep datadir

Enter password:

|datadir| /u01/mysqldata/mysql/

My question:

1: Before modifying the storage directory of the database, there is no mysql.sock file in the /var/lib/mysql/ directory. After installing the above configuration, the mysql.sock file will be generated.

Regarding the mysql.sock file, I searched for information: mysql.sock is a file used for socket connections. That is, this file exists only when your daemon is started. But your mysql program (this program is the client, the server is mysqld) can choose whether to use the mysql.sock file to connect (because this method is only suitable for connecting to local mysqld on Unix hosts), for any type of non-local host. So is this file necessary? This needs to be further understood.

2: I read on the Internet that some netizens summed up the modification of the MySQL data path, some need to do some processing for the permissions of the newly created directory, and some do not need to authorize the directory permissions, I have not dealt with it, and there is no problem. Do you want to authorize the new database directory?

3: When I tested the version of MySQL_5.6.20, I did not modify my.cnf, but only modified the startup script /etc/init.d/mysql, and there was no problem at all. Also no mysql.sock file is generated.

4: Note that if selinux is not disabled, you will encounter some errors when starting the MySQL service after modifying the MySQL data path. The explanation for this is that the background services need to have corresponding permissions to the corresponding directories, and the default path of mysql /var/lib/mysql has added a corresponding policy. After modifying the path, there is no corresponding policy, causing the background process to read the file. Blocked by selinux, resulting in a permission error. So either close Selinux or modify the file security context.

[root@DB-Server mysql]# /etc/init.d/mysql start

Starting MySQL....The server quit without updating PID file(/u01/mysqldata/mysql//DB-Server.localdomain.pid).[FAILED]

[root@DB-Server mysql]#

[root@DB-Server mysql]# chcon -R -t mysqld_db_t /u01/mysqldata/mysql/

[root@DB-Server mysql]# /etc/init.d/mysql start

Starting MySQL.[OK]

[root@DB-Server mysql]#

Privacy Film

The Privacy Screen Protector can display a black screen directly in front of the screen at an angle greater than 30° to effectively block the sight of people next to it, while achieving a perfect balance between black screen privacy and daytime clarity.

The Screen Protector can protect the edges and gaps of the display so that it can extend to the entire screen surface, thereby achieving maximum coverage without any exposed space.

The Self-Healing Screen Protector can provide the best protection for your phone from drops, bumps, scratches and normal wear and tear. Using an oleophobic waterproof coating can prevent sweat and grease from remaining on your fingerprints, keeping you simple all day long.

The 0.14mm thick Ultra-Thin Protective Film has a "real touch" feel and ensures fast response performance.

If you want to know more about Privacy Screen Protector products, please click the product details to view the parameters, models, pictures, prices and other information about Privacy Screen Protector.

Whether you are a group or an individual, we will try our best to provide you with accurate and comprehensive information about the Privacy Screen Protector!

Anti-peep Screen Protector, Privacy Screen Protector, Anti-spy Screen Protector, Privacy Protective Film, Privacy Hydrogel Film,Anti-peeping Screen Protector

Shenzhen Jianjiantong Technology Co., Ltd. , https://www.hydrogelprotectivefilm.com