今天在linux安装了mysql,是用的是centos系统,我用的是yum安装的。
yum install mysql-server mysql-devel mysql
修改数据的存储目录的时候遇到了些问题,记录一下步奏。
默认的数据存储目录:/var/lib/mysql
我修改后的存储目录:/data/mysqldata/mysql
mysql 修改数据目录:
1、停止mysql服务
service mysqld stop
2、复制原来的数据到新目录,新目录不存在请创建
mkdir -p /data/mysqldata/mysql
cp -fr /var/lib/mysql/* /data/mysqldata/mysql
3、修改目录权限
chown mysql:mysql -R /data/mysqldata/mysql
4、修改配置文件
vi /etc/my.cnf
修改:
datadir=/data/mysqldata/mysql
socket=/data/mysqldata/mysql/mysql.sock
添加:
[mysql]
socket=/data/mysqldata/mysql/mysql.sock
附上my.cnf文件
[mysqld] #datadir=/var/lib/mysql datadir=/data/mysqldata/mysql #socket=/var/lib/mysql/mysql.sock socket=/data/mysqldata/mysql/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 [mysql] socket=/data/mysqldata/mysql/mysql.sock
vi /etc/init.d/mysqld
datadir "/data/mysqldata/mysql"
5、防止SELinux
chcon -R -t mysqld_db_t /data/mysqldata/mysql
(如果步奏6,启动报以下错,就使用第五步的方法处理)
141209 23:52:32 [Warning] Can't create test file /data/mysqldata/mysql/localhost.lower-test 141209 23:52:32 [Warning] Can't create test file /data/mysqldata/mysql/localhost.lower-test /usr/libexec/mysqld: Can't find file: './mysql/plugin.frm' (errno: 13) 141209 23:52:32 [ERROR] Can't open the mysql.plugin table. Please run mysql_upgrade to create it.
6、启动mysql服务
service mysqld start
时间: 2024-10-06 08:19:33