mysql> show global variables like '%datadir%' ;
+---------------+-----------------+
| Variable_name | Value |
+---------------+-----------------+
| datadir | /var/lib/mysql/ |
+---------------+-----------------+
1 row in set (0.00 sec)
mysql 数据默认是在 /var/lib/mysql/ 目录下,准备移动到 /database/mysql
[root@db mysql]# service mysqld stop
Redirecting to /bin/systemctl stop mysqld.service
vi /etc/my.cnf
[mysqld]
#datadir=/var/lib/mysql
#socket=/var/lib/mysql/mysql.sock
datadir=/database/mysql
socket=/database/mysql/mysql.sock
[root@db ~]# service mysqld start
Redirecting to /bin/systemctl start mysqld.service
如果出现
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)
vi /etc/my.cnf
加上
[client]
socket=/database/mysql/mysql.sock