RPM-QL MySQL View installation location
The default data file storage directory for MySQL is/var/lib/mysql. The following steps are required if you want to move the directory to/home/data:
1. Set up the data directory in the home directory
Cd/homemkdir data
2. Stop the MySQL service process:
Mysqladmin-u root-p shutdown
3. Move/var/lib/mysql Entire directory to/home/data
mv/var/lib/mysql/home/data/
This will move the MySQL data file to/home/data/mysql.
4. Locate the MY.CNF configuration file
If there is no MY.CNF configuration file under the/etc/directory, locate the *.cnf file under/usr/share/mysql/, and copy one of them to/etc/and rename it to MY.CNF). The command is as follows:
[Email protected] mysql]# CP/USR/SHARE/MYSQL/MY-MEDIUM.CNF/ETC/MY.CNF
5. Edit the MySQL configuration file/etc/my.cnf
To ensure that MySQL works correctly, you need to indicate where the Mysql.sock file is generated. Modify the value in the Socket=/var/lib/mysql/mysql.sock line to the right of the equals sign:/home/mysql/mysql.sock. The operation is as follows:
VI my.cnf (edit my.cnf file with VI tool, find the following data modified) # The MySQL server[mysqld] Port = 3306#socket =/var/lib/mysql/mysql.sock (original content, in order to more Secure with "#" comment this line) socket =/home/data/mysql/mysql.sock (plus this line)
6. Modify MySQL startup script/etc/init.d/mysql
Finally, the MySQL startup script needs to be modified/etc/init.d/mysql, the path to the right of the equal sign in the Datadir=/var/lib/mysql line is changed to your current actual storage path: Home/data/mysql.
[[email protected] etc]# Vi/etc/init.d/mysql#datadir=/var/lib/mysql (note this line) Datadir=/home/data/mysql (plus this line)
If it is CentOS also need to change/usr/bin/mysqld_safe relevant file location;
Finally make a mysql.sock link:
In-s/home/data/mysql/mysql.sock/var/lib/mysql/mysql.sock
7. Restart MySQL Service
/etc/init.d/mysqld start
or restart Linux with the reboot command
If the work is moving properly, otherwise check the previous 7 steps. Also pay attention to the owner and permission of the directory.
Copy Content to Clipboard
Code:
[[email protected] ~]# chown -R mysql:mysql /home/data/mysql/ ← 改变数据库的归属为mysql
[[email protected] ~]# chmod 700 /home/data/mysql/test/ ← 改变数据库目录属性为700
[[email protected] ~]# chmod 660 /home/data/mysql/test/* ← 改变数据库中数据的属性为660
Error Resolution:
1.在CentOS上,如果mysql是通过yum安装的,那么可能使用上面的方法不能完全凑效。
原因:mysql的配置文件有多处,除了更改/etc/my.cnf文件之外,还需要更改/usr/lib64/mysql/mysql_config
这个文件里面有一行“ldata=‘/var/lib/mysql‘”和"socket=/var/lib/mysql/mysql.sock",这里也需要改掉
2.另外,还有权限问题,查看/var/log/mysqld.log,发现Can‘t create test file /xxx/mysql/centos5.lower-test
这里是因为没有权限创建或读取文件。
解决办法就是使用setenforce 0 这个命令,让系统关闭权限校验,然后再运行命令 service mysqld start 发现OK了。
另外一个办法是restorecon -FRv /home/data/mysql,或者chcon -R -t mysqld_db_t /home/data/mysql
CentOS MySQL data store directory installation location