1,
Use the Command service mysqld stop to stop mysql
View the default path of the mysql database:/var/lib/mysql
Use cp-afir/var/lib/mysql/*/usr/local/mysql
For details about the f I r parameter, see cp help.
2,
Change my. cnf
Run the command vim/etc/my. cnf.
Change datadir to a new path.
Datadir =/usr/local/mysql
To ensure that MySQL works properly, you must specify the location where the mysql. sock file is generated.
# Socket =/var/lib/mysql. sock)
Socket =/usr/local/mysql. sock (add this line)
3. Modify the MySQL STARTUP script/etc/init. d/mysqld,
Change the datadir =/var/lib/mysql line to your actual storage path/usr/local/mysql.
[Root @ test1 etc] # vi/etc/init. d/mysqld
# Datadir =/var/lib/mysql (comment this row)
Datadir =/usr/local/mysql (add this row)
4,
Modify etc/php. ini to add mysql. default_socket path
Mysql. default_socket =/usr/local/mysql. sock
5. ln-s/usr/local/mysql. sock/var/lib/mysql. sock
Create a soft link for mysql. sock. Otherwise, the system will prompt that/var/lib/mysql. sock cannot be found.
6. Restart mysqld.
Service mysqld restart