at work, we will encounter the need to change the database storage location, such as: the original database where the disk space is insufficient, and so on.
compiling the installed Mysql
[[Email protected] ~]# service mysqld status # First see MySQL as running state
success! MySQL Running (3794)
[[email protected] ~]# PS aux | grep mysqld | grep-v grep
# Here you can see the location of the original DataDir, there are other parameter paths
root 3543 0.0 0.1 11304 1504 pts/0 S 19:32 0:00
/bin/sh/usr/local/mysql/bin/mysqld_safe
–datadir=/usr/local/mysql/data–pid-file=/usr/local/mysql/data/localhost.pid
mysql 3794 0.0 4.3 647376 43936 pts/0 Sl 19:32 0:00
/usr/local/mysql/bin/mysqld
–basedir=/usr/local/mysql–datadir=/usr/local/mysql/data
–plugin-dir=/usr/local/mysql/lib/plugin–user=mysql
–log-error=/usr/local/mysql/data/localhost.err–pid-file=/usr/local/mysql/data/localhost.pid
–socket=/tmp/mysql.sock–port=3306
[[Email protected] ~]# service mysqld Stop # Okay, we're going to stop MySQL first .
shutting down MySQL. Success!
[[email protected] ~]# PS aux | grep mysqld | grep-v grep # no process detected
[[email protected] ~]# Mkdir/data # Create the location you want to change
[[email protected] ~]# cp-r/usr/local/mysql/data/*/data/# Copy all the contents of the original data directory to the new path
[[email protected] ~]# chown-r mysql/data/# to directory owner
[[email protected] ~]# VIM/ETC/MY.CNF # Edit configuration file
[Mysqld]
DataDir =/data# Add Database storage location
[[Email protected] ~]# service mysqld start # and start the database
starting MySQL. Success!
[[email protected] ~]# PS aux | grep mysqld | grep-v grep # can see –datadir=/data this is the new location
Root 3890 0.5 0.1 11304 1504 pts/0 S 19:52 0:00
/bin/sh/usr/local/mysql/bin/mysqld_safe–datadir=/data–pid-file=/data/localhost.pid
MySQL 4153 2.5 4.0 647376 41824 pts/0 Sl 19:52 0:00
/usr/local/mysql/bin/mysqld
–basedir=/usr/local/mysql
–datadir=/data–plugin-dir=/usr/local/mysql/lib/plugin–user=mysql–log-error=/data/localhost.err
–pid-file=/data/localhost.pid–socket=/tmp/mysql.sock–port=3306
This article is from the "System operation and maintenance website Development" blog, please be sure to keep this source http://cgc888.blog.51cto.com/3989433/1688853
Mysql Modify Database storage location