今天在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

//   处理SElinux另一个办法  vi /etc/selinux/config     修改SELINUX=disabled

(如果步奏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

如果要将mysql设置为开机启动:

chkconfig --add mysqld
chkconfig --level 2345 mysqld on


7、添加用户无法访问情况

添加用户:

mysql> grant all privileges on *.* to root2@'%' identified by '123456';

mysql> flush privileges;

mysql> exit;

[root@localhost ~]# mysql -r root -p

输入密码,但是报错了。

ERROR 1045 (28000): Access denied for user 'root2'@'localhost' (using password: YES)
解决方法: 
改用root 登陆  ,然后做以下操作,删除匿名用户。 
mysql> use mysql 
mysql> delete from user where user=''; 
mysql> flush privileges; 

Logo

更多推荐