Step 1: Create new data folder for mysql (For
example: /u01/mysql/data)
[root@ptudvtg149 ~]# mkdir -p
/u01/mysql/data
|
Step 2: Copy all old data of mysql to new
folder ( old folder: /var/lib/mysql)
[root@ptudvtg149 mysql]# cp -r
/var/lib/mysql /u01/mysql/data/
|
Step 3: Edit /etc/my.cnf
[root@ptudvtg149 data]# vi /etc/my.cnf
[mysqld]
datadir=/u01/mysql/data
socket=/u01/mysql/data/mysql.sock
user=mysql
# Disabling symbolic-links is recommended to prevent assorted
security risks
symbolic-links=0
[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
[mysqld]
default-time-zone='+00:00'
[client]
socket=/u01/mysql/data/mysql.sock
port=3306
|
Step 4: Init new data_dir
[root@ptudvtg149 mysql]# mysql_install_db
--user=mysql --datadir=/u01/mysql/data
Installing MySQL system tables...
OK
Filling help tables...
OK
To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system
PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
To do so, start the server, then issue the following commands:
/usr/bin/mysqladmin -u root password 'new-password'
/usr/bin/mysqladmin -u root -h ptudvtg149 password 'new-password'
Alternatively you can run:
/usr/bin/mysql_secure_installation
which will also give you the option of removing the test
databases and anonymous user created by default. This is
strongly recommended for production servers.
See the manual for more instructions.
You can start the MySQL daemon with:
cd /usr ; /usr/bin/mysqld_safe &
You can test the MySQL daemon with mysql-test-run.pl
cd /usr/mysql-test ; perl mysql-test-run.pl
Please report any problems with the /usr/bin/mysqlbug script!
|
Step 5: Restart and check again mysql
[root@ptudvtg149 mysql]# service
mysqld restart
Stopping mysqld:
[ OK ]
Starting mysqld:
[ OK ]
[root@ptudvtg149 mysql]# ps
-ef | grep mysql
root 8365 1
0 14:42 pts/1 00:00:00
/bin/sh /usr/bin/mysqld_safe --datadir=/u01/mysql/data --socket=/u01/mysql/data/mysql.sock
--pid-file=/var/run/mysqld/mysqld.pid --basedir=/usr --user=mysql
mysql 8470 8365
0 14:42 pts/1 00:00:00
/usr/libexec/mysqld --basedir=/usr --datadir=/u01/mysql/data --user=mysql
--log-error=/var/log/mysqld.log --pid-file=/var/run/mysqld/mysqld.pid
--socket=/u01/mysql/data/mysql.sock
root 8593 6957
0 14:43 pts/1 00:00:00 grep
mysql
|
0 Comment to "How to change MySQL datadir"
Post a Comment